lib/builders: pass text as file

This fixes potential "argument list too long" errors from bash when
writing large files.
This commit is contained in:
Matt Sturgeon 2025-06-11 11:07:53 +01:00
parent 46ad5ec05c
commit 28f652a8a7
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -34,10 +34,15 @@ lib.fix (builders: {
*/ */
writeLuaWith = writeLuaWith =
pkgs: name: text: pkgs: name: text:
pkgs.runCommand name { inherit text; } '' pkgs.runCommand name
echo -n "$text" > "$out" {
nativeBuildInputs = [ pkgs.stylua ];
${lib.getExe pkgs.stylua} \ passAsFile = [ "text" ];
inherit text;
}
''
install -m 644 -T "$textPath" "$out"
stylua \
--no-editorconfig \ --no-editorconfig \
--line-endings Unix \ --line-endings Unix \
--indent-type Spaces \ --indent-type Spaces \
@ -62,10 +67,14 @@ lib.fix (builders: {
*/ */
writeByteCompiledLuaWith = writeByteCompiledLuaWith =
pkgs: name: text: pkgs: name: text:
pkgs.runCommandLocal name { inherit text; } '' pkgs.runCommandLocal name
echo -n "$text" > "$out" {
nativeBuildInputs = [ pkgs.luajit ];
${lib.getExe' pkgs.luajit "luajit"} -bd -- "$out" "$out" passAsFile = [ "text" ];
inherit text;
}
''
luajit -bd -- "$textPath" "$out"
''; '';
/* /*
@ -86,8 +95,13 @@ lib.fix (builders: {
*/ */
byteCompileLuaFileWith = byteCompileLuaFileWith =
pkgs: name: src: pkgs: name: src:
pkgs.runCommandLocal name { inherit src; } '' pkgs.runCommandLocal name
${lib.getExe' pkgs.luajit "luajit"} -bd -- "$src" "$out" {
nativeBuildInputs = [ pkgs.luajit ];
inherit src;
}
''
luajit -bd -- "$src" "$out"
''; '';
# Setup hook to byte compile all lua files in the output directory. # Setup hook to byte compile all lua files in the output directory.