summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2022-06-18 18:26:29 +0200
committerMatthieu Coudron <mcoudron@hotmail.com>2022-06-18 21:23:45 +0200
commit011911bc5465d009fcc9f7a92ee741761e091d3a (patch)
tree28616a80152f810d16c5af4d294d2631d7be73f2
parente0a42267f73ea52adc061a64650fddc59906fc99 (diff)
luarocks-check-hook: init
The hook is added to buildLuarocksPackage when doCheck is set to true.
-rw-r--r--pkgs/development/interpreters/lua-5/build-lua-package.nix24
-rw-r--r--pkgs/development/interpreters/lua-5/hooks/default.nix5
-rw-r--r--pkgs/development/interpreters/lua-5/hooks/luarocks-check-hook.sh18
-rw-r--r--pkgs/development/lua-modules/overrides.nix14
-rw-r--r--pkgs/top-level/lua-packages.nix2
5 files changed, 51 insertions, 12 deletions
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix
index ff93e842eeae1..0af7b470b0b38 100644
--- a/pkgs/development/interpreters/lua-5/build-lua-package.nix
+++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix
@@ -4,6 +4,7 @@
 , wrapLua
 # Whether the derivation provides a lua module or not.
 , toLuaModule
+, luarocksCheckHook
 }:
 
 {
@@ -42,6 +43,7 @@ pname
 
 , passthru ? {}
 , doCheck ? false
+, doInstallCheck ? false
 
 # Non-Lua / system (e.g. C library) dependencies. Is a list of deps, where
 # each dep is either a derivation, or an attribute set like
@@ -97,10 +99,12 @@ let
   # 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 luarocksDrv.propagatedBuildInputs);
+    (lua.pkgs.requiredLuaModules (luarocksDrv.nativeBuildInputs ++ luarocksDrv.propagatedBuildInputs));
 
   # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
-  externalDepsGenerated = lib.unique (lib.filter (drv: !drv ? luaModule) (luarocksDrv.propagatedBuildInputs ++ luarocksDrv.buildInputs));
+  externalDepsGenerated = lib.unique (lib.filter (drv: !drv ? luaModule) (
+    luarocksDrv.nativeBuildInputs ++ luarocksDrv.propagatedBuildInputs ++ luarocksDrv.buildInputs)
+    );
   externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
 
   luarocksDrv = toLuaModule ( lua.stdenv.mkDerivation (
@@ -108,15 +112,17 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab
 
   name = namePrefix + pname + "-" + version;
 
-  buildInputs = [ wrapLua lua.pkgs.luarocks ]
+  nativeBuildInputs = [
+    wrapLua
+    lua.pkgs.luarocks
+  ]
     ++ buildInputs
-    ++ lib.optionals doCheck checkInputs
+    ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ checkInputs)
     ++ (map (d: d.dep) externalDeps')
     ;
 
   # propagate lua to active setup-hook in nix-shell
   propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
-  inherit doCheck;
 
   # @-patterns do not capture formal argument default values, so we need to
   # explicitly inherit this for it to be available as a shell variable in the
@@ -190,6 +196,14 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab
     runHook postCheck
   '';
 
+  LUAROCKS_CONFIG="$PWD/${luarocks_config}";
+
+  shellHook = ''
+    runHook preShell
+    export LUAROCKS_CONFIG="$PWD/${luarocks_config}";
+    runHook postShell
+  '';
+
   passthru = {
     inherit lua; # The lua interpreter
     inherit externalDeps;
diff --git a/pkgs/development/interpreters/lua-5/hooks/default.nix b/pkgs/development/interpreters/lua-5/hooks/default.nix
index 8fd725a9b8a4f..61261ca3d046e 100644
--- a/pkgs/development/interpreters/lua-5/hooks/default.nix
+++ b/pkgs/development/interpreters/lua-5/hooks/default.nix
@@ -24,4 +24,9 @@ in {
       mv hook.sh $out
     '';
 
+  luarocksCheckHook = callPackage ({ luarocks }:
+    makeSetupHook {
+      name = "luarocks-check-hook";
+      deps = [ luarocks ];
+    } ./luarocks-check-hook.sh) {};
 }
diff --git a/pkgs/development/interpreters/lua-5/hooks/luarocks-check-hook.sh b/pkgs/development/interpreters/lua-5/hooks/luarocks-check-hook.sh
new file mode 100644
index 0000000000000..bc6c6255d5601
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/hooks/luarocks-check-hook.sh
@@ -0,0 +1,18 @@
+# Setup hook for checking whether Python imports succeed
+echo "Sourcing luarocks-check-hook.sh"
+
+luarocksCheckPhase () {
+    echo "Executing luarocksCheckPhase"
+    runHook preCheck
+
+    luarocks test
+
+    runHook postCheck
+    echo "Finished executing luarocksCheckPhase"
+}
+
+if [ -z "${dontLuarocksCheck-}" ] && [ -z "${checkPhase-}" ]; then
+    echo "Using luarocksCheckPhase"
+    checkPhase+=" luarocksCheckPhase"
+fi
+
diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix
index 1fe4cd3574f1a..507e1414189e8 100644
--- a/pkgs/development/lua-modules/overrides.nix
+++ b/pkgs/development/lua-modules/overrides.nix
@@ -15,7 +15,7 @@ with prev;
   });
 
   busted = prev.busted.overrideAttrs(oa: {
-    nativeBuildInputs = [
+    nativeBuildInputs = oa.nativeBuildInputs ++ [
       pkgs.installShellFiles
     ];
     postConfigure = ''
@@ -30,9 +30,6 @@ with prev;
   });
 
   cqueues = (prev.lib.overrideLuarocks prev.cqueues (drv: {
-    nativeBuildInputs = [
-      pkgs.gnum4
-    ];
     externalDeps = [
       { name = "CRYPTO"; dep = pkgs.openssl; }
       { name = "OPENSSL"; dep = pkgs.openssl; }
@@ -46,6 +43,11 @@ with prev;
       date = head rel;
       rev = last (splitString "-" (last rel));
     in "${date}-${rev}";
+
+    nativeBuildInputs = oa.nativeBuildInputs ++ [
+      pkgs.gnum4
+    ];
+
     # Upstream rockspec is pointlessly broken into separate rockspecs, per Lua
     # version, which doesn't work well for us, so modify it
     postConfigure = let inherit (prev.cqueues) pname; in ''
@@ -111,8 +113,8 @@ with prev;
     propagatedBuildInputs = with pkgs.lib; optional (!isLuaJIT) luaffi;
   });
 
-  lgi = prev.lib.overrideLuarocks prev.lgi (drv: {
-    nativeBuildInputs = [
+  lgi = prev.lgi.overrideAttrs (oa: {
+    nativeBuildInputs = oa.nativeBuildInputs ++ [
       pkgs.pkg-config
     ];
     buildInputs = [
diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix
index 96dfd89b59589..385aef164c2d6 100644
--- a/pkgs/top-level/lua-packages.nix
+++ b/pkgs/top-level/lua-packages.nix
@@ -50,7 +50,7 @@ in
   getLuaCPath = drv: getPath drv luaLib.luaCPathList;
 
   inherit (callPackage ../development/interpreters/lua-5/hooks { inherit (args) lib;})
-    lua-setup-hook;
+    luarocksCheckHook lua-setup-hook;
 
   inherit lua callPackage;
   inherit buildLuaPackage buildLuarocksPackage buildLuaApplication;