cachix / devenv

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

sed: command not found #364

Closed DamienCassou closed 1 month ago

DamienCassou commented 1 year ago

Describe the bug

I see a lot of "sed: command not found" when starting devenv shell:

$ devenv shell
Building shell ...
Entering shell ...

sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
sed: command not found
hello
jq-1.6

To Reproduce

https://gist.github.com/DamienCassou/4d355b3648369586b7226554f46a9891

Version

0.5.1

domenkozar commented 1 year ago

What OS are you running it on? I can't reproduce it on NixOS.

DamienCassou commented 1 year ago

This is Fedora 37.

By the way: thank you for joining FOSDEM and doing this great presentation! And thank you very much for all your work around Nix.

domenkozar commented 1 year ago

Could you add set -xe into enterShell so that we see where it's coming from?

DamienCassou commented 1 year ago

It feels like the errors happens before enterShell is executed. Here is part of my devenv.nix file:

{
  enterShell = ''
    echo FOOOOOOOOOOOOOOOOOOOOOOOOO
    set -xe
    hello
    git --version
  '';
}

And here is the result:

$ devenv shell
Building shell ...
Entering shell ...

sed: command not found
...
sed: command not found
FOOOOOOOOOOOOOOOOOOOOOOOOO
++++ history 1
++++ sed 's/^[ ]*[0-9]*[ ]*//g'
+++ echo -ne '\033]2;\007'
++ hello
hello from devenv
domenkozar commented 1 year ago

If you add packages = [ pkgs.gnused ]; does it work?

DamienCassou commented 1 year ago

it doesn't change anything:

$ grep packages devenv.nix 
  # https://devenv.sh/packages/
  packages = [ pkgs.git pkgs.gnused ];

$ devenv shell
Building shell ...
Entering shell ...

sed: command not found
sed: command not found
sandydoo commented 1 year ago

@DamienCassou, does which sed return /usr/bin/sed (both before and after devenv shell)? Could you also show us your PATH (echo $PATH)?

@domenkozar, I removed sed from my Ubuntu VM and this error doesn't show up.

DamienCassou commented 1 year ago

It seems that devenv is adding several copies of /home/cassou/.nix-profile/bin to my PATH beyond the /nix/store/...devenv-profile/bin directory. Other than that, I don't see anything strange.

Please note that the gnused I use is in ~/.nix-profile/bin because I'm using home manager. There is also Fedora's gnused in /usr/bin.


$ echo $PATH
/home/cassou/.nix-profile/bin:/home/cassou/.nix-profile/bin:/home/cassou/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/cassou/.local/bin:/home/cassou/Documents/projects/ledger/hledger/bin:/home/cassou/.dotnet:/home/cassou/.dotnet/tools

$ which sed
/home/cassou/.nix-profile/bin/sed

$ ls -l /usr/bin/sed
-rwxr-xr-x 1 root root 116824 Jul 23  2022 /usr/bin/sed

$ devenv shell
Building shell ...
Entering shell ...

sed: command not found
…
sed: command not found
…
devenv$ echo $PATH
/nix/store/4psc8l1y0xg2chk7sg8mz7scygpfw8n2-devenv-profile/bin:/home/cassou/.nix-profile/bin:/home/cassou/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/cassou/.nix-profile/bin:/home/cassou/.nix-profile/bin:/home/cassou/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/cassou/.local/bin:/home/cassou/Documents/projects/ledger/hledger/bin:/home/cassou/.dotnet:/home/cassou/.dotnet/tools

devenv$ which sed
/home/cassou/.nix-profile/bin/sed
sandydoo commented 1 year ago

@DamienCassou, and is there anything special about your shell? Perhaps a custom prompt?

DamienCassou commented 1 year ago

@sandydoo nothing in the prompt, but I indeed found a reference to sed in my .bashrc:

# Show the executing command in the terminal's title
# https://stackoverflow.com/questions/5076127/bash-update-terminal-title-by-running-a-second-command
trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG

Because my .bashrc is generated by home manager, I changed the sed reference to ${pkgs.gnused}/bin/sed. This seems to work great now!

What is the reason for sed not being found?

Feel free to close the issue if there is nothing to be done in devenv.

Thank you very much for your help @sandydoo.

sandydoo commented 1 year ago

PATH is set to /path-not-set to prevent shells from initialising it to their built-in default value. https://github.com/NixOS/nix/blob/e4a2a5c074f8faf947a8864ca2acea85a8fc6ab7/doc/manual/src/language/derivations.md https://github.com/NixOS/nix/blob/c1921514d4f70921a30aa5414bb379c1d5710d1c/src/libstore/build/local-derivation-goal.cc#L1101

Nix is setting the PATH to nowhere for a while when we're building the shell, which results in sed not getting resolved. It's the built-in derivation function: https://github.com/cachix/devenv/blob/eac5eb12eb42765f5f252972dc876d1f96b03dfe/src/modules/mkNakedShell.nix#L114

We can open a dedicated issue if it keeps cropping up.

domenkozar commented 1 year ago

I'd like to keep this open as part of #240 to address it, we shouldn't break stuff like this :)

domenkozar commented 1 month ago

We got rid of the naked shell, closing.