about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/lua-modules/lib.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
committerAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
commit99fcaeccb89621dd492203ce1f2d551c06f228ed (patch)
tree41cb730ae07383004789779b0f6e11cb3f4642a3 /nixpkgs/pkgs/development/lua-modules/lib.nix
parent59c5f5ac8682acc13bb22bc29c7cf02f7d75f01f (diff)
parent75a5ebf473cd60148ba9aec0d219f72e5cf52519 (diff)
downloadnixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.gz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.bz2
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.lz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.xz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.zst
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.zip
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs
Conflicts:
	nixpkgs/nixos/modules/config/console.nix
	nixpkgs/nixos/modules/services/mail/mailman.nix
	nixpkgs/nixos/modules/services/mail/public-inbox.nix
	nixpkgs/nixos/modules/services/mail/rss2email.nix
	nixpkgs/nixos/modules/services/networking/ssh/sshd.nix
	nixpkgs/pkgs/applications/networking/instant-messengers/dino/default.nix
	nixpkgs/pkgs/applications/networking/irc/weechat/default.nix
	nixpkgs/pkgs/applications/window-managers/sway/default.nix
	nixpkgs/pkgs/build-support/go/module.nix
	nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
	nixpkgs/pkgs/development/interpreters/python/default.nix
	nixpkgs/pkgs/development/node-packages/overrides.nix
	nixpkgs/pkgs/development/tools/b4/default.nix
	nixpkgs/pkgs/servers/dict/dictd-db.nix
	nixpkgs/pkgs/servers/mail/public-inbox/default.nix
	nixpkgs/pkgs/tools/security/pinentry/default.nix
	nixpkgs/pkgs/tools/text/unoconv/default.nix
	nixpkgs/pkgs/top-level/all-packages.nix
Diffstat (limited to 'nixpkgs/pkgs/development/lua-modules/lib.nix')
-rw-r--r--nixpkgs/pkgs/development/lua-modules/lib.nix82
1 files changed, 37 insertions, 45 deletions
diff --git a/nixpkgs/pkgs/development/lua-modules/lib.nix b/nixpkgs/pkgs/development/lua-modules/lib.nix
index 5079a4b25405..bdf363fb4799 100644
--- a/nixpkgs/pkgs/development/lua-modules/lib.nix
+++ b/nixpkgs/pkgs/development/lua-modules/lib.nix
@@ -1,5 +1,6 @@
 { pkgs, lib, lua }:
 let
+  inherit (lib.generators) toLua;
   requiredLuaModules = drvs: with lib; let
     modules =  filter hasLuaModule drvs;
   in unique ([lua] ++ modules ++ concatLists (catAttrs "requiredLuaModules" modules));
@@ -65,7 +66,7 @@ rec {
     so that luaRequireModules can be run later
   */
   toLuaModule = drv:
-    drv.overrideAttrs( oldAttrs: {
+    drv.overrideAttrs(oldAttrs: {
       # Use passthru in order to prevent rebuilds when possible.
       passthru = (oldAttrs.passthru or {}) // {
         luaModule = lua;
@@ -81,66 +82,57 @@ rec {
   };
   */
   generateLuarocksConfig = {
-    externalDeps
-
+      externalDeps
     # a list of lua derivations
     , requiredLuaRocks
     , extraVariables ? {}
     , rocksSubdir
     }: let
       rocksTrees = lib.imap0
-        (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
+        (i: dep: { name = "dep-${toString i}"; root = "${dep}"; rocks_dir = "${dep}/${dep.rocksSubdir}"; })
         requiredLuaRocks;
 
       # Explicitly point luarocks to the relevant locations for multiple-output
       # derivations that are external dependencies, to work around an issue it has
       # (https://github.com/luarocks/luarocks/issues/766)
-      depVariables = lib.concatMap ({name, dep}: [
-        "${name}_INCDIR='${lib.getDev dep}/include';"
-        "${name}_LIBDIR='${lib.getLib dep}/lib';"
-        "${name}_BINDIR='${lib.getBin dep}/bin';"
-      ]) externalDeps';
+      depVariables = zipAttrsWithLast (lib.lists.map ({name, dep}: {
+        "${name}_INCDIR" = "${lib.getDev dep}/include";
+        "${name}_LIBDIR" = "${lib.getLib dep}/lib";
+        "${name}_BINDIR" = "${lib.getBin dep}/bin";
+      }) externalDeps');
+      zipAttrsWithLast = lib.attrsets.zipAttrsWith (name: lib.lists.last);
 
       # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
       externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
 
       externalDepsDirs = map
-        (x: "'${builtins.toString x}'")
+        (x: builtins.toString x)
         (lib.filter (lib.isDerivation) externalDeps);
-
-      extraVariablesStr = lib.concatStringsSep "\n "
-        (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
-  in ''
-    local_cache = ""
-    -- To prevent collisions when creating environments, we install the rock
-    -- files into per-package subdirectories
-    rocks_subdir = '${rocksSubdir}'
-    -- first tree is the default target where new rocks are installed,
-    -- any other trees in the list are treated as additional sources of installed rocks for matching dependencies.
-    rocks_trees = {
-      {name = "current", root = '${placeholder "out"}', rocks_dir = "current" },
-      ${lib.concatStringsSep "\n, " rocksTrees}
-    }
-  '' + lib.optionalString lua.pkgs.isLuaJIT ''
-    -- Luajit provides some additional functionality built-in; this exposes
-    -- that to luarock's dependency system
+  in toLua { asBindings = true; } ({
+    local_cache = "";
+    # To prevent collisions when creating environments, we install the rock
+    # files into per-package subdirectories
+    rocks_subdir = rocksSubdir;
+    # first tree is the default target where new rocks are installed,
+    # any other trees in the list are treated as additional sources of installed rocks for matching dependencies.
+    rocks_trees = (
+      [{name = "current"; root = "${placeholder "out"}"; rocks_dir = "current"; }] ++
+      rocksTrees
+    );
+  } // lib.optionalAttrs lua.pkgs.isLuaJIT {
+    # Luajit provides some additional functionality built-in; this exposes
+    # that to luarock's dependency system
     rocks_provided = {
-      jit='${lua.luaversion}-1';
-      ffi='${lua.luaversion}-1';
-      luaffi='${lua.luaversion}-1';
-      bit='${lua.luaversion}-1';
-    }
-  '' + ''
-    -- For single-output external dependencies
-    external_deps_dirs = {
-      ${lib.concatStringsSep "\n, " externalDepsDirs}
-    }
-    variables = {
-      -- Some needed machinery to handle multiple-output external dependencies,
-      -- as per https://github.com/luarocks/luarocks/issues/766
-      ${lib.optionalString (lib.length depVariables > 0) ''
-        ${lib.concatStringsSep "\n  " depVariables}''}
-      ${extraVariablesStr}
-    }
-  '';
+      jit = "${lua.luaversion}-1";
+      ffi = "${lua.luaversion}-1";
+      luaffi = "${lua.luaversion}-1";
+      bit = "${lua.luaversion}-1";
+    };
+  } // {
+    # For single-output external dependencies
+    external_deps_dirs = externalDepsDirs;
+    # Some needed machinery to handle multiple-output external dependencies,
+    # as per https://github.com/luarocks/luarocks/issues/766
+    variables = (depVariables // extraVariables);
+  });
 }