Open timblaktu opened 6 months ago
Thanks for the report. Does sudo -E
work as an alternative to sudo -i
without changing the cwd?
I can also reproduce this on Linux/aarch64
I have just had this issue on uBlue Aurora (Fedoa Silverblue based, rpm-ostree distro).
sudo -E nix-env --help
Does not work for me. The binary is not in $PATH
I dont understand the discrepancy here between these three commands:
sudo -E echo $PATH /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/var/home/matthew/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/var/home/matthew/.local/bin:/var/home/matthew/bin:/var/home/matthew/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
sudo -E which nix-env which: no nix-env in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin)
Used "nix-foo" in my user profile just so it would fail and return the paths for comparison.
which nix-foo /usr/bin/which: no nix-foo in (/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/var/home/matthew/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/var/home/matthew/.local/bin:/var/home/matthew/bin:/var/home/matthew/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin)
As an aside, what can be done to manually fix this while waiting for the bug to be fixed? I don't understand the difference between "sudo
On Ubuntu/WSL, I installed latest nix (2.21.2) with
sudo nix-installer install linux
, and can access it as normal user at/nix/var/nix/profiles/default/bin/nix
:and as root user at
/root/.nix-profile/bin/nix
:However, normal user utterances of
sudo nix
don't findnix
binary:We can make this error go away with a root login shell (sudo -i/--login):
..but being forced to use a login shell is undesirable in cases where I want to run nix escalated with sudo but do NOT want the environment to change.
For example, I'm using
sudo nix run
to execute thetarballBuilder
defined in a modified, local working copy of the NixOS-WSL project, which requires root privileges. Passing the flakeref argument tosudo -i nix run
requires an absolute path, even when run from the flake root directory, because cwd is changed bysudo -i
.This is cumbersome when you consider that instructions for users of nix projects like NixOS-WSL now depend on the way the user installed nix. In my case, none of the NixOS-WSL build examples worked for me because I happen to have installed nix with
nix-installer
.So, the summary of this issue is that:
nix
binaries available for normal and root users in a consistent way that works with basicsudo nix
and thatsudo -i
is not acceptable because changing cwd is unacceptable, because that forces confusing dependencies on the usage of nix projects.Below are my environment details. I look forward to your feedback. Thanks for your time and contributions for this amazing project!
Environment
Ubuntu 22.04.3 LTS on WSL version: 2.1.5.0 Kernel version: 5.15.146.1-2 WSLg version: 1.0.60 MSRDC version: 1.2.5105 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22631.3593