Skip to content

Commit

Permalink
Don't use whoami
Browse files Browse the repository at this point in the history
`whoami` doesn't work when auto-uid-allocation is enabled and
sandboxing is disabled, since then the build UID doesn't have a
matching entry in /etc/passwd.
  • Loading branch information
edolstra committed Jan 16, 2024
1 parent b746191 commit 1741f4d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/nix/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ static bool matchUser(std::optional<uid_t> uid, std::optional<gid_t> gid, const

if (gid) {
auto gr = getgrgid(gid.value());
//std::string group = gr ? gr->gr_name : std::to_string(peer.gid.value());

/* Don't allow connecting as the build users group. */
if (gr && gr->gr_name == settings.buildUsersGroup)
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/bash-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ source common.sh

sed -e "s|@localstatedir@|$TEST_ROOT/profile-var|g" -e "s|@coreutils@|$coreutils|g" < ../../scripts/nix-profile.sh.in > $TEST_ROOT/nix-profile.sh

user=$(whoami)
rm -rf $TEST_HOME $TEST_ROOT/profile-var
mkdir -p $TEST_HOME
USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh; set"
USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh" # test idempotency
USER=foobar $SHELL -e -c ". $TEST_ROOT/nix-profile.sh; set"
USER=foobar $SHELL -e -c ". $TEST_ROOT/nix-profile.sh" # test idempotency
2 changes: 1 addition & 1 deletion tests/functional/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ substituters =
flake-registry = $TEST_ROOT/registry.json
show-trace = true
include nix.conf.extra
trusted-users = $(whoami)
trusted-users = $(id -u)
EOF

cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
Expand Down

0 comments on commit 1741f4d

Please sign in to comment.