git.iko.soy/typeable/nixpkgs
on master help sign in
lua: create a folder for hooks
abc3645Matthieu Coudron
pkgs/development/interpreters/lua-5/build-lua-package.nix+11−52
@@ -82,66 +82,25 @@ let
82 # configured trees)
82 # configured trees)
83 luarocks_config = "luarocks-config.lua";
83 luarocks_config = "luarocks-config.lua";
84 luarocks_content = let
84 luarocks_content = let
85− extraVariablesStr = lib.concatStringsSep "\n "
85+ generatedConfig = lua.pkgs.lib.generateLuarocksConfig {
86+ inherit externalDeps;
86− (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
87+ inherit extraVariables;
87− in ''
88− local_cache = ""
89− -- To prevent collisions when creating environments, we install the rock
90− -- files into per-package subdirectories
91− rocks_subdir = '${rocksSubdir}'
88+ inherit rocksSubdir;
92− -- Then we need to tell luarocks where to find the rock files per
89+ inherit requiredLuaRocks;
93− -- dependency
94− rocks_trees = {
95− ${lib.concatStringsSep "\n, " rocksTrees}
96− }
90+ };
97− '' + lib.optionalString lua.pkgs.isLuaJIT ''
91+ in
98− -- Luajit provides some additional functionality built-in; this exposes
92+ ''
99− -- that to luarock's dependency system
93+ ${generatedConfig}
100− rocks_provided = {
101− jit='${lua.luaversion}-1';
102− ffi='${lua.luaversion}-1';
103− luaffi='${lua.luaversion}-1';
104− bit='${lua.luaversion}-1';
105− }
106− '' + ''
107− -- For single-output external dependencies
108− external_deps_dirs = {
109− ${lib.concatStringsSep "\n, " externalDepsDirs}
110− }
111− variables = {
112− -- Some needed machinery to handle multiple-output external dependencies,
113− -- as per https://github.com/luarocks/luarocks/issues/766
114− ${lib.optionalString (lib.length depVariables > 0) ''
115− ${lib.concatStringsSep "\n " depVariables}''}
116− ${extraVariablesStr}
117− }
118− ${extraConfig}
94+ ${extraConfig}
119− '';
95+ '';
120
96
121 rocksSubdir = "${attrs.pname}-${version}-rocks";
97 rocksSubdir = "${attrs.pname}-${version}-rocks";
122
98
123− externalDepsDirs = map
124− (x: "'${builtins.toString x}'")
125− (lib.filter (lib.isDerivation) externalDeps);
126−
127− rocksTrees = lib.imap0
128− (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
129− requiredLuaRocks;
130−
131 # Filter out the lua derivation itself from the Lua module dependency
99 # Filter out the lua derivation itself from the Lua module dependency
132 # closure, as it doesn't have a rock tree :)
100 # closure, as it doesn't have a rock tree :)
133 requiredLuaRocks = lib.filter (d: d ? luaModule)
101 requiredLuaRocks = lib.filter (d: d ? luaModule)
134 (lua.pkgs.requiredLuaModules propagatedBuildInputs);
102 (lua.pkgs.requiredLuaModules propagatedBuildInputs);
135
103
136− # Explicitly point luarocks to the relevant locations for multiple-output
137− # derivations that are external dependencies, to work around an issue it has
138− # (https://github.com/luarocks/luarocks/issues/766)
139− depVariables = lib.concatMap ({name, dep}: [
140− "${name}_INCDIR='${lib.getDev dep}/include';"
141− "${name}_LIBDIR='${lib.getLib dep}/lib';"
142− "${name}_BINDIR='${lib.getBin dep}/bin';"
143− ]) externalDeps';
144−
145 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
104 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
146 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
105 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
147in
106in
pkgs/development/interpreters/lua-5/hooks/default.nixnew file+27
@@ -0,0 +1,27 @@
1+# Hooks for building lua packages.
2+{ lua
3+, lib
4+, makeSetupHook
5+, findutils
6+, runCommand
7+}:
8+
9+let
10+ callPackage = lua.pkgs.callPackage;
11+ luaInterpreter = lua.interpreter;
12+in {
13+
14+ lua-setup-hook = LuaPathSearchPaths: LuaCPathSearchPaths:
15+ let
16+ hook = ./setup-hook.sh;
17+ in runCommand "lua-setup-hook.sh" {
18+ # hum doesn't seem to like caps !! BUG ?
19+ luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
20+ luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
21+ } ''
22+ cp ${hook} hook.sh
23+ substituteAllInPlace hook.sh
24+ mv hook.sh $out
25+ '';
26+
27+}
pkgs/development/interpreters/lua-5/setup-hook.sh → pkgs/development/interpreters/lua-5/hooks/setup-hook.shrenamed

The content is the same.

pkgs/development/interpreters/lua-5/setup-hook.nix−15
@@ -1,15 +0,0 @@
1−{ runCommand, lib, }:
2−
3−LuaPathSearchPaths: LuaCPathSearchPaths:
4−
5−let
6− hook = ./setup-hook.sh;
7−in runCommand "lua-setup-hook.sh" {
8− # hum doesn't seem to like caps !! BUG ?
9− luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
10− luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
11−} ''
12− cp ${hook} hook.sh
13− substituteAllInPlace hook.sh
14− mv hook.sh $out
15−''
pkgs/development/lua-modules/lib.nix+68
@@ -60,4 +60,72 @@ rec {
60 requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
60 requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
61 };
61 };
62 });
62 });
63+
64+ /* generate luarocks config
65+
66+ generateLuarocksConfig {
67+ externalDeps = [ { name = "CRYPTO"; dep = pkgs.openssl; } ];
68+ rocksSubdir = "subdir";
69+ };
70+ */
71+ generateLuarocksConfig = {
72+ externalDeps
73+ , requiredLuaRocks
74+ , extraVariables ? {}
75+ , rocksSubdir
76+ }: let
77+ rocksTrees = lib.imap0
78+ (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
79+ requiredLuaRocks;
80+
81+ # Explicitly point luarocks to the relevant locations for multiple-output
82+ # derivations that are external dependencies, to work around an issue it has
83+ # (https://github.com/luarocks/luarocks/issues/766)
84+ depVariables = lib.concatMap ({name, dep}: [
85+ "${name}_INCDIR='${lib.getDev dep}/include';"
86+ "${name}_LIBDIR='${lib.getLib dep}/lib';"
87+ "${name}_BINDIR='${lib.getBin dep}/bin';"
88+ ]) externalDeps';
89+
90+ # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
91+ externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
92+
93+ externalDepsDirs = map
94+ (x: "'${builtins.toString x}'")
95+ (lib.filter (lib.isDerivation) externalDeps);
96+
97+ extraVariablesStr = lib.concatStringsSep "\n "
98+ (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
99+ in ''
100+ local_cache = ""
101+ -- To prevent collisions when creating environments, we install the rock
102+ -- files into per-package subdirectories
103+ rocks_subdir = '${rocksSubdir}'
104+ -- Then we need to tell luarocks where to find the rock files per
105+ -- dependency
106+ rocks_trees = {
107+ ${lib.concatStringsSep "\n, " rocksTrees}
108+ }
109+ '' + lib.optionalString lua.pkgs.isLuaJIT ''
110+ -- Luajit provides some additional functionality built-in; this exposes
111+ -- that to luarock's dependency system
112+ rocks_provided = {
113+ jit='${lua.luaversion}-1';
114+ ffi='${lua.luaversion}-1';
115+ luaffi='${lua.luaversion}-1';
116+ bit='${lua.luaversion}-1';
117+ }
118+ '' + ''
119+ -- For single-output external dependencies
120+ external_deps_dirs = {
121+ ${lib.concatStringsSep "\n, " externalDepsDirs}
122+ }
123+ variables = {
124+ -- Some needed machinery to handle multiple-output external dependencies,
125+ -- as per https://github.com/luarocks/luarocks/issues/766
126+ ${lib.optionalString (lib.length depVariables > 0) ''
127+ ${lib.concatStringsSep "\n " depVariables}''}
128+ ${extraVariablesStr}
129+ }
130+ '';
63}
131}
pkgs/top-level/lua-packages.nix+6−10
@@ -12,18 +12,12 @@
12, fetchFromGitHub, which, writeText
12, fetchFromGitHub, which, writeText
13, pkgs
13, pkgs
14, lib
14, lib
15−}:
15+}@args:
16
16
17let
17let
18 packages = ( self:
18 packages = ( self:
19
19
20let
20let
21−
22− # a function of lua_path / lua_cpath
23− lua-setup-hook = callPackage ../development/interpreters/lua-5/setup-hook.nix {
24− inherit lib;
25− };
26−
27 callPackage = pkgs.newScope self;
21 callPackage = pkgs.newScope self;
28
22
29 buildLuaApplication = args: buildLuarocksPackage ({namePrefix="";} // args );
23 buildLuaApplication = args: buildLuarocksPackage ({namePrefix="";} // args );
@@ -52,11 +46,13 @@ in
52 # helper functions for dealing with LUA_PATH and LUA_CPATH
46 # helper functions for dealing with LUA_PATH and LUA_CPATH
53 lib = luaLib;
47 lib = luaLib;
54
48
55− getLuaPath = drv: luaLib.getPath drv (luaLib.luaPathList lua.luaversion) ;
49+ getLuaPath = drv: getPath drv (luaLib.luaPathList lua.luaversion) ;
56− getLuaCPath = drv: luaLib.getPath drv (luaLib.luaCPathList lua.luaversion) ;
50+ getLuaCPath = drv: getPath drv (luaLib.luaCPathList lua.luaversion) ;
57
51
52+ inherit (callPackage ../development/interpreters/lua-5/hooks { inherit (args) lib;})
53+ lua-setup-hook;
58
54
59− inherit lua lua-setup-hook callPackage;
55+ inherit lua callPackage;
60 inherit buildLuaPackage buildLuarocksPackage buildLuaApplication;
56 inherit buildLuaPackage buildLuarocksPackage buildLuaApplication;
61 inherit (luaLib) luaOlder luaAtLeast isLua51 isLua52 isLua53 isLuaJIT
57 inherit (luaLib) luaOlder luaAtLeast isLua51 isLua52 isLua53 isLuaJIT
62 requiredLuaModules toLuaModule hasLuaModule;
58 requiredLuaModules toLuaModule hasLuaModule;