9 , packageOverrides ? (final: prev: {})
18 , enableJITDebugModule ? enableJIT
20 , enable52Compat ? false
21 , enableValgrindSupport ? false
23 , enableGDBJITSupport ? false
24 , enableAPICheck ? false
25 , enableVMAssertions ? false
26 , enableRegisterAllocationRandomization ? false
27 , useSystemMalloc ? false
28 # Upstream generates randomized string id's by default for security reasons
29 # https://github.com/LuaJIT/LuaJIT/issues/626. Deterministic string id's should
30 # never be needed for correctness (that should be fixed in the lua code),
31 # but may be helpful when you want to embed jit-compiled raw lua blobs in
32 # binaries that you want to be reproducible.
33 , deterministicStringIds ? false
34 , luaAttr ? "luajit_${lib.versions.major version}_${lib.versions.minor version}"
36 assert enableJITDebugModule -> enableJIT;
37 assert enableGDBJITSupport -> enableJIT;
38 assert enableValgrindSupport -> valgrind != null;
41 luaPackages = self.pkgs;
44 lib.optional (!enableFFI) "-DLUAJIT_DISABLE_FFI"
45 ++ lib.optional (!enableJIT) "-DLUAJIT_DISABLE_JIT"
46 ++ lib.optional enable52Compat "-DLUAJIT_ENABLE_LUA52COMPAT"
47 ++ lib.optional (!enableGC64) "-DLUAJIT_DISABLE_GC64"
48 ++ lib.optional useSystemMalloc "-DLUAJIT_USE_SYSMALLOC"
49 ++ lib.optional enableValgrindSupport "-DLUAJIT_USE_VALGRIND"
50 ++ lib.optional enableGDBJITSupport "-DLUAJIT_USE_GDBJIT"
51 ++ lib.optional enableAPICheck "-DLUAJIT_USE_APICHECK"
52 ++ lib.optional enableVMAssertions "-DLUAJIT_USE_ASSERT"
53 ++ lib.optional enableRegisterAllocationRandomization "-DLUAJIT_RANDOM_RA"
54 ++ lib.optional deterministicStringIds "-DLUAJIT_SECURITY_STRID=0"
57 # LuaJIT requires build for 32bit architectures to be build on x86 not x86_64
58 # TODO support also other build architectures. The ideal way would be to use
59 # stdenv_32bit but that doesn't work due to host platform mismatch:
60 # https://github.com/NixOS/nixpkgs/issues/212494
61 buildStdenv = if buildPackages.stdenv.hostPlatform.isx86_64 && stdenv.hostPlatform.is32bit
62 then buildPackages.pkgsi686Linux.buildPackages.stdenv
63 else buildPackages.stdenv;
66 stdenv.mkDerivation (finalAttrs: {
73 substituteInPlace Makefile --replace ldconfig :
74 if test -n "''${dontStrip-}"; then
75 # CCDEBUG must be non-empty or everything will be stripped, -g being
76 # passed by nixpkgs CC wrapper is insufficient on its own
77 substituteInPlace src/Makefile --replace-fail "#CCDEBUG= -g" "CCDEBUG= -g"
83 buildInputs = lib.optional enableValgrindSupport valgrind;
86 "amalg" # Build highly optimized version
91 "CROSS=${stdenv.cc.targetPrefix}"
92 "HOST_CC=${buildStdenv.cc}/bin/cc"
93 ] ++ lib.optional enableJITDebugModule "INSTALL_LJLIBD=$(INSTALL_LMOD)"
94 ++ lib.optional stdenv.hostPlatform.isStatic "BUILDMODE=static";
95 enableParallelBuilding = true;
96 env.NIX_CFLAGS_COMPILE = toString XCFLAGS;
99 mkdir -p $out/nix-support
101 src = ../lua-5/utils.sh;
102 luapathsearchpaths=lib.escapeShellArgs finalAttrs.LuaPathSearchPaths;
103 luacpathsearchpaths=lib.escapeShellArgs finalAttrs.LuaCPathSearchPaths;
104 }} $out/nix-support/utils.sh
105 ( cd "$out/include"; ln -s luajit-*/* . )
106 ln -s "$out"/bin/luajit-* "$out"/bin/lua
107 if [[ ! -e "$out"/bin/luajit ]]; then
108 ln -s "$out"/bin/luajit* "$out"/bin/luajit
112 LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
113 LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
115 setupHook = builtins.toFile "lua-setup-hook" ''
116 source @out@/nix-support/utils.sh
117 addEnvHooks "$hostOffset" luaEnvHook
122 # When we override the interpreter we also need to override the spliced versions of the interpreter
123 inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
124 override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
126 inherit self packageOverrides luaAttr;
127 inherit (finalAttrs) luaversion;
129 luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
130 luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
131 luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
132 luaOnHostForHost = override pkgsHostHost.${luaAttr};
133 luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr});
137 description = "High-performance JIT compiler for Lua 5.1";
138 homepage = "https://luajit.org/";
139 license = licenses.mit;
140 platforms = platforms.linux ++ platforms.darwin;
142 "riscv64-linux" "riscv64-linux" # See https://github.com/LuaJIT/LuaJIT/issues/628
143 "powerpc64le-linux" # `#error "No support for PPC64"`
145 maintainers = with maintainers; [ thoughtpolice smironov vcunat lblasc ];