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>2021-10-19 14:40:23 +0000
committerAlyssa Ross <hi@alyssa.is>2022-01-07 10:22:32 +0000
commitcc62bcb55359ba8c5e0fe3a48e778444c89060d8 (patch)
treeca0e21d44eaf8837b687395e614445f7761d7bbd /nixpkgs/pkgs/development/lua-modules/lib.nix
parentd6625e8d25efd829c3cfa227d025ca4e606ae4b7 (diff)
parenta323570a264da96a0b0bcc1c9aa017794acdc752 (diff)
downloadnixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar.gz
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar.bz2
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar.lz
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar.xz
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.tar.zst
nixlib-cc62bcb55359ba8c5e0fe3a48e778444c89060d8.zip
Merge commit 'a323570a264da96a0b0bcc1c9aa017794acdc752'
Diffstat (limited to 'nixpkgs/pkgs/development/lua-modules/lib.nix')
-rw-r--r--nixpkgs/pkgs/development/lua-modules/lib.nix80
1 files changed, 80 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/lua-modules/lib.nix b/nixpkgs/pkgs/development/lua-modules/lib.nix
index 9c31f9a5c53c..bd952e7b8ce7 100644
--- a/nixpkgs/pkgs/development/lua-modules/lib.nix
+++ b/nixpkgs/pkgs/development/lua-modules/lib.nix
@@ -5,8 +5,20 @@ let
   in unique ([lua] ++ modules ++ concatLists (catAttrs "requiredLuaModules" modules));
   # Check whether a derivation provides a lua module.
   hasLuaModule = drv: drv ? luaModule;
+
+
+  /*
+  Use this to override the arguments passed to buildLuarocksPackage
+  */
+  overrideLuarocks = drv: f: (drv.override (args: args // {
+    buildLuarocksPackage = drv: (args.buildLuarocksPackage drv).override f;
+  })) // {
+    overrideScope = scope: overrideLuarocks (drv.overrideScope scope) f;
+  };
+
 in
 rec {
+  inherit overrideLuarocks;
   inherit hasLuaModule requiredLuaModules;
 
   luaPathList = [
@@ -60,4 +72,72 @@ rec {
         requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
       };
     });
+
+  /* generate luarocks config
+
+  generateLuarocksConfig {
+    externalDeps = [ { name = "CRYPTO"; dep = pkgs.openssl; } ];
+    rocksSubdir = "subdir";
+  };
+  */
+  generateLuarocksConfig = {
+    externalDeps
+    , requiredLuaRocks
+    , extraVariables ? {}
+    , rocksSubdir
+    }: let
+      rocksTrees = lib.imap0
+        (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';
+
+      # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
+      externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
+
+      externalDepsDirs = map
+        (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}'
+    -- 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}
+    }
+  '';
 }