summaryrefslogtreecommitdiffstats
path: root/pkgs/top-level/lua-packages.nix
diff options
context:
space:
mode:
authorMatthieu Coudron <coudron@iij.ad.jp>2019-01-30 23:13:15 +0900
committerMichael Raskin <7c6f434c@mail.ru>2019-01-30 14:13:15 +0000
commitc4519cf8a6bfdb21ced8b053953d2a8fa68c615c (patch)
tree3ea0dac7056b81a28f024d1db2df0ce97354a240 /pkgs/top-level/lua-packages.nix
parent16ab34c37b7ead2266ae24ebcf5d6e9f5cd5ab59 (diff)
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
Diffstat (limited to 'pkgs/top-level/lua-packages.nix')
-rw-r--r--pkgs/top-level/lua-packages.nix56
1 files changed, 50 insertions, 6 deletions
diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix
index 628a3f6aa45c..50dd4d1fcd9a 100644
--- a/pkgs/top-level/lua-packages.nix
+++ b/pkgs/top-level/lua-packages.nix
@@ -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)