Skip to content
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

use existing GID in sequoia migration script #11433

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scripts/sequoia-nixbld-user-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ any_nixbld(){
dscl . list /Users UniqueID | grep -E '\b_nixbld' >/dev/null
}

dsclattr() {
dscl . -read "$1" | awk "/$2/ { print \$2 }"
}

re_create_nixbld_user(){
local name uid

name="$1"
uid="$2"
gid="$3"

sudo /usr/bin/dscl . -create "/Users/$name" "UniqueID" "$uid"
sudo /usr/bin/dscl . -create "/Users/$name" "IsHidden" "1"
sudo /usr/bin/dscl . -create "/Users/$name" "NFSHomeDirectory" "/var/empty"
sudo /usr/bin/dscl . -create "/Users/$name" "RealName" "Nix build user $name"
sudo /usr/bin/dscl . -create "/Users/$name" "UserShell" "/sbin/nologin"
sudo /usr/bin/dscl . -create "/Users/$name" "PrimaryGroupID" "30001"
sudo /usr/bin/dscl . -create "/Users/$name" "PrimaryGroupID" "$gid"
}

hit_id_cap(){
Expand Down Expand Up @@ -68,11 +73,12 @@ temporarily_move_existing_nixbld_uids(){
}

change_nixbld_uids(){
local name next_id user_n
local existing_gid name next_id user_n

((next_id=NEW_NIX_FIRST_BUILD_UID))
((user_n=1))
name="$(nix_user_n "$user_n")"
existing_gid="$(dsclattr "/Groups/nixbld" "PrimaryGroupID")"

# we know that we have *some* nixbld users, but macOS may have
# already clobbered the first few users if this system has been
Expand All @@ -91,7 +97,7 @@ change_nixbld_uids(){
fi
done

re_create_nixbld_user "$name" "$next_id"
re_create_nixbld_user "$name" "$next_id" "$existing_gid"
echo " $name was missing; created with uid: $next_id"

((user_n++))
Expand Down
Loading