diff options
author | Matthieu Coudron <mcoudron@hotmail.com> | 2021-09-18 21:56:32 +0200 |
---|---|---|
committer | Matthieu Coudron <teto@users.noreply.github.com> | 2021-09-27 23:42:54 +0200 |
commit | abc36451d78d4c36a57a3acc7ce2f08e40789e72 (patch) | |
tree | b6e95539dede09b289a034f8cd108143d1c542e1 /pkgs/development/lua-modules | |
parent | 99a1d8ef57edd53b5bf957aa1e9d2898bc987f4d (diff) | |
download | nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar.gz nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar.bz2 nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar.lz nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar.xz nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.tar.zst nixpkgs-abc36451d78d4c36a57a3acc7ce2f08e40789e72.zip |
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/lua-modules')
-rw-r--r-- | pkgs/development/lua-modules/lib.nix | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkgs/development/lua-modules/lib.nix b/pkgs/development/lua-modules/lib.nix index 9c31f9a5c53..0d429b3ba6d 100644 --- a/pkgs/development/lua-modules/lib.nix +++ b/pkgs/development/lua-modules/lib.nix @@ -60,4 +60,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} + } + ''; } |