Open LnL7 opened 7 years ago
cc @grahamc given that this changed with the multi-user setup
cc @jmitchell
Doing some debugging, so far things are looking okay here:
nixos$ nix-channel --add https://nixos.org/channels/nixos-17.03 fizzbuzz
nixos$ nix-channel --update
downloading Nix expressions from ‘https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1775.56da88a298/nixexprs.tar.xz’...
downloading ‘https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1775.56da88a298/nixexprs.tar.xz’... [6975/9252 KiB, 6959.8 KiB/s]
unpacking channels...
nixos$ ls /nix/var/nix/profiles/per-user/grahamc/channels/
binary-caches fizzbuzz manifest.nix
macos$ nix-channel --add https://nixos.org/channels/nixos-17.03 fizzbuzz
macos$ nix-channel --update
downloading Nix expressions from ‘https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1775.56da88a298/nixexprs.tar.xz’...
downloading ‘https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1775.56da88a298/nixexprs.tar.xz’... [7295/9252 KiB, 7277.6 KiB/s]
unpacking channels...
macos$ ls /nix/var/nix/profiles/per-user/graham/channels/
binary-caches fizzbuzz manifest.nix
I wonder if sudo nix-channel --add http://nixos.org/channels/foo
(ie: without the second arg) is causing problems there.
I definitely have the problem:
nixos$ nix-channel --list
fizzbuzz https://nixos.org/channels/nixos-17.03
nixos$ sudo nix-channel --list
nixos https://nixos.org/channels/nixos-17.03
nixos$ sudo -i nix-channel --list
nixos https://nixos.org/channels/nixos-17.03
macos$ nix-channel --list
fizzbuzz https://nixos.org/channels/nixos-17.03
macos$ sudo nix-channel --list
fizzbuzz https://nixos.org/channels/nixos-17.03
macos$ sudo -i nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
More info:
nixos$ sudo env | grep HOME=
HOME=/root
plus
macos$ sudo env | grep HOME=
HOME=/Users/graham
plus
https://github.com/NixOS/nix/blob/1.11-maintenance/scripts/nix-channel.in#L25-L26
= nix-channel is looking at user's channels w/ sudo on macos, and root's channels w/ sudo on nixos.
This is because of this macOS default:
macos$ sudo cat /etc/sudoers | grep -i home
Defaults env_keep += "HOME MAIL"
So where go from here?
It seems like a workaround would be to just edit the sudoers file when a multiuser installation is done. I'm not sure this would be a good idea though since this change has deeper implications than most of the other changes the multiuser install seems to make.
Would modifying the way Nix gets the home directory be better?
I'm interested in seeing this fixed. While this is a minor irritation it poses a pretty big barrier for people trying to use Nix on MacOS who are just starting out.
Maybe something like: if HOME
is set and exists but is owned by a different uid than the current user, then ignore it and use getpwuid
instead.
I would prefer not to depend on getpwuid
but changing sudoers sounds like a terrible idea so it's probably the best solution.
I removed HOME
from my sudoer file as a workaround. Took me quite a bit of time hunting around as to why nix-channel --list
shows nothing. At the very least with a fresh install on macos some warning would be useful to illustrate how to properly access the current nixos status given the multi user setup. Basically the confusion for me (as someone who just installed nix):
I discovered this as well:
blast$ nix-channel --list
blast$ sudo nix-channel --list
Password:
though sudo
has a -H
flag that properly sets the HOME
envvar, intended for this purpose:
blast$ sudo -H nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
blast$ sudo -H nix-channel --update
unpacking channels...
created 2 symlinks in user environment
this was definitely confusing initially, as it seemed as though I could install packages without being subscribed to any channels at all.
I marked this as stale due to inactivity. → More info
well, until the questions around whether nix-channels
should be removed/repurposed are resolved, I think this should probably not be closed because of "stale"
I marked this as stale due to inactivity. → More info
Not stale.
Also occurs on NixOS with sudo -E
(obviously).
I marked this as stale due to inactivity. → More info
This issue can be closed. I recently added a PR (since landed) which fixes this on macos.
On macOS it seems like nix-channel doesn't behave correctly when just using sudo. I'm not sure if this also happens on other platforms, but it works fine on nixos.
and even more confusing