lib/builders: pass text as file
Some checks are pending
Build and deploy documentation / deploy (push) Waiting to run
Publish every Git push to main to FlakeHub / flakehub-publish (push) Waiting to run
Publish every git push to Flakestry / publish-flake (push) Waiting to run

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 64f0d3c86a
commit 1b08a4d976

View file

@ -34,16 +34,21 @@ 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" ];
--no-editorconfig \ inherit text;
--line-endings Unix \ }
--indent-type Spaces \ ''
--indent-width 4 \ install -m 644 -T "$textPath" "$out"
"$out" stylua \
''; --no-editorconfig \
--line-endings Unix \
--indent-type Spaces \
--indent-width 4 \
"$out"
'';
/* /*
Write a byte compiled lua file to the nix store. Write a byte compiled lua file to the nix store.
@ -62,11 +67,15 @@ 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"
'';
/* /*
Get a source lua file and write a byte compiled copy of it Get a source lua file and write a byte compiled copy of it
@ -86,9 +95,14 @@ 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.
# Invalid lua files are ignored. # Invalid lua files are ignored.