devenv icon indicating copy to clipboard operation
devenv copied to clipboard

Cannot run python code (or anything non-shell?) in a `task`

Open flaw opened this issue 1 year ago • 1 comments

It seems it's not possible to run non-shell scripts in a tasks: entry.

Given a config like

  tasks."python:hello" = {
    exec = ''print("Hello, world!")'';
    binary = "python3";
    package = config.languages.python.package;
  };

when I try to run it, I see:

--- python:hello failed with error: Task exited with status: exit status: 1
--- python:hello stdout:
--- python:hello stderr:
0000.00: Traceback (most recent call last):
0000.00:   File "/nix/store/54s3d671wvdnih712v7qszixim53n568-python-hello", line 2, in <module>
0000.00:     set -e
0000.00: NameError: name 'e' is not defined

Problem seems to be that the generated script contains a rogue set -e:

❯ cat /nix/store/54s3d671wvdnih712v7qszixim53n568-python-hello
#!/nix/store/ibjjy3ab86hiib290mcrmmzghqqr4hg2-python3-3.8.13/bin/python3
set -e
print("Hello, world!")

flaw avatar Dec 12 '24 11:12 flaw

Hello, I encountered the same issue.

I took a look at the source code of devenv, and I suspect that this part might be the cause:

https://github.com/cachix/devenv/blob/9e4003b2702483bd962dac3d4ff43e8dafb93cda/src/modules/tasks.nix#L24

Since I don’t have much experience with Nix, I’m not sure if I can fix it myself, but I plan to continue investigating the cause. If I find anything else, I’ll post an update here.

Comamoca avatar Feb 25 '25 15:02 Comamoca