lua: add withPackages function (#54460)
* lua: add withPackages function First step towards more automation similar to the haskell backend. Follow up of https://github.com/NixOS/nixpkgs/pull/33903
This commit is contained in:
committed by
Michael Raskin
parent
16ab34c37b
commit
c4519cf8a6
@@ -10,13 +10,45 @@
|
||||
, glib, gobject-introspection, libevent, zlib, autoreconfHook, gnum4
|
||||
, mysql, postgresql, cyrus_sasl
|
||||
, fetchFromGitHub, libmpack, which, fetchpatch, writeText
|
||||
, pkgs
|
||||
, fetchgit
|
||||
, overrides ? (self: super: {})
|
||||
, lib
|
||||
}:
|
||||
|
||||
let
|
||||
isLua52 = lua.luaversion == "5.2";
|
||||
packages = ( self:
|
||||
|
||||
let
|
||||
luaAtLeast = lib.versionAtLeast lua.luaversion;
|
||||
luaOlder = lib.versionOlder lua.luaversion;
|
||||
isLua51 = (lib.versions.majorMinor lua.version) == "5.1";
|
||||
isLua52 = (lib.versions.majorMinor lua.version) == "5.2";
|
||||
isLua53 = lua.luaversion == "5.3";
|
||||
isLuaJIT = (builtins.parseDrvName lua.name).name == "luajit";
|
||||
|
||||
lua-setup-hook = callPackage ../development/interpreters/lua-5/setup-hook.nix { };
|
||||
|
||||
# Check whether a derivation provides a lua module.
|
||||
hasLuaModule = drv: drv ? luaModule ;
|
||||
|
||||
callPackage = pkgs.newScope self;
|
||||
|
||||
requiredLuaModules = drvs: with stdenv.lib; let
|
||||
modules = filter hasLuaModule drvs;
|
||||
in unique ([lua] ++ modules ++ concatLists (catAttrs "requiredLuaModules" modules));
|
||||
|
||||
# Convert derivation to a lua module.
|
||||
toLuaModule = drv:
|
||||
drv.overrideAttrs( oldAttrs: {
|
||||
# Use passthru in order to prevent rebuilds when possible.
|
||||
passthru = (oldAttrs.passthru or {})// {
|
||||
luaModule = lua;
|
||||
requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
platformString =
|
||||
if stdenv.isDarwin then "macosx"
|
||||
else if stdenv.isFreeBSD then "freebsd"
|
||||
@@ -24,10 +56,16 @@ let
|
||||
else if stdenv.isSunOS then "solaris"
|
||||
else throw "unsupported platform";
|
||||
|
||||
self = _self;
|
||||
_self = with self; {
|
||||
inherit lua;
|
||||
inherit (stdenv.lib) maintainers;
|
||||
in
|
||||
with self; {
|
||||
|
||||
getLuaPathList = majorVersion: [
|
||||
"lib/lua/${majorVersion}/?.lua" "share/lua/${majorVersion}/?.lua"
|
||||
"share/lua/${majorVersion}/?/init.lua" "lib/lua/${majorVersion}/?/init.lua"
|
||||
];
|
||||
getLuaCPathList = majorVersion: [
|
||||
"lib/lua/${majorVersion}/?.so" "share/lua/${majorVersion}/?.so" "share/lua/${majorVersion}/?/init.so"
|
||||
];
|
||||
|
||||
# helper functions for dealing with LUA_PATH and LUA_CPATH
|
||||
getPath = lib : type : "${lib}/lib/lua/${lua.luaversion}/?.${type};${lib}/share/lua/${lua.luaversion}/?.${type}";
|
||||
@@ -39,6 +77,11 @@ let
|
||||
inherit lua writeText;
|
||||
};
|
||||
|
||||
|
||||
inherit toLuaModule lua-setup-hook;
|
||||
inherit requiredLuaModules luaOlder luaAtLeast
|
||||
isLua51 isLua52 isLuaJIT lua callPackage;
|
||||
|
||||
luarocks = callPackage ../development/tools/misc/luarocks {
|
||||
inherit lua;
|
||||
};
|
||||
@@ -1078,4 +1121,5 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
}; in self
|
||||
});
|
||||
in (lib.extends overrides packages)
|
||||
|
||||
Reference in New Issue
Block a user