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:
Matthieu Coudron
2019-01-30 23:13:15 +09:00
committed by Michael Raskin
parent 16ab34c37b
commit c4519cf8a6
16 changed files with 381 additions and 82 deletions

View File

@@ -0,0 +1,10 @@
{ self, callPackage, lib }:
callPackage ./default.nix {
inherit self;
version = "2.0.5";
isStable = true;
sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7";
extraMeta = {
platforms = lib.filter (p: p != "aarch64-linux") lib.meta.platforms;
};
}

View File

@@ -0,0 +1,7 @@
{ self, callPackage, lib }:
callPackage ./default.nix {
inherit self;
version = "2.1.0-beta3";
isStable = false;
sha256 = "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs";
}

View File

@@ -1,71 +1,74 @@
{ stdenv, lib, fetchurl }:
rec {
{ stdenv, lib, fetchurl
, name ? "luajit-${version}"
, isStable
, sha256
, version
, extraMeta ? {}
, callPackage
, self
, packageOverrides ? (self: super: {})
}:
let
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
in
stdenv.mkDerivation rec {
inherit name version;
src = fetchurl {
url = "http://luajit.org/download/LuaJIT-${version}.tar.gz";
inherit sha256;
};
luajit = luajit_2_1;
luaversion = "5.1";
luajit_2_0 = generic {
version = "2.0.5";
isStable = true;
sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7";
meta = genericMeta // {
platforms = lib.filter (p: p != "aarch64-linux") genericMeta.platforms;
patchPhase = ''
substituteInPlace Makefile \
--replace /usr/local "$out"
substituteInPlace src/Makefile --replace gcc cc
'' + stdenv.lib.optionalString (stdenv.cc.libc != null)
''
substituteInPlace Makefile \
--replace ldconfig ${stdenv.cc.libc.bin or stdenv.cc.libc}/bin/ldconfig
'';
configurePhase = false;
buildFlags = [ "amalg" ]; # Build highly optimized version
enableParallelBuilding = true;
installPhase = ''
make install PREFIX="$out"
( cd "$out/include"; ln -s luajit-*/* . )
ln -s "$out"/bin/luajit-* "$out"/bin/lua
''
+ stdenv.lib.optionalString (!isStable) ''
ln -s "$out"/bin/luajit-* "$out"/bin/luajit
'';
LuaPathSearchPaths = [
"lib/lua/${luaversion}/?.lua" "share/lua/${luaversion}/?.lua"
"share/lua/${luaversion}/?/init.lua" "lib/lua/${luaversion}/?/init.lua"
"share/${name}/?.lua"
];
LuaCPathSearchPaths = [ "lib/lua/${luaversion}/?.so" "share/lua/${luaversion}/?.so" ];
setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
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";
};
luajit_2_1 = generic {
version = "2.1.0-beta3";
isStable = false;
sha256 = "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs";
};
genericMeta = with stdenv.lib; {
meta = with stdenv.lib; extraMeta // {
description = "High-performance JIT compiler for Lua 5.1";
homepage = http://luajit.org;
license = licenses.mit;
platforms = platforms.linux ++ platforms.darwin;
maintainers = with maintainers; [ thoughtpolice smironov vcunat andir ];
};
generic =
{ version, sha256 ? null, isStable
, name ? "luajit-${version}"
, src ?
(fetchurl {
url = "http://luajit.org/download/LuaJIT-${version}.tar.gz";
inherit sha256;
})
, meta ? genericMeta
}:
stdenv.mkDerivation rec {
inherit name version src meta;
luaversion = "5.1";
patchPhase = ''
substituteInPlace Makefile \
--replace /usr/local "$out"
substituteInPlace src/Makefile --replace gcc cc
'' + stdenv.lib.optionalString (stdenv.cc.libc != null)
''
substituteInPlace Makefile \
--replace ldconfig ${stdenv.cc.libc.bin or stdenv.cc.libc}/bin/ldconfig
'';
configurePhase = false;
buildFlags = [ "amalg" ]; # Build highly optimized version
enableParallelBuilding = true;
installPhase = ''
make install PREFIX="$out"
( cd "$out/include"; ln -s luajit-*/* . )
ln -s "$out"/bin/luajit-* "$out"/bin/lua
''
+ stdenv.lib.optionalString (!isStable)
''
ln -s "$out"/bin/luajit-* "$out"/bin/luajit
'';
};
}