While trying to follow the nix.dev tutorial, I found that the nix-shell -p cowsay lolcat command didn’t work.

I am running Arch Linux and had installed Nix by running sudo pacman -S nix.

The first problem was that I had not completed the Nix installation, resulting in Nix being unable to find nixpkgs. This wasn’t mentioned in the tutorial and it appears to be a quirk of how nix is packaged for Arch Linux. This was fixed by adding a channel:

nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --update

Next, I found that after running nix-shell -p cowsay lolcat, that neither cowsay nor lolcat could be found by my fish shell. This is apparently because the way I start fish causes the PATH variable, which Nix modifies to be clobbered. I apparently had this line at the end of my .bashrc file:

exec fish

I’m not entirely sure how this clobbers the PATH as the exec documentation is pretty sparse, with man exec stating:

EXEC(1)                              fish-shell                              EXEC(1)

NAME
       exec - execute command in current process

SYNOPSIS
       exec COMMAND

DESCRIPTION
       exec  replaces  the currently running shell with a new command. On successful
       completion, exec never returns. exec cannot be used inside a pipeline.

       The --help or -h option displays help about using this command.

EXAMPLE
       exec emacs starts up the emacs text editor, and exits fish. When emacs exits,
       the session will terminate.

COPYRIGHT
       2024, fish-shell developers

3.7                                 Apr 13, 2024                             EXEC(1)

I gave up on trying to figure out how to get exec to stop clobbering the PATH variable. So, I decided to remove the exec fish line and configured my terminal emulator alacritty to launch fish on start instead.