1 { lib, stdenv, fetchurl, readline
5 , packageOverrides ? (final: prev: {})
16 , postConfigure ? null
18 , staticOnly ? stdenv.hostPlatform.isStatic
19 , luaAttr ? "lua${lib.versions.major version}_${lib.versions.minor version}"
22 stdenv.mkDerivation (finalAttrs:
24 luaPackages = self.pkgs;
26 luaversion = lib.versions.majorMinor finalAttrs.version;
28 plat = if (stdenv.hostPlatform.isLinux && lib.versionOlder self.luaversion "5.4") then "linux"
29 else if (stdenv.hostPlatform.isLinux && lib.versionAtLeast self.luaversion "5.4") then "linux-readline"
30 else if stdenv.hostPlatform.isDarwin then "macosx"
31 else if stdenv.hostPlatform.isMinGW then "mingw"
32 else if stdenv.hostPlatform.isFreeBSD then "freebsd"
33 else if stdenv.hostPlatform.isSunOS then "solaris"
34 else if stdenv.hostPlatform.isBSD then "bsd"
35 else if stdenv.hostPlatform.isUnix then "posix"
38 compatFlags = if (lib.versionOlder self.luaversion "5.3") then " -DLUA_COMPAT_ALL"
39 else if (lib.versionOlder self.luaversion "5.4") then " -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2"
40 else " -DLUA_COMPAT_5_3";
46 outputs = [ "out" "doc" ];
49 url = "https://www.lua.org/ftp/lua-${finalAttrs.version}.tar.gz";
53 LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
54 LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
55 setupHook = builtins.toFile "lua-setup-hook" ''
56 source @out@/nix-support/utils.sh
57 addEnvHooks "$hostOffset" luaEnvHook
60 nativeBuildInputs = [ makeWrapper ];
61 buildInputs = [ readline ];
66 sed -i "s@#define LUA_ROOT[[:space:]]*\"/usr/local/\"@#define LUA_ROOT \"$out/\"@g" src/luaconf.h
68 # abort if patching didn't work
69 grep $out src/luaconf.h
70 '' + lib.optionalString (!stdenv.hostPlatform.isDarwin && !staticOnly) ''
71 # Add a target for a shared library to the Makefile.
72 sed -e '1s/^/LUA_SO = liblua.so/' \
73 -e 's/ALL_T *= */&$(LUA_SO) /' \
75 cat ${./lua-dso.make} >> src/Makefile
78 # see configurePhase for additional flags (with space)
80 "INSTALL_TOP=${placeholder "out"}"
81 "INSTALL_MAN=${placeholder "out"}/share/man/man1"
86 "CC=${stdenv.cc.targetPrefix}cc"
87 "RANLIB=${stdenv.cc.targetPrefix}ranlib"
88 # Lua links with readline wich depends on ncurses. For some reason when
89 # building pkgsStatic.lua it fails because symbols from ncurses are not
90 # found. Adding ncurses here fixes the problem.
97 makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat compatFlags} $(${
98 if lib.versionAtLeast luaversion "5.2" then "SYSCFLAGS" else "MYCFLAGS"})' )
99 makeFlagsArray+=(${lib.optionalString stdenv.hostPlatform.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})
101 installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
102 TO_LIB="${if stdenv.hostPlatform.isDarwin then "liblua.${finalAttrs.version}.dylib"
103 else ("liblua.a" + lib.optionalString (!staticOnly) " liblua.so liblua.so.${luaversion} liblua.so.${finalAttrs.version}" )}" )
105 runHook postConfigure
107 inherit postConfigure;
112 mkdir -p "$out/nix-support" "$out/share/doc/lua" "$out/lib/pkgconfig"
115 luapathsearchpaths=lib.escapeShellArgs finalAttrs.LuaPathSearchPaths;
116 luacpathsearchpaths=lib.escapeShellArgs finalAttrs.LuaCPathSearchPaths;
117 }} $out/nix-support/utils.sh
118 mv "doc/"*.{gif,png,css,html} "$out/share/doc/lua/"
119 rmdir $out/{share,lib}/lua/${luaversion} $out/{share,lib}/lua
120 mkdir -p "$out/lib/pkgconfig"
122 cat >"$out/lib/pkgconfig/lua.pc" <<EOF
125 includedir=$out/include
127 INSTALL_INC=$out/include
129 INSTALL_MAN=$out/man/man1
132 Description: An Extensible Extension Language
133 Version: ${finalAttrs.version}
135 Libs: -L$out/lib -llua
136 Cflags: -I$out/include
138 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua-${luaversion}.pc"
139 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${luaversion}.pc"
140 ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${lib.replaceStrings [ "." ] [ "" ] luaversion}.pc"
142 # Make documentation outputs of different versions co-installable.
143 mv $out/share/doc/lua $out/share/doc/lua-${finalAttrs.version}
148 # When we override the interpreter we also need to override the spliced versions of the interpreter
149 inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
150 override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
152 inherit self luaversion packageOverrides luaAttr;
154 luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
155 luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
156 luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
157 luaOnHostForHost = override pkgsHostHost.${luaAttr};
158 luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr});
162 homepage = "https://www.lua.org";
163 description = "Powerful, fast, lightweight, embeddable scripting language";
165 Lua combines simple procedural syntax with powerful data
166 description constructs based on associative arrays and extensible
167 semantics. Lua is dynamically typed, runs by interpreting bytecode
168 for a register-based virtual machine, and has automatic memory
169 management with incremental garbage collection, making it ideal
170 for configuration, scripting, and rapid prototyping.
173 license = lib.licenses.mit;
174 platforms = lib.platforms.unix;