Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildLuarocksPackage: accept structured luarocks config #288669

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/languages-frameworks/lua.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
40 changes: 27 additions & 13 deletions pkgs/development/interpreters/lua-5/build-luarocks-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; } ]
Expand All @@ -116,23 +117,36 @@ 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
# closure, as it doesn't have a rock tree :)
# 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
Expand Down
69 changes: 38 additions & 31 deletions pkgs/development/lua-modules/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -89,7 +93,6 @@ rec {
externalDeps ? []
# a list of lua derivations
, requiredLuaRocks ? []
, extraVariables ? {}
, rocksSubdir ? "rocks-subdir"
, ...
}@args: let
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion pkgs/development/lua-modules/nfd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
11 changes: 6 additions & 5 deletions pkgs/development/lua-modules/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
};

Expand Down Expand Up @@ -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";
Expand All @@ -588,7 +589,7 @@ with prev;
sha256 = "1mk9algpsvyqwhnq7jlw4cgmfzj30l7n2r6ak4qxgdxgc39f48k4";
};

extraVariables = rec {
luarocksConfig.variables = rec {
READLINE_INCDIR = "${readline.dev}/include";
HISTORY_INCDIR = READLINE_INCDIR;
};
Expand All @@ -597,7 +598,6 @@ with prev;
tar xf *.tar.gz
'';

disabled = (luaOlder "5.1") || (luaAtLeast "5.5");
propagatedBuildInputs = [ lua luaposix
readline.out
];
Expand All @@ -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");
};
})) {};

Expand Down
Loading