1 { lib, stdenv, fetchurl, readline
6 , packageOverrides ? (final: prev: {})
16 , postConfigure ? null
18 , staticOnly ? stdenv.hostPlatform.isStatic
19 , luaAttr ? "lua${sourceVersion.major}_${sourceVersion.minor}"
22 luaPackages = self.pkgs;
24 luaversion = with sourceVersion; "${major}.${minor}";
26 plat = if (stdenv.isLinux && lib.versionOlder self.luaversion "5.4") then "linux"
27 else if (stdenv.isLinux && lib.versionAtLeast self.luaversion "5.4") then "linux-readline"
28 else if stdenv.isDarwin then "macosx"
29 else if stdenv.hostPlatform.isMinGW then "mingw"
30 else if stdenv.isFreeBSD then "freebsd"
31 else if stdenv.isSunOS then "solaris"
32 else if stdenv.hostPlatform.isBSD then "bsd"
33 else if stdenv.hostPlatform.isUnix then "posix"
37 stdenv.mkDerivation rec {
39 version = "${luaversion}.${sourceVersion.patch}";
42 url = "https://www.lua.org/ftp/${pname}-${version}.tar.gz";
46 LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
47 LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
48 setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
50 nativeBuildInputs = [ makeWrapper ];
51 buildInputs = [ readline ];
55 # we can't pass flags to the lua makefile because for portability, everything is hardcoded
59 #undef LUA_PATH_DEFAULT
60 #define LUA_PATH_DEFAULT "./share/lua/${luaversion}/?.lua;./?.lua;./?/init.lua"
61 #undef LUA_CPATH_DEFAULT
62 #define LUA_CPATH_DEFAULT "./lib/lua/${luaversion}/?.so;./?.so;./lib/lua/${luaversion}/loadall.so"
65 '' + lib.optionalString (!stdenv.isDarwin && !staticOnly) ''
66 # Add a target for a shared library to the Makefile.
67 sed -e '1s/^/LUA_SO = liblua.so/' \
68 -e 's/ALL_T *= */&$(LUA_SO) /' \
70 cat ${./lua-dso.make} >> src/Makefile
73 # see configurePhase for additional flags (with space)
75 "INSTALL_TOP=${placeholder "out"}"
76 "INSTALL_MAN=${placeholder "out"}/share/man/man1"
81 "CC=${stdenv.cc.targetPrefix}cc"
82 "RANLIB=${stdenv.cc.targetPrefix}ranlib"
83 # Lua links with readline wich depends on ncurses. For some reason when
84 # building pkgsStatic.lua it fails because symbols from ncurses are not
85 # found. Adding ncurses here fixes the problem.
92 makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(${
93 if lib.versionAtLeast luaversion "5.2" then "SYSCFLAGS" else "MYCFLAGS"})' )
94 makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})
96 installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
97 TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib"
98 else ("liblua.a" + lib.optionalString (!staticOnly) " liblua.so liblua.so.${luaversion} liblua.so.${version}" )}" )
100 runHook postConfigure
102 inherit postConfigure;
107 mkdir -p "$out/share/doc/lua" "$out/lib/pkgconfig"
108 mv "doc/"*.{gif,png,css,html} "$out/share/doc/lua/"
109 rmdir $out/{share,lib}/lua/${luaversion} $out/{share,lib}/lua
110 mkdir -p "$out/lib/pkgconfig"
112 cat >"$out/lib/pkgconfig/lua.pc" <<EOF
115 includedir=$out/include
117 INSTALL_INC=$out/include
119 INSTALL_MAN=$out/man/man1
122 Description: An Extensible Extension Language
125 Libs: -L$out/lib -llua
126 Cflags: -I$out/include
128 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua-${luaversion}.pc"
129 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${luaversion}.pc"
130 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${lib.replaceStrings [ "." ] [ "" ] luaversion}.pc"
135 # When we override the interpreter we also need to override the spliced versions of the interpreter
136 inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
137 override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
139 inherit self luaversion packageOverrides luaAttr sourceVersion;
141 luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
142 luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
143 luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
144 luaOnHostForHost = override pkgsHostHost.${luaAttr};
145 luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {};
149 homepage = "https://www.lua.org";
150 description = "Powerful, fast, lightweight, embeddable scripting language";
152 Lua combines simple procedural syntax with powerful data
153 description constructs based on associative arrays and extensible
154 semantics. Lua is dynamically typed, runs by interpreting bytecode
155 for a register-based virtual machine, and has automatic memory
156 management with incremental garbage collection, making it ideal
157 for configuration, scripting, and rapid prototyping.
159 license = lib.licenses.mit;
160 platforms = lib.platforms.unix;