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