luaPackages: copy passthruFun from python

This commit is contained in:
Artturin
2022-08-26 20:55:30 +03:00
parent bdb8ca175a
commit 39571bd6fa
8 changed files with 150 additions and 95 deletions
@@ -1,7 +1,6 @@
# Generic builder for lua packages
{ lib
, lua
, buildPackages
, wrapLua
, luarocks
# Whether the derivation provides a lua module or not.
@@ -14,9 +13,7 @@ pname
, version
# by default prefix `name` e.g. "lua5.2-${name}"
, namePrefix ? if lua.pkgs.isLuaJIT
then lua.name + "-"
else "lua" + lua.luaversion + "-"
, namePrefix ? "${lua.pname}${lua.sourceVersion.major}.${lua.sourceVersion.minor}-"
# Dependencies for building the package
, buildInputs ? []
@@ -1,11 +1,86 @@
# similar to interpreters/python/default.nix
{ stdenv, lib, callPackage, fetchurl, fetchpatch, makeBinaryWrapper }:
let
# Common passthru for all lua interpreters.
# copied from python
passthruFun =
{ executable
, sourceVersion
, luaversion
, packageOverrides
, luaOnBuildForBuild
, luaOnBuildForHost
, luaOnBuildForTarget
, luaOnHostForHost
, luaOnTargetForTarget
, luaAttr ? null
, self # is luaOnHostForTarget
}: let
luaPackages = callPackage
# Function that when called
# - imports lua-packages.nix
# - adds spliced package sets to the package set
# - applies overrides from `packageOverrides`
({ lua, overrides, callPackage, splicePackages, newScope }: let
luaPackagesFun = callPackage ../../../top-level/lua-packages.nix {
lua = self;
};
generatedPackages = if (builtins.pathExists ../../lua-modules/generated-packages.nix) then
(final: prev: callPackage ../../lua-modules/generated-packages.nix { inherit (final) callPackage; } final prev)
else (final: prev: {});
overridenPackages = callPackage ../../lua-modules/overrides.nix { };
otherSplices = {
selfBuildBuild = luaOnBuildForBuild.pkgs;
selfBuildHost = luaOnBuildForHost.pkgs;
selfBuildTarget = luaOnBuildForTarget.pkgs;
selfHostHost = luaOnHostForHost.pkgs;
selfTargetTarget = luaOnTargetForTarget.pkgs or {};
};
keep = self: { };
extra = spliced0: {};
extensions = lib.composeManyExtensions [
generatedPackages
overridenPackages
overrides
];
in lib.makeScopeWithSplicing
splicePackages
newScope
otherSplices
keep
extra
(lib.extends extensions luaPackagesFun))
{
overrides = packageOverrides;
lua = self;
};
in rec {
buildEnv = callPackage ./wrapper.nix {
lua = self;
inherit (luaPackages) requiredLuaModules;
};
withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
pkgs = luaPackages;
interpreter = "${self}/bin/${executable}";
inherit executable luaversion sourceVersion;
luaOnBuild = luaOnBuildForHost.override { inherit packageOverrides; self = luaOnBuild; };
inherit luaAttr;
};
in
rec {
lua5_4 = callPackage ./interpreter.nix {
self = lua5_4;
sourceVersion = { major = "5"; minor = "4"; patch = "3"; };
hash = "1yxvjvnbg4nyrdv10bq42gz6dr66pyan28lgzfygqfwy2rv24qgq";
makeWrapper = makeBinaryWrapper;
inherit passthruFun;
patches = lib.optional stdenv.isDarwin ./5.4.darwin.patch
++ [
@@ -28,53 +103,62 @@ rec {
};
lua5_4_compat = lua5_4.override({
self = lua5_4_compat;
compat = true;
});
lua5_3 = callPackage ./interpreter.nix {
self = lua5_3;
sourceVersion = { major = "5"; minor = "3"; patch = "6"; };
hash = "0q3d8qhd7p0b7a4mh9g7fxqksqfs6mr1nav74vq26qvkp2dxcpzw";
makeWrapper = makeBinaryWrapper;
inherit passthruFun;
patches =
lib.optionals stdenv.isDarwin [ ./5.2.darwin.patch ];
};
lua5_3_compat = lua5_3.override({
self = lua5_3_compat;
compat = true;
});
lua5_2 = callPackage ./interpreter.nix {
self = lua5_2;
sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
makeWrapper = makeBinaryWrapper;
inherit passthruFun;
patches = [
./CVE-2022-28805.patch
] ++ lib.optional stdenv.isDarwin ./5.2.darwin.patch;
};
lua5_2_compat = lua5_2.override({
self = lua5_2_compat;
compat = true;
});
lua5_1 = callPackage ./interpreter.nix {
self = lua5_1;
sourceVersion = { major = "5"; minor = "1"; patch = "5"; };
hash = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
makeWrapper = makeBinaryWrapper;
inherit passthruFun;
patches = (lib.optional stdenv.isDarwin ./5.1.darwin.patch)
++ [ ./CVE-2014-5461.patch ];
};
luajit_2_0 = import ../luajit/2.0.nix {
self = luajit_2_0;
inherit callPackage lib;
inherit callPackage lib passthruFun;
};
luajit_2_1 = import ../luajit/2.1.nix {
self = luajit_2_1;
inherit callPackage;
inherit callPackage passthruFun;
};
}
@@ -2,22 +2,26 @@
, compat ? false
, callPackage
, makeWrapper
, self
, packageOverrides ? (final: prev: {})
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
, pkgsHostHost
, pkgsTargetTarget
, sourceVersion
, hash
, passthruFun
, patches ? []
, postConfigure ? null
, postBuild ? null
, staticOnly ? stdenv.hostPlatform.isStatic
}:
, luaAttr ? "lua${sourceVersion.major}_${sourceVersion.minor}"
} @ inputs:
let
luaversion = with sourceVersion; "${major}.${minor}";
luaPackages = self.pkgs;
luaPackages = callPackage ../../lua-modules {
lua = self;
overrides = packageOverrides;
packagesAttr = "lua${lib.replaceChars ["."] ["_"] luaversion}.pkgs";
};
luaversion = with sourceVersion; "${major}.${minor}";
plat = if (stdenv.isLinux && lib.versionOlder self.luaversion "5.4") then "linux"
else if (stdenv.isLinux && lib.versionAtLeast self.luaversion "5.4") then "linux-readline"
@@ -28,8 +32,9 @@ plat = if (stdenv.isLinux && lib.versionOlder self.luaversion "5.4") then "linux
else if stdenv.hostPlatform.isBSD then "bsd"
else if stdenv.hostPlatform.isUnix then "posix"
else "generic";
in
self = stdenv.mkDerivation rec {
stdenv.mkDerivation rec {
pname = "lua";
version = "${luaversion}.${sourceVersion.patch}";
@@ -125,16 +130,19 @@ self = stdenv.mkDerivation rec {
ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${lib.replaceStrings [ "." ] [ "" ] luaversion}.pc"
'';
passthru = rec {
inherit luaversion;
buildEnv = callPackage ./wrapper.nix {
lua = self;
inherit makeWrapper;
inherit (luaPackages) requiredLuaModules;
};
withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
pkgs = luaPackages;
interpreter = "${self}/bin/lua";
# copied from python
passthru = let
# When we override the interpreter we also need to override the spliced versions of the interpreter
inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
in passthruFun rec {
inherit self luaversion packageOverrides luaAttr sourceVersion;
executable = "lua";
luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
luaOnHostForHost = override pkgsHostHost.${luaAttr};
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {};
};
meta = {
@@ -151,5 +159,4 @@ self = stdenv.mkDerivation rec {
license = lib.licenses.mit;
platforms = lib.platforms.unix;
};
};
in self
}
+3 -3
View File
@@ -1,7 +1,7 @@
{ self, callPackage, lib }:
{ self, callPackage, lib, passthruFun }:
callPackage ./default.nix {
inherit self;
packagesAttr = "luajit_2_0.pkgs";
sourceVersion = { major = "2"; minor = "0"; patch = "5"; };
inherit self passthruFun;
version = "2.0.5-2022-03-13";
rev = "93a65d3cc263aef2d2feb3d7ff2206aca3bee17e";
isStable = true;
+3 -3
View File
@@ -1,7 +1,7 @@
{ self, callPackage }:
{ self, callPackage, passthruFun }:
callPackage ./default.nix {
inherit self;
packagesAttr = "luajit_2_1.pkgs";
sourceVersion = { major = "2"; minor = "1"; patch = "0"; };
inherit self passthruFun;
version = "2.1.0-2022-04-05";
rev = "5e3c45c43bb0e0f1f2917d432e9d2dba12c42a6e";
isStable = false;
@@ -2,16 +2,21 @@
, stdenv
, fetchFromGitHub
, buildPackages
, name ? "luajit-${version}"
, isStable
, hash
, rev
, version
, packagesAttr
, extraMeta ? { }
, callPackage
, self
, packageOverrides ? (final: prev: {})
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
, pkgsHostHost
, pkgsTargetTarget
, sourceVersion
, passthruFun
, enableFFI ? true
, enableJIT ? true
, enableJITDebugModule ? enableJIT
@@ -23,16 +28,14 @@
, enableAPICheck ? false
, enableVMAssertions ? false
, useSystemMalloc ? false
}:
, luaAttr ? "luajit_${sourceVersion.major}_${sourceVersion.minor}"
} @ inputs:
assert enableJITDebugModule -> enableJIT;
assert enableGDBJITSupport -> enableJIT;
assert enableValgrindSupport -> valgrind != null;
let
luaPackages = callPackage ../../lua-modules {
lua = self;
overrides = packageOverrides;
inherit packagesAttr;
};
luaPackages = self.pkgs;
XCFLAGS = with lib;
optional (!enableFFI) "-DLUAJIT_DISABLE_FFI"
@@ -47,7 +50,8 @@ let
;
in
stdenv.mkDerivation rec {
inherit name version;
pname = "luajit";
inherit version;
src = fetchFromGitHub {
owner = "LuaJIT";
repo = "LuaJIT";
@@ -103,14 +107,19 @@ stdenv.mkDerivation rec {
setupHook = luaPackages.lua-setup-hook luaPackages.luaLib.luaPathList luaPackages.luaLib.luaCPathList;
passthru = rec {
buildEnv = callPackage ../lua-5/wrapper.nix {
lua = self;
inherit (luaPackages) requiredLuaModules;
};
withPackages = import ../lua-5/with-packages.nix { inherit buildEnv luaPackages; };
pkgs = luaPackages;
interpreter = "${self}/bin/lua";
# copied from python
passthru = let
# When we override the interpreter we also need to override the spliced versions of the interpreter
inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
in passthruFun rec {
inherit self luaversion packageOverrides luaAttr sourceVersion;
executable = "lua";
luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
luaOnHostForHost = override pkgsHostHost.${luaAttr};
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {};
};
meta = with lib; {
-43
View File
@@ -1,43 +0,0 @@
# inspired by pkgs/development/haskell-modules/default.nix
{ pkgs, lib
, lua
, packagesAttr
, stdenv
, callPackage
, overrides ? (final: prev: {})
}:
let
inherit (lib) extends;
initialPackages = import ../../top-level/lua-packages.nix {
inherit lua pkgs lib stdenv;
};
overridenPackages = callPackage ./overrides.nix { };
generatedPackages = if (builtins.pathExists ./generated-packages.nix) then
(final: prev: callPackage ./generated-packages.nix { inherit (final) callPackage; } final prev) else (final: prev: {});
extensions = lib.composeManyExtensions [
generatedPackages
overridenPackages
overrides
];
otherSplices = let
packagesAttrFun = set: lib.getAttrFromPath (lib.splitString "." packagesAttr) set;
in {
selfBuildBuild = packagesAttrFun pkgs.pkgsBuildBuild;
selfBuildHost = packagesAttrFun pkgs.pkgsBuildHost;
selfBuildTarget = packagesAttrFun pkgs.pkgsBuildTarget;
selfHostHost = packagesAttrFun pkgs.pkgsHostHost;
selfTargetTarget = if pkgs.pkgsTargetTarget.__raw or false then {} else packagesAttrFun pkgs.pkgsTargetTarget; # might be missing;
};
keep = self: { };
extra = spliced0: { };
in
lib.makeScopeWithSplicing pkgs.splicePackages pkgs.newScope otherSplices keep extra
(lib.extends extensions initialPackages)
+4 -3
View File
@@ -5,12 +5,13 @@
for each package in a separate file: the call to the function would
be almost as must code as the function itself. */
{ stdenv
, lua
, pkgs
{ pkgs
, stdenv
, lib
, lua
}:
self:
let