cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.44k stars 331 forks source link

Failing process exits process-compose immediately #1037

Open tennox opened 7 months ago

tennox commented 7 months ago

If I run devenv up frontend but have a command in the exec that fails, e.g.:

processes = {
    frontend.exec = "cd page && pnpm dev --port 3000";
};

If I run this while in the subdirectory page/:

thenonameguy commented 7 months ago

the command will fail because there is no such directory (that's an issue of it's own - shouldn't processed run with devenv root as PWD?)

You can set CWD explicitly for processes, so you don't need to cd within exec: https://github.com/schemamap/schemamap/blob/main/devenv.nix#L88-L89

process-compose will exit immediately, making it impossible to see the error message

This can be solved by setting a restart strategy, combined with the above:

processes = {
    frontend = { 
      exec = "pnpm dev --port 3000";
      process-compose = {
          working_dir = "page";
          availability.restart = "always";
      };
    };
};
tennox commented 7 months ago

Thx, this kinda works as a workaround:

frontend = {
    exec = "echo fail; false";
    process-compose = {
          availability.restart = "always";
    };
};

But I feel the default of a silent exit in case of error is a bit awkward - that's why I posted this issue :thinking:

And for the working dir, while this works when I'm in the root directory:

frontend = {
      exec = "pnpm run dev";
      process-compose = {
            working_dir = "frontend";
      };
};

When I'm in the subdirectory, the command fails:

❯ devenv up page
path '/home/manu/dev/levin-shop/frontend' does not contain a 'flake.nix', searching up

And in /tmp/process-compose-manu.log:

ERR Failed to run command exec /nix/store/r9jd1jvd9q4qxy7ilricw2g2kfm5wqlh-frontend for process frontend [0m36merror="stat frontend: no such file or directory"
ori-nonni commented 4 months ago

Set your working directory in the root devenv.nix and other options in sub devenv.nix. The root nix will merge the options

./devenv.nix processes = { frontend.process-compose.working_dir = "./frontend"; };

./frontend/devenv.nix processes = { frontend = { exec = "pnpm dev --port 3000"; process-compose = { availability.restart = "always"; }; }; };