1# similar to interpreters/python/default.nix
2{
3 stdenv,
4 config,
5 lib,
6 callPackage,
7 fetchFromGitHub,
8 fetchurl,
9 makeBinaryWrapper,
10}:
11
12let
13
14 # Common passthru for all lua interpreters.
15 # copied from python
16 passthruFun =
17 {
18 executable,
19 luaversion,
20 packageOverrides,
21 luaOnBuildForBuild,
22 luaOnBuildForHost,
23 luaOnBuildForTarget,
24 luaOnHostForHost,
25 luaOnTargetForTarget,
26 luaAttr ? null,
27 self, # is luaOnHostForTarget
28 }:
29 let
30 luaPackages =
31 callPackage
32 # Function that when called
33 # - imports lua-packages.nix
34 # - adds spliced package sets to the package set
35 # - applies overrides from `packageOverrides`
36 (
37 {
38 lua,
39 overrides,
40 callPackage,
41 makeScopeWithSplicing',
42 }:
43 let
44 luaPackagesFun = callPackage ../../../top-level/lua-packages.nix {
45 lua = self;
46 };
47 generatedPackages =
48 if (builtins.pathExists ../../lua-modules/generated-packages.nix) then
49 (
50 final: prev:
51 callPackage ../../lua-modules/generated-packages.nix { inherit (final) callPackage; } final prev
52 )
53 else
54 (final: prev: { });
55 overriddenPackages = callPackage ../../lua-modules/overrides.nix { };
56
57 otherSplices = {
58 selfBuildBuild = luaOnBuildForBuild.pkgs;
59 selfBuildHost = luaOnBuildForHost.pkgs;
60 selfBuildTarget = luaOnBuildForTarget.pkgs;
61 selfHostHost = luaOnHostForHost.pkgs;
62 selfTargetTarget = luaOnTargetForTarget.pkgs or { };
63 };
64
65 aliases =
66 final: prev:
67 lib.optionalAttrs config.allowAliases (import ../../lua-modules/aliases.nix lib final prev);
68
69 extensions = lib.composeManyExtensions [
70 aliases
71 generatedPackages
72 overriddenPackages
73 overrides
74 ];
75 in
76 makeScopeWithSplicing' {
77 inherit otherSplices;
78 f = lib.extends extensions luaPackagesFun;
79 }
80 )
81 {
82 overrides = packageOverrides;
83 lua = self;
84 };
85 in
86 rec {
87 buildEnv = callPackage ./wrapper.nix {
88 lua = self;
89 makeWrapper = makeBinaryWrapper;
90 inherit (luaPackages) requiredLuaModules;
91 };
92 withPackages = import ./with-packages.nix { inherit buildEnv luaPackages; };
93 pkgs =
94 let
95 lp = luaPackages;
96 in
97 lp
98 // {
99 luaPackages = lp.luaPackages // {
100 __attrsFailEvaluation = true;
101 };
102 };
103 interpreter = "${self}/bin/${executable}";
104 inherit executable luaversion;
105 luaOnBuild = luaOnBuildForHost.override {
106 inherit packageOverrides;
107 self = luaOnBuild;
108 };
109
110 tests = callPackage ./tests {
111 lua = self;
112 inherit (luaPackages) wrapLua;
113 };
114
115 inherit luaAttr;
116 };
117
118in
119
120rec {
121 lua5_4 = callPackage ./interpreter.nix {
122 self = lua5_4;
123 version = "5.4.7";
124 hash = "sha256-n79eKO+GxphY9tPTTszDLpEcGii0Eg/z6EqqcM+/HjA=";
125 makeWrapper = makeBinaryWrapper;
126 inherit passthruFun;
127
128 patches = lib.optional stdenv.hostPlatform.isDarwin ./5.4.darwin.patch;
129 };
130
131 lua5_4_compat = lua5_4.override ({
132 self = lua5_4_compat;
133 compat = true;
134 });
135
136 lua5_3 = callPackage ./interpreter.nix {
137 self = lua5_3;
138 version = "5.3.6";
139 hash = "0q3d8qhd7p0b7a4mh9g7fxqksqfs6mr1nav74vq26qvkp2dxcpzw";
140 makeWrapper = makeBinaryWrapper;
141 inherit passthruFun;
142
143 patches = lib.optionals stdenv.hostPlatform.isDarwin [ ./5.2.darwin.patch ];
144 };
145
146 lua5_3_compat = lua5_3.override ({
147 self = lua5_3_compat;
148 compat = true;
149 });
150
151 lua5_2 = callPackage ./interpreter.nix {
152 self = lua5_2;
153 version = "5.2.4";
154 hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
155 makeWrapper = makeBinaryWrapper;
156 inherit passthruFun;
157 patches = [
158 ./CVE-2022-28805.patch
159 ] ++ lib.optional stdenv.hostPlatform.isDarwin ./5.2.darwin.patch;
160 };
161
162 lua5_2_compat = lua5_2.override ({
163 self = lua5_2_compat;
164 compat = true;
165 });
166
167 lua5_1 = callPackage ./interpreter.nix {
168 self = lua5_1;
169 version = "5.1.5";
170 hash = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
171 makeWrapper = makeBinaryWrapper;
172 inherit passthruFun;
173 patches = (lib.optional stdenv.hostPlatform.isDarwin ./5.1.darwin.patch) ++ [
174 ./CVE-2014-5461.patch
175 ];
176 };
177
178 luajit_2_0 = import ../luajit/2.0.nix {
179 self = luajit_2_0;
180 inherit
181 callPackage
182 fetchFromGitHub
183 lib
184 passthruFun
185 ;
186 };
187
188 luajit_2_1 = import ../luajit/2.1.nix {
189 self = luajit_2_1;
190 inherit callPackage fetchFromGitHub passthruFun;
191 };
192
193 luajit_openresty = import ../luajit/openresty.nix {
194 self = luajit_openresty;
195 inherit callPackage fetchFromGitHub passthruFun;
196 };
197}