Skip to content

Commit 1b08a4d

Browse files
committed
lib/builders: pass text as file
This fixes potential "argument list too long" errors from bash when writing large files.
1 parent 64f0d3c commit 1b08a4d

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

lib/builders.nix

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,21 @@ lib.fix (builders: {
3434
*/
3535
writeLuaWith =
3636
pkgs: name: text:
37-
pkgs.runCommand name { inherit text; } ''
38-
echo -n "$text" > "$out"
39-
40-
${lib.getExe pkgs.stylua} \
41-
--no-editorconfig \
42-
--line-endings Unix \
43-
--indent-type Spaces \
44-
--indent-width 4 \
45-
"$out"
46-
'';
37+
pkgs.runCommand name
38+
{
39+
nativeBuildInputs = [ pkgs.stylua ];
40+
passAsFile = [ "text" ];
41+
inherit text;
42+
}
43+
''
44+
install -m 644 -T "$textPath" "$out"
45+
stylua \
46+
--no-editorconfig \
47+
--line-endings Unix \
48+
--indent-type Spaces \
49+
--indent-width 4 \
50+
"$out"
51+
'';
4752

4853
/*
4954
Write a byte compiled lua file to the nix store.
@@ -62,11 +67,15 @@ lib.fix (builders: {
6267
*/
6368
writeByteCompiledLuaWith =
6469
pkgs: name: text:
65-
pkgs.runCommandLocal name { inherit text; } ''
66-
echo -n "$text" > "$out"
67-
68-
${lib.getExe' pkgs.luajit "luajit"} -bd -- "$out" "$out"
69-
'';
70+
pkgs.runCommandLocal name
71+
{
72+
nativeBuildInputs = [ pkgs.luajit ];
73+
passAsFile = [ "text" ];
74+
inherit text;
75+
}
76+
''
77+
luajit -bd -- "$textPath" "$out"
78+
'';
7079

7180
/*
7281
Get a source lua file and write a byte compiled copy of it
@@ -86,9 +95,14 @@ lib.fix (builders: {
8695
*/
8796
byteCompileLuaFileWith =
8897
pkgs: name: src:
89-
pkgs.runCommandLocal name { inherit src; } ''
90-
${lib.getExe' pkgs.luajit "luajit"} -bd -- "$src" "$out"
91-
'';
98+
pkgs.runCommandLocal name
99+
{
100+
nativeBuildInputs = [ pkgs.luajit ];
101+
inherit src;
102+
}
103+
''
104+
luajit -bd -- "$src" "$out"
105+
'';
92106

93107
# Setup hook to byte compile all lua files in the output directory.
94108
# Invalid lua files are ignored.

0 commit comments

Comments
 (0)