Linux multi-user install, nix command not found

I have working nix installations on MacOS, Arch Linux, and NixOS on a Raspberry Pi 3.

Today I wanted to install the package manager on a Raspberry Pi running Raspbian and thought it would be no sweat.

Following the instructions at for a multi-user install:

sh <(curl -L --daemon

I allowed it to use sudo when requested.

It looks like the installation worked, so I reboot, but I’m getting -bash: nix: command not found.

Digging around, I find that nix is installed for root and works fine:

$ sudo -i nix-shell -p nix-info --run "nix-info -m"
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
/nix/store/addlxsbl7ycab3zbkb0wq6a74487pncm-bash-5.1-p16/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
 - system: `"aarch64-linux"`
 - host os: `Linux 5.10.103-v8+, Debian GNU/Linux, 11 (bullseye), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/root/.nix-defexpr/channels/nixpkgs`

but not installed under my user:

$ sudo ls -l /root/.nix-profile
lrwxrwxrwx 1 root root 29 Oct  7 13:46 /root/.nix-profile -> /nix/var/nix/profiles/default
$ ~/.nix-profile
-bash: /home/n8henrie/.nix-profile: No such file or directory

Did I do something wrong? If memory serves, on Arch it went ahead and installed to my regular user.

1 Like

I’m not super familiar with the OOB experience on the various linuxes, but this sounds like your user’s shell init files might be either terminating early (before Nix’s shell hook can run) or may be hard-setting the PATH, overwriting the PATH-prefix it tries to add.

If looking over the init files doesn’t turn up anything obvious, I think you can run bash -x to make print the statements as it runs–it should be easy enough to tell from this if it’s terminating early or hard setting the PATH.

You’re right, once again it’s something in my bashrc overriding things:

$ bash --norc --noprofile -c 'source /etc/bashrc; which nix'

Funny thing is I’m finally trying to figure out home-manager with this (attempted) installation.

After a bit of investigation, it looks like the issue is:

# Load profiles from /etc/profile, which will load those found in /etc/profile.d
if is_interactive_shell; then
  [[ -r /etc/profile ]] && source /etc/profile

where on Raspbian, /etc/profile leads with:

if [ "`id -u`" -eq 0 ]; then
export PATH

This is in my ~/.bashrc after putting nix on PATH, which is erasing it. Changing the order of things seems resolve the problem. Thank you!

1 Like