-
-
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
Set HOME
var to root
's home when running nix-store
as root
#6980
Conversation
A [recent-ish change](NixOS#6676) logs a warning when a potentially counterintuitive situation happens. This now causes the multi-user installer to [emit a warning](NixOS/nixpkgs#189043) when it's doing the "seed the Nix database" step via a low-level `nix-store --load-db` invocation. `nix-store` functionality implementations don't actually use profiles or channels or homedir as far as i can tell. So why are we hitting this code at all? Well, the current command approach for functionality here builds a [fat `nix` binary](https://github.com/NixOS/nix/blob/master/src/nix/local.mk#L23-L26) which has _all_ the functionality of previous individual binaries (nix-env, nix-store, etc) bundled in, then [uses the invocation name](https://github.com/NixOS/nix/blob/master/src/nix/main.cc#L274-L277) to select the set of commands to expose. `nix` itself has this behavior, even when just trying to parse the (sub)command and arguments: ``` dave @ davembp2 $ nix error: no subcommand specified Try 'nix --help' for more information. dave @ davembp2 $ sudo nix warning: $HOME ('/Users/dave') is not owned by you, falling back to the one defined in the 'passwd' file error: no subcommand specified Try 'nix --help' for more information. dave @ davembp2 $ HOME=~root sudo nix error: no subcommand specified Try 'nix --help' for more information. ``` This behavior can also be seen pretty easily with an arbitrary `nix-store` invocation: ``` dave @ davembp2 $ nix-store --realize dave @ davembp2 $ sudo nix-store --realize # what installer is doing now warning: $HOME ('/Users/dave') is not owned by you, falling back to the one defined in the 'passwd' file dave @ davembp2 $ sudo HOME=~root nix-store --realize # what this PR effectively does dave @ davembp2 $ ```
Fixes NixOS/nixpkgs#189043 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just wondering whether it would make sense to have _sudo
run sudo -H
to generalize this. But that can be done independently anyways)
Set `HOME` var to `root`'s home when running `nix-store` as `root`
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-install-script-not-allowed-to-set-env-variables/26104/2 |
Agreed |
@virusdave Check out |
A recent-ish change logs a warning when a potentially counterintuitive situation happens.
This now causes the multi-user installer to emit a warning when it's doing
the "seed the Nix database" step via a low-level
nix-store --load-db
invocation.nix-store
functionality implementations don't actually use profiles or channels or homedir as far as i can tell. So why are wehitting this code at all?
Well, the current command approach for functionality here builds a fat
nix
binary which has all the functionality ofprevious individual binaries (nix-env, nix-store, etc) bundled in, then uses the invocation name to select the
set of commands to expose.
nix
itself has this behavior, even when just trying to parse the (sub)command and arguments:This behavior can also be seen pretty easily with an arbitrary
nix-store
invocation: