mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
buildLuarocksPackage: accept structured luarocks config
There is an arbitrary mapping being done right now between nixpkgs lua infrastructre and luarocks config schema. This is confusing if you use lua so let's make it possible to use the lua names in the nixpkgs, thanks to the lib.generators.toLua convertor. The only nixpkgs thing to remember should be to put the config into `luarocksConfig` `buildLuarocksPackage.extraVariables` should become `buildLuarocksPackage.luarocksConfig.variables`
This commit is contained in:
parent
bc9b32647a
commit
50e877ed89
@ -215,6 +215,11 @@ install the package
|
||||
environment variable and add dependent libraries to script's `LUA_PATH` and
|
||||
`LUA_CPATH`.
|
||||
|
||||
It accepts as arguments:
|
||||
|
||||
* 'luarocksConfig': a nix value that directly maps to the luarocks config used during
|
||||
the installation
|
||||
|
||||
By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise.
|
||||
|
||||
#### `buildLuaApplication` function {#buildluaapplication-function}
|
||||
|
@ -51,9 +51,10 @@
|
||||
|
||||
# Appended to the generated luarocks config
|
||||
, extraConfig ? ""
|
||||
# Inserted into the generated luarocks config in the "variables" table
|
||||
, extraVariables ? {}
|
||||
# The two above arguments have access to builder variables -- e.g. to $out
|
||||
|
||||
# transparent mapping nix <-> lua used as LUAROCKS_CONFIG
|
||||
# Refer to https://github.com/luarocks/luarocks/wiki/Config-file-format for specs
|
||||
, luarocksConfig ? {}
|
||||
|
||||
# relative to srcRoot, path to the rockspec to use when using rocks
|
||||
, rockspecFilename ? null
|
||||
@ -92,7 +93,7 @@ let
|
||||
luarocks
|
||||
];
|
||||
|
||||
inherit doCheck extraConfig extraVariables rockspecFilename knownRockspec externalDeps nativeCheckInputs;
|
||||
inherit doCheck extraConfig rockspecFilename knownRockspec externalDeps nativeCheckInputs;
|
||||
|
||||
buildInputs = let
|
||||
# example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
|
||||
@ -116,9 +117,18 @@ let
|
||||
text = self.luarocks_content;
|
||||
};
|
||||
|
||||
luarocks_content = let
|
||||
externalDepsGenerated = lib.filter (drv: !drv ? luaModule)
|
||||
(self.nativeBuildInputs ++ self.propagatedBuildInputs ++ self.buildInputs);
|
||||
luarocks_content =
|
||||
(lib.generators.toLua { asBindings = true; } self.luarocksConfig) +
|
||||
''
|
||||
|
||||
${self.extraConfig}
|
||||
'';
|
||||
|
||||
# TODO make it the default variable
|
||||
luarocksConfig = let
|
||||
externalDepsGenerated = lib.filter (drv: !drv ? luaModule)
|
||||
(self.nativeBuildInputs ++ self.propagatedBuildInputs ++ self.buildInputs);
|
||||
|
||||
generatedConfig = luaLib.generateLuarocksConfig {
|
||||
externalDeps = lib.unique (self.externalDeps ++ externalDepsGenerated);
|
||||
# Filter out the lua derivation itself from the Lua module dependency
|
||||
@ -126,13 +136,17 @@ let
|
||||
# luaLib.hasLuaModule
|
||||
requiredLuaRocks = lib.filter luaLib.hasLuaModule
|
||||
(lua.pkgs.requiredLuaModules (self.nativeBuildInputs ++ self.propagatedBuildInputs));
|
||||
inherit (self) extraVariables rocksSubdir;
|
||||
inherit (self) rocksSubdir;
|
||||
};
|
||||
in
|
||||
''
|
||||
${generatedConfig}
|
||||
${self.extraConfig}
|
||||
'';
|
||||
|
||||
luarocksConfig' = lib.recursiveUpdate luarocksConfig
|
||||
(lib.optionalAttrs (attrs ? extraVariables) (lib.warn "extraVariables in buildLuarocksPackage is deprecated, use luarocksConfig instead"
|
||||
{
|
||||
variables = attrs.extraVariables;
|
||||
}))
|
||||
;
|
||||
in lib.recursiveUpdate generatedConfig luarocksConfig';
|
||||
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
@ -74,7 +74,11 @@ rec {
|
||||
};
|
||||
});
|
||||
|
||||
/* generate luarocks config
|
||||
|
||||
/* generate a luarocks config conforming to:
|
||||
https://github.com/luarocks/luarocks/wiki/Config-file-format
|
||||
|
||||
The config lists folders where to find lua dependencies
|
||||
|
||||
Example:
|
||||
generateLuarocksConfig {
|
||||
@ -89,7 +93,6 @@ rec {
|
||||
externalDeps ? []
|
||||
# a list of lua derivations
|
||||
, requiredLuaRocks ? []
|
||||
, extraVariables ? {}
|
||||
, rocksSubdir ? "rocks-subdir"
|
||||
, ...
|
||||
}@args: let
|
||||
@ -119,33 +122,37 @@ rec {
|
||||
externalDepsDirs = map
|
||||
(x: builtins.toString x)
|
||||
(lib.filter (lib.isDerivation) externalDeps);
|
||||
in toLua { asBindings = true; } ({
|
||||
local_cache = "";
|
||||
# To prevent collisions when creating environments, we install the rock
|
||||
# files into per-package subdirectories
|
||||
rocks_subdir = rocksSubdir;
|
||||
# first tree is the default target where new rocks are installed,
|
||||
# any other trees in the list are treated as additional sources of installed rocks for matching dependencies.
|
||||
rocks_trees = (
|
||||
[{name = "current"; root = "${placeholder "out"}"; rocks_dir = "current"; }] ++
|
||||
rocksTrees
|
||||
);
|
||||
} // lib.optionalAttrs 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 = externalDepsDirs;
|
||||
# Some needed machinery to handle multiple-output external dependencies,
|
||||
# as per https://github.com/luarocks/luarocks/issues/766
|
||||
variables = (depVariables // extraVariables);
|
||||
}
|
||||
// removeAttrs args [ "rocksSubdir" "extraVariables" "requiredLuaRocks" "externalDeps" ]
|
||||
);
|
||||
|
||||
generatedConfig = ({
|
||||
local_cache = "";
|
||||
|
||||
# To prevent collisions when creating environments, we install the rock
|
||||
# files into per-package subdirectories
|
||||
rocks_subdir = rocksSubdir;
|
||||
|
||||
# first tree is the default target where new rocks are installed,
|
||||
# any other trees in the list are treated as additional sources of installed rocks for matching dependencies.
|
||||
rocks_trees = (
|
||||
[{name = "current"; root = "${placeholder "out"}"; rocks_dir = "current"; }] ++
|
||||
rocksTrees
|
||||
);
|
||||
} // lib.optionalAttrs 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 = externalDepsDirs;
|
||||
# Some needed machinery to handle multiple-output external dependencies,
|
||||
# as per https://github.com/luarocks/luarocks/issues/766
|
||||
variables = depVariables;
|
||||
}
|
||||
// removeAttrs args [ "requiredLuaRocks" "externalDeps" ]
|
||||
);
|
||||
in generatedConfig;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ buildLuarocksPackage {
|
||||
];
|
||||
knownRockspec = "lua/nfd-scm-1.rockspec";
|
||||
|
||||
extraVariables.LUA_LIBDIR = "${lua}/lib";
|
||||
luarocksConfig.LUA_LIBDIR = "${lua}/lib";
|
||||
nativeBuildInputs = [ pkg-config ];
|
||||
|
||||
buildInputs = lib.optionals stdenv.isDarwin [ AppKit ];
|
||||
|
@ -164,7 +164,7 @@ with prev;
|
||||
});
|
||||
|
||||
ldbus = prev.ldbus.overrideAttrs (oa: {
|
||||
extraVariables = {
|
||||
luarocksConfig.variables = {
|
||||
DBUS_DIR = "${dbus.lib}";
|
||||
DBUS_ARCH_INCDIR = "${dbus.lib}/lib/dbus-1.0/include";
|
||||
DBUS_INCDIR = "${dbus.dev}/include/dbus-1.0";
|
||||
@ -309,7 +309,7 @@ with prev;
|
||||
});
|
||||
|
||||
luadbi-mysql = prev.luadbi-mysql.overrideAttrs (oa: {
|
||||
extraVariables = {
|
||||
luarocksConfig.variables = {
|
||||
# Can't just be /include and /lib, unfortunately needs the trailing 'mysql'
|
||||
MYSQL_INCDIR = "${libmysqlclient.dev}/include/mysql";
|
||||
MYSQL_LIBDIR = "${libmysqlclient}/lib/mysql";
|
||||
@ -520,7 +520,7 @@ with prev;
|
||||
buildInputs = [ libuv ];
|
||||
|
||||
# Use system libuv instead of building local and statically linking
|
||||
extraVariables = {
|
||||
luarocksConfig.variables = {
|
||||
WITH_SHARED_LIBUV = "ON";
|
||||
};
|
||||
|
||||
@ -573,6 +573,7 @@ with prev;
|
||||
'';
|
||||
});
|
||||
|
||||
# upstream broken, can't be generated, so moved out from the generated set
|
||||
readline = final.callPackage({ buildLuarocksPackage, fetchurl, luaAtLeast, luaOlder, lua, luaposix }:
|
||||
buildLuarocksPackage ({
|
||||
pname = "readline";
|
||||
@ -588,7 +589,7 @@ with prev;
|
||||
sha256 = "1mk9algpsvyqwhnq7jlw4cgmfzj30l7n2r6ak4qxgdxgc39f48k4";
|
||||
};
|
||||
|
||||
extraVariables = rec {
|
||||
luarocksConfig.variables = rec {
|
||||
READLINE_INCDIR = "${readline.dev}/include";
|
||||
HISTORY_INCDIR = READLINE_INCDIR;
|
||||
};
|
||||
@ -597,7 +598,6 @@ with prev;
|
||||
tar xf *.tar.gz
|
||||
'';
|
||||
|
||||
disabled = (luaOlder "5.1") || (luaAtLeast "5.5");
|
||||
propagatedBuildInputs = [ lua luaposix
|
||||
readline.out
|
||||
];
|
||||
@ -606,6 +606,7 @@ with prev;
|
||||
homepage = "http://pjb.com.au/comp/lua/readline.html";
|
||||
description = "Interface to the readline library";
|
||||
license.fullName = "MIT/X11";
|
||||
broken = (luaOlder "5.1") || (luaAtLeast "5.5");
|
||||
};
|
||||
})) {};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user