Skip to content

Commit

Permalink
tasks: make sure status fails correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Oct 11, 2024
1 parent 151a82a commit c1117e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/modules/tasks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ let
taskType = types.submodule
({ name, config, ... }:
let
mkCommand = command:
mkCommand = command: isStatus:
if builtins.isNull command
then null
else
pkgs.writeScript name ''
#!${pkgs.lib.getBin config.package}/bin/${config.binary}
${lib.optionalString (!isStatus) "set -e"}
${command}
${lib.optionalString (config.exports != []) "${devenv}/bin/devenv-tasks export ${lib.concatStringsSep " " config.exports}"}
${lib.optionalString (config.exports != [] && !isStatus) "${devenv}/bin/devenv-tasks export ${lib.concatStringsSep " " config.exports}"}
'';
in
{
Expand All @@ -35,7 +36,7 @@ let
command = lib.mkOption {
type = types.nullOr types.package;
internal = true;
default = mkCommand config.exec;
default = mkCommand config.exec false;
description = "Path to the script to run.";
};
status = lib.mkOption {
Expand All @@ -46,7 +47,7 @@ let
statusCommand = lib.mkOption {
type = types.nullOr types.package;
internal = true;
default = mkCommand config.status;
default = mkCommand config.status true;
description = "Path to the script to run.";
};
config = lib.mkOption {
Expand Down
9 changes: 9 additions & 0 deletions tests/tasks/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"devenv:enterShell".after = [ "myapp:shell" ];
"myapp:test".exec = "touch test";
"devenv:enterTest".after = [ "myapp:test" ];
"example:statusIgnored" = {
before = [ "devenv:enterTest" ];
exec = "touch ./should-not-exist";
status = "rm should-not-exist && ls";
};
};

enterTest = ''
Expand All @@ -17,6 +22,10 @@
if [ ! -f test ]; then
echo "test does not exist"
exit 1
fi
if [ -f ./should-not-exist ]; then
echo should-not-exist exists
exit 1
fi
'';
}

0 comments on commit c1117e0

Please sign in to comment.