about summary refs log tree commit diff
path: root/pkgs/development/interpreters/lua-5
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2021-09-18 21:56:32 +0200
committerMatthieu Coudron <teto@users.noreply.github.com>2021-09-27 23:42:54 +0200
commitabc36451d78d4c36a57a3acc7ce2f08e40789e72 (patch)
treeb6e95539dede09b289a034f8cd108143d1c542e1 /pkgs/development/interpreters/lua-5
parent99a1d8ef57edd53b5bf957aa1e9d2898bc987f4d (diff)
lua: create a folder for hooks
- moved lua hooks to a specific folder as I foresee to add more
- moved generateLuarocksConfig to lib
- fix getLuaPath
- removed the useless rockspecDir
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r--pkgs/development/interpreters/lua-5/build-lua-package.nix63
-rw-r--r--pkgs/development/interpreters/lua-5/hooks/default.nix27
-rw-r--r--pkgs/development/interpreters/lua-5/hooks/setup-hook.sh (renamed from pkgs/development/interpreters/lua-5/setup-hook.sh)0
-rw-r--r--pkgs/development/interpreters/lua-5/setup-hook.nix15
4 files changed, 38 insertions, 67 deletions
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix
index 64e872ad5f638..e74649cab4a4c 100644
--- a/pkgs/development/interpreters/lua-5/build-lua-package.nix
+++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix
@@ -82,66 +82,25 @@ let
   # configured trees)
   luarocks_config = "luarocks-config.lua";
   luarocks_content = let
-    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}'
-    -- Then we need to tell luarocks where to find the rock files per
-    -- dependency
-    rocks_trees = {
-      ${lib.concatStringsSep "\n, " rocksTrees}
-    }
-  '' + lib.optionalString 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}
-    }
-    ${extraConfig}
-  '';
+    generatedConfig = lua.pkgs.lib.generateLuarocksConfig {
+      inherit externalDeps;
+      inherit extraVariables;
+      inherit rocksSubdir;
+      inherit requiredLuaRocks;
+    };
+    in
+      ''
+      ${generatedConfig}
+      ${extraConfig}
+      '';
 
   rocksSubdir = "${attrs.pname}-${version}-rocks";
 
-  externalDepsDirs = map
-    (x: "'${builtins.toString x}'")
-    (lib.filter (lib.isDerivation) externalDeps);
-
-  rocksTrees = lib.imap0
-    (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
-    requiredLuaRocks;
-
   # Filter out the lua derivation itself from the Lua module dependency
   # closure, as it doesn't have a rock tree :)
   requiredLuaRocks = lib.filter (d: d ? luaModule)
     (lua.pkgs.requiredLuaModules propagatedBuildInputs);
 
-  # 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';
-
   # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
   externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
 in
diff --git a/pkgs/development/interpreters/lua-5/hooks/default.nix b/pkgs/development/interpreters/lua-5/hooks/default.nix
new file mode 100644
index 0000000000000..8fd725a9b8a4f
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/hooks/default.nix
@@ -0,0 +1,27 @@
+# Hooks for building lua packages.
+{ lua
+, lib
+, makeSetupHook
+, findutils
+, runCommand
+}:
+
+let
+  callPackage = lua.pkgs.callPackage;
+  luaInterpreter = lua.interpreter;
+in {
+
+  lua-setup-hook = LuaPathSearchPaths: LuaCPathSearchPaths:
+    let
+      hook = ./setup-hook.sh;
+    in runCommand "lua-setup-hook.sh" {
+      # hum doesn't seem to like caps !! BUG ?
+      luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
+      luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
+    } ''
+      cp ${hook} hook.sh
+      substituteAllInPlace hook.sh
+      mv hook.sh $out
+    '';
+
+}
diff --git a/pkgs/development/interpreters/lua-5/setup-hook.sh b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh
index 1c445b82afded..1c445b82afded 100644
--- a/pkgs/development/interpreters/lua-5/setup-hook.sh
+++ b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh
diff --git a/pkgs/development/interpreters/lua-5/setup-hook.nix b/pkgs/development/interpreters/lua-5/setup-hook.nix
index 62caffd8d8a0f..e69de29bb2d1d 100644
--- a/pkgs/development/interpreters/lua-5/setup-hook.nix
+++ b/pkgs/development/interpreters/lua-5/setup-hook.nix
@@ -1,15 +0,0 @@
-{ runCommand, lib, }:
-
-LuaPathSearchPaths: LuaCPathSearchPaths:
-
-let
-  hook = ./setup-hook.sh;
-in runCommand "lua-setup-hook.sh" {
-  # hum doesn't seem to like caps !! BUG ?
-  luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
-  luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
-} ''
-  cp ${hook} hook.sh
-  substituteAllInPlace hook.sh
-  mv hook.sh $out
-''