refactor: small changes

This commit is contained in:
Moritz Böhme 2023-09-10 15:07:55 +02:00
parent 749e2cf67d
commit 372ee5985a
No known key found for this signature in database
GPG key ID: 970C6E89EB0547A9
4 changed files with 86 additions and 54 deletions

View file

@ -2,7 +2,33 @@ _:
final: _:
with final.lib;
{
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;
};
writeFishApplication =
{ name
, text
@ -11,30 +37,21 @@ with final.lib;
, checkPhase ? null
}:
let
fishFile = destination: content: final.writeTextFile {
inherit name destination;
executable = true;
allowSubstitutes = true;
preferLocalBuild = false;
text = ''
#!${getExe final.fish}
runtimeHeader = optionalString (runtimeInputs != [ ])
''export PATH="${makeBinPath runtimeInputs}:$PATH"'';
${optionalString (runtimeInputs != [ ]) ''export PATH="${makeBinPath runtimeInputs}:$PATH"''}
${content}
'';
checkPhase =
if checkPhase == null then ''
runHook preCheck
${getExe final.fish} -n "$target"
runHook postCheck
''
else checkPhase;
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 ];
};
script = fishFile "/bin/${name}" text;
completions_file = fishFile "/share/fish/vendor_completions.d/${name}.fish" completions;
in
final.symlinkJoin {
inherit name;