Nix shell --command interprets quoted argument as filename

Old behaviour

The old nix-shell allowed quoting compound commands like this:

$ nix-shell -p cowsay lolcat --command 'cowsay hello | lolcat'
 _______ 
< hello >
 ------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

That is, complex commands could be enclosed in quotes and would be parsed and interpreted by the shell.

New problem

The new nix shell’s --command option treats quoted values as filenames, leading to errors such as this:

$ nix shell nixpkgs#{cowsay,lolcat} --command 'cowsay hello | lolcat'
error: --- SysError -------------------------------------------------- nix
unable to execute 'cowsay hello | lolcat': No such file or directory

Leaving out the quotes leads to errors such as this:

$ nix shell nixpkgs#{cowsay,lolcat} --command cowsay hello | lolcat
The program ‘lolcat’ is currently not installed. You can install it by typing:
  nix-env -iA nixos.lolcat

Bug or feature?

As a workaround you can probably nix shell ... -c bash -c 'complex command | here'.

1 Like

Yes, this workaround succeeds.

However

  1. I assume that the current behaviour is a bug. Or am I missing some deeper reason for which this behaviour is desirable?
  2. If it is indeed a bug, would opening an issue/PR be helpful, or merely unwelcome noise, at this stage in the development process. With 1291 open issues and 195 open PRs, I’d rather not add any more if they might merely waste the developers’ time.
1 Like