dotfiles/overlays/builders.nix

63 lines
1.4 KiB
Nix
Raw Normal View History

2023-07-04 11:44:55 +02:00
_:
final: _:
with final.lib;
2023-09-10 15:07:55 +02:00
rec {
fishFile =
{ name
, destination
, content
, checkPhase ? null
}:
final.writeTextFile {
inherit name destination;
executable = true;
allowSubstitutes = true;
preferLocalBuild = false;
text = ''
#!${getExe final.fish}
${content}
'';
checkPhase =
if checkPhase == null then ''
runHook preCheck
${getExe final.fish} -n "$target"
runHook postCheck
''
else checkPhase;
};
2023-07-04 11:44:55 +02:00
writeFishApplication =
{ name
, text
, completions ? null
, runtimeInputs ? [ ]
, checkPhase ? null
}:
let
2023-09-10 15:07:55 +02:00
runtimeHeader = optionalString (runtimeInputs != [ ])
''export PATH="${makeBinPath runtimeInputs}:$PATH"'';
2023-07-04 11:44:55 +02:00
2023-09-10 15:07:55 +02:00
script = fishFile {
inherit checkPhase;
name = "${name}_script";
destination = "/bin/${name}";
content = concatLines [ runtimeHeader text ];
};
completions_file = fishFile {
inherit checkPhase;
name = "${name}_completions";
destination = "/share/fish/vendor_completions.d/${name}.fish";
content = concatLines [ runtimeHeader completions ];
2023-07-04 11:44:55 +02:00
};
in
final.symlinkJoin {
inherit name;
paths = [
script
] ++ optional (completions != null) completions_file;
};
}