diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-09-04 19:32:39 -0500 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2018-09-04 19:32:39 -0500 |
commit | 74f6d8767de13980b0e83a249633ee4a7e6fc547 (patch) | |
tree | cd8947808b49c9f6d3140ffaaa21b3e2798dbd05 /src/nix-channel | |
parent | 5e0a7206f59df575582f42415fc3df59b0d640cb (diff) |
Get effective user in Nix commands
‘geteuid’ gives us the user that the command is being run as,
including in setuid modes. By using geteuid to determind id, we can
avoid the ‘sudo -i’ hack when upgrading Nix. So now, upgrading Nix on
macOS is as simple as:
$ sudo nix-channel --update
$ sudo nix-env -u
$ sudo launchctl stop org.nixos.nix-daemon
$ sudo launchctl start org.nixos.nix-daemon
or
$ sudo systemctl restart nix-daemon
Diffstat (limited to 'src/nix-channel')
-rwxr-xr-x | src/nix-channel/nix-channel.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc index 55ebda438..2083d3df5 100755 --- a/src/nix-channel/nix-channel.cc +++ b/src/nix-channel/nix-channel.cc @@ -169,7 +169,7 @@ int main(int argc, char ** argv) // Figure out the name of the channels profile. ; - auto pw = getpwuid(getuid()); + auto pw = getpwuid(geteuid()); std::string name = pw ? pw->pw_name : getEnv("USER", ""); if (name.empty()) throw Error("cannot figure out user name"); |