nix-configs/modules/utils.nix

57 lines
1.3 KiB
Nix
Raw Permalink Normal View History

{
pkgs,
lib,
}: rec {
2023-10-28 20:25:06 +00:00
# taken from https://github.com/NixOS/nixpkgs/blob/3650808d85dccbfa3be3d785dfd3ce33a757bd2c/pkgs/build-support/trivial-builders/default.nix#L335
writeNuShellApplication = {
name,
text,
runtimeInputs ? [],
meta ? {},
checkPhase ? null,
}:
2023-10-28 20:25:06 +00:00
writeTextFile {
inherit name meta;
executable = true;
destination = "/bin/${name}";
allowSubstitutes = true;
preferLocalBuild = false;
text =
''
#!${pkgs.nushell}
''
+ lib.optionalString (runtimeInputs != []) ''
2023-10-28 20:25:06 +00:00
$env.PATH = ($env.PATH | split row (char esep) | prepend '${lib.makeBinPath runtimeInputs}');
''
+ ''
2023-10-28 20:25:06 +00:00
${text}
'';
2023-10-28 20:25:06 +00:00
checkPhase =
# GHC (=> shellcheck) isn't supported on some platforms (such as risc-v)
# but we still want to use writeShellApplication on those platforms
if checkPhase == null
then ''
2023-10-28 20:25:06 +00:00
runHook preCheck
nu -c "nu-check -d $target"
2023-10-28 20:25:06 +00:00
runHook postCheck
''
else checkPhase;
};
packageNushellApplication = {
name,
path,
runtimeInputs ? [],
meta ? {},
checkPhase ? null,
}:
2023-10-28 20:25:06 +00:00
writeNuShellApplication {
inherit name runtimeInputs meta checkPhase;
text = builtins.readFile path;
};
}