-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running Nix with sudo
on darwin now complains that /Users/lily
isn't owned by me
#6834
Comments
Actually I suppose I dunno. Maybe I'm just grumpy, but I don't relish trying to move everything over to At the very least the warning could be improved, because it's telling me that my home directory isn't owned by me, which is wrong. As long as we have the warning, it should say the actual username instead of "you" (e.g. "is not owned by root"). And it would be nice to tell me the actual path it's falling back to instead of saying it's falling back to whatever's in the 'passwd' file. |
The home directory is used for a buch of things (as you mention the config file, the default profile and channels, but also some cache and the
That looks like it's making things more complex than it should. And also error-prone since there's a few reasons why Nix might want to write under |
Found this issue after getting the warning during |
hitting this in my tests, where i must normalize the home path with nix 2.11.0
at least there should be an escape hatch like workaround:
|
Describe the bug
In Nix 2.10.0, Nix now checks if
$HOME
is owned by the current user and falls back to reading thepasswd
entry if not (see #6676). On macOS, by defaultsudo
will not reset$HOME
. This means that running Nix withsudo
on macOS now prints a warning even if the command shouldn't care about the home directory1. This is very annoying.I'm not even sure the warning is all that useful. It sounds like it was primarily motivated by
nix-channel
, although off the top of my head it obvious affectsnix-env
as well. Resetting$HOME
fornix-channel
is obviously correct, and probably doesn't need a warning, but it's less obvious to me that resetting$HOME
makes sense for other commands. For example, if I have a user channel set and I want to install it to the root profile,sudo nix-env -i
will reset$HOME
and therefore not see my user channel. I can see how someone might think this is correct, but more generally,sudo
is a way to add permissions to an action2, so it feels wrong that it would also change the way things are evaluated. With this context, I claimsudo nix-channel
is correct to reset$HOME
because the use ofsudo
is to opt in to changing the root channels as there is otherwise no permission issue that necessitates thesudo
.The concrete motivation for filing this issue now is that
nix-darwin
now triggers this warning ondarwin-rebuild switch
, with the linesudo nix-env -p "$profile" --set "$systemConfig"
. This command shouldn't care about$HOME
at all, but it now triggers a warning.Steps To Reproduce
sudo nix-instantiate --eval -E 1
Expected behavior
It should evaluate without printing any warnings.
nix-env --version
outputnix-env (Nix) 2.10.3
Additional context
I'm not all that familiar with the circumstances in which
$HOME
would be set to a folder not owned by the current user outside of the use ofsudo
, so perhaps there is some situation where warning about this is useful (for example if I mangle the env var it might be nice to know it's being ignored, but that seems fairly niche). If there is a good argument for having this in the general case then Nix could detect the use ofsudo
specifically by looking for the env vars it sets (such as$SUDO_USER
). But I really think it would be more useful to only check if$HOME
is owned by the current user fornix-channel
, and otherwise only check if$HOME
is readable by the current user. That way if I do something likesudo -u otheruser
then it would still reset$HOME
for me since that user can't read my home folder.Footnotes
In theory a
nix.conf
in the user's config dir could matter, but I'm not even sure it would be incorrect to read that from$HOME
regardless of ownership. In particular, if I run a nix command withsudo
, it would not be unreasonable to expect the same config to apply as running without. ↩This is probably why macOS preserves
$HOME
by default when invokingsudo
. ↩The text was updated successfully, but these errors were encountered: