mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-02 03:43:06 +00:00
buildLuarocksPackage: Several improvements
Summary of main changes: - Now makes use of luarocks dependency resolution (builds will fail if rockspec dependencies are unmet) - Renamed argument `external_deps` -> `exernalDeps` and add functionality to handle external dependencies that are multiple-output derivations - Added an `extraVariables` argument for appending to the contents of luarocks config `variables` table - The `rockspecFilename` argument default is now actually used - The `disabled` argument can now be overriden with a less-restrictive check, as it now just sets `meta.broken` instead of throwing an error during eval - The `doCheck` argument is now actually honored if set to `true`
This commit is contained in:
parent
f8efece8e7
commit
8eabbb3d20
@ -28,12 +28,13 @@ name ? "${attrs.pname}-${attrs.version}"
|
|||||||
, propagatedNativeBuildInputs ? []
|
, propagatedNativeBuildInputs ? []
|
||||||
|
|
||||||
# used to disable derivation, useful for specific lua versions
|
# used to disable derivation, useful for specific lua versions
|
||||||
|
# TODO move from this setting meta.broken to a 'disabled' attribute on the
|
||||||
|
# package, then use that to skip/include in each lua${ver}Packages set?
|
||||||
, disabled ? false
|
, disabled ? false
|
||||||
|
|
||||||
# Additional arguments to pass to the makeWrapper function, which wraps
|
# Additional arguments to pass to the makeWrapper function, which wraps
|
||||||
# generated binaries.
|
# generated binaries.
|
||||||
, makeWrapperArgs ? []
|
, makeWrapperArgs ? []
|
||||||
, external_deps ? propagatedBuildInputs ++ buildInputs
|
|
||||||
|
|
||||||
# Skip wrapping of lua programs altogether
|
# Skip wrapping of lua programs altogether
|
||||||
, dontWrapLuaPrograms ? false
|
, dontWrapLuaPrograms ? false
|
||||||
@ -43,11 +44,19 @@ name ? "${attrs.pname}-${attrs.version}"
|
|||||||
, passthru ? {}
|
, passthru ? {}
|
||||||
, doCheck ? false
|
, doCheck ? false
|
||||||
|
|
||||||
# appended to the luarocks generated config
|
# Non-Lua / system (e.g. C library) dependencies. Is a list of deps, where
|
||||||
# in peculiar variables like { EVENT_INCDIR } can be useful to work around
|
# each dep is either a derivation, or an attribute set like
|
||||||
# luarocks limitations, ie, luarocks consider include/lib folders to be subfolders of the same package in external_deps_dirs
|
# { name = "rockspec external_dependencies key"; dep = derivation; }
|
||||||
# as explained in https://github.com/luarocks/luarocks/issues/766
|
# The latter is used to work-around luarocks having a problem with
|
||||||
|
# multiple-output derivations as external deps:
|
||||||
|
# https://github.com/luarocks/luarocks/issues/766<Paste>
|
||||||
|
, externalDeps ? lib.unique (lib.filter (drv: !drv ? luaModule) (propagatedBuildInputs ++ buildInputs))
|
||||||
|
|
||||||
|
# Appended to the generated luarocks config
|
||||||
, extraConfig ? ""
|
, 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
|
||||||
|
|
||||||
# relative to srcRoot, path to the rockspec to use when using rocks
|
# relative to srcRoot, path to the rockspec to use when using rocks
|
||||||
, rockspecFilename ? "../*.rockspec"
|
, rockspecFilename ? "../*.rockspec"
|
||||||
@ -59,44 +68,95 @@ name ? "${attrs.pname}-${attrs.version}"
|
|||||||
|
|
||||||
|
|
||||||
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
||||||
if disabled
|
|
||||||
then throw "${name} not supported for interpreter ${lua}"
|
|
||||||
else
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
# TODO fix warnings "Couldn't load rockspec for ..." during manifest
|
||||||
deps_dirs= lib.concatStringsSep ", " (
|
# construction -- from initial investigation, appears it will require
|
||||||
map (x: "\"${builtins.toString x}\"") external_deps
|
# upstream luarocks changes to fix cleanly (during manifest construction,
|
||||||
);
|
# luarocks only looks for rockspecs in the default/system tree instead of all
|
||||||
|
# configured trees)
|
||||||
# TODO
|
luarocks_config = "luarocks-config.lua";
|
||||||
# - add rocktrees (look at torch-distro.nix/https://github.com/luarocks/luarocks/wiki/Config-file-format)
|
|
||||||
# - silence warnings
|
|
||||||
luarocks_config = "luarocksConfig";
|
|
||||||
luarocks_content = ''
|
luarocks_content = ''
|
||||||
local_cache = ""
|
local_cache = ""
|
||||||
-- array of strings
|
-- To prevent collisions when creating environments, we install the rock
|
||||||
external_deps_dirs = {
|
-- files into per-package subdirectories
|
||||||
${deps_dirs}
|
rocks_subdir = '${rocksSubdir}'
|
||||||
}
|
-- Then we need to tell luarocks where to find the rock files per
|
||||||
|
-- dependency
|
||||||
rocks_trees = {
|
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}''}
|
||||||
|
${extraVariables}
|
||||||
}
|
}
|
||||||
${extraConfig}
|
${extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
rocksSubdir = "${attrs.pname}-${version}-rocks";
|
||||||
|
|
||||||
|
externalDepsDirs = map
|
||||||
|
(x: "'${builtins.toString x}'")
|
||||||
|
(lib.filter (lib.isDerivation) externalDeps);
|
||||||
|
|
||||||
|
rocksTrees = lib.imap0
|
||||||
|
(i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
|
||||||
|
requiredLuaRocks;
|
||||||
|
|
||||||
|
# Filter out the lua derivation itself from the Lua module dependency
|
||||||
|
# closure, as it doesn't have a rock tree :)
|
||||||
|
requiredLuaRocks = lib.filter (d: d ? luaModule)
|
||||||
|
(lua.pkgs.requiredLuaModules propagatedBuildInputs);
|
||||||
|
|
||||||
|
# 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;
|
||||||
in
|
in
|
||||||
toLuaModule ( lua.stdenv.mkDerivation (
|
toLuaModule ( lua.stdenv.mkDerivation (
|
||||||
builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
|
builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps"] // {
|
||||||
|
|
||||||
name = namePrefix + name;
|
name = namePrefix + name;
|
||||||
|
|
||||||
buildInputs = [ wrapLua lua.pkgs.luarocks ]
|
buildInputs = [ wrapLua lua.pkgs.luarocks ]
|
||||||
++ buildInputs
|
++ buildInputs
|
||||||
++ lib.optionals doCheck checkInputs
|
++ lib.optionals doCheck checkInputs
|
||||||
|
++ (map (d: d.dep) externalDeps')
|
||||||
;
|
;
|
||||||
|
|
||||||
# propagate lua to active setup-hook in nix-shell
|
# propagate lua to active setup-hook in nix-shell
|
||||||
propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
|
propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
|
||||||
doCheck = false;
|
inherit doCheck;
|
||||||
|
|
||||||
|
# @-patterns do not capture formal argument default values, so we need to
|
||||||
|
# explicitly inherit this for it to be available as a shell variable in the
|
||||||
|
# builder
|
||||||
|
inherit rockspecFilename;
|
||||||
|
inherit rocksSubdir;
|
||||||
|
|
||||||
# enabled only for src.rock
|
# enabled only for src.rock
|
||||||
setSourceRoot= let
|
setSourceRoot= let
|
||||||
@ -163,23 +223,20 @@ builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
|
|||||||
|
|
||||||
nix_debug "ROCKSPEC $rockspecFilename"
|
nix_debug "ROCKSPEC $rockspecFilename"
|
||||||
nix_debug "cwd: $PWD"
|
nix_debug "cwd: $PWD"
|
||||||
$LUAROCKS make --deps-mode=none --tree $out ''${rockspecFilename}
|
$LUAROCKS make --deps-mode=all --tree=$out ''${rockspecFilename}
|
||||||
|
|
||||||
# to prevent collisions when creating environments
|
|
||||||
# also added -f as it doesn't always exist
|
|
||||||
# don't remove the whole directory as
|
|
||||||
rm -rf $out/lib/luarocks/rocks-${lua.luaversion}/manifest
|
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
inherit lua; # The lua interpreter
|
inherit lua; # The lua interpreter
|
||||||
|
inherit externalDeps;
|
||||||
} // passthru;
|
} // passthru;
|
||||||
|
|
||||||
meta = with lib.maintainers; {
|
meta = with lib.maintainers; {
|
||||||
platforms = lua.meta.platforms;
|
platforms = lua.meta.platforms;
|
||||||
# add extra maintainer(s) to every package
|
# add extra maintainer(s) to every package
|
||||||
maintainers = (meta.maintainers or []) ++ [ ];
|
maintainers = (meta.maintainers or []) ++ [ ];
|
||||||
|
broken = disabled;
|
||||||
} // meta;
|
} // meta;
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user