Skip to content

Commit 49322d1

Browse files
committed
add script to migrate macOS 15 Sequoia nixbld UIDs
While we don't have any easy way to forcibly notify everyone about the impending breakage (or forcibly migrate the users on their system), this script enables those who do hear about the problem to migrate their systems before they take the macOS update. It should also enable people who only discover it after the update when a build fails to ~fix their installs without a full reinstall.
1 parent caabdb0 commit 49322d1

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

scripts/sequoia-nixbld-user-migration.sh

100644100755
Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
((NEW_NIX_FIRST_BUILD_UID=331))
44

5+
nix_user_n() {
6+
printf "_nixbld%d" "$1"
7+
}
8+
59
id_available(){
610
dscl . list /Users UniqueID | grep -E '\b'"$1"'\b' >/dev/null
711
}
812

913
change_nixbld_names_and_ids(){
10-
local name uid next_id
14+
local name next_id user_n
15+
1116
((next_id=NEW_NIX_FIRST_BUILD_UID))
17+
((user_n=1))
18+
name="$(nix_user_n "$user_n")"
19+
1220
echo "Attempting to migrate _nixbld users."
1321
echo "Each _nixbld# user should have its UID moved to $next_id+"
14-
while read -r name uid; do
15-
echo " Checking $name (uid: $uid)"
22+
23+
# start at _nixbld1 and increment until _nixbld<n> doesn't exist
24+
while dscl . read "/Users/$name" &>/dev/null; do
1625
# iterate for a clean ID
1726
while id_available "$next_id"; do
1827
((next_id++))
@@ -25,12 +34,18 @@ change_nixbld_names_and_ids(){
2534
fi
2635
done
2736

28-
# first 2 are cleanup, it's OK if they aren't here
29-
sudo dscl . delete "/Users/$name" dsAttrTypeNative:_writers_passwd &>/dev/null || true
30-
sudo dscl . change "/Users/$name" NFSHomeDirectory "/private/var/empty 1" "/var/empty" &>/dev/null || true
31-
sudo dscl . change "/Users/$name" UniqueID "$uid" "$next_id"
37+
sudo dscl . -create "/Users/$name" UniqueID "$next_id"
3238
echo " $name migrated to uid: $next_id"
33-
done < <(dscl . list /Users UniqueID | grep _nixbld | sort -n -k2)
39+
((user_n++))
40+
done
41+
42+
if ((user_n == 1)); then
43+
echo "Didn't find _nixbld1. Perhaps you have single-user Nix?"
44+
exit 1
45+
else
46+
echo "Migrated $((user_n - 1)) users. If you want to double-check, try:"
47+
echo "dscl . list /Users UniqueID | grep _nixbld | sort -n -k2"
48+
fi
3449
}
3550

3651
change_nixbld_names_and_ids

0 commit comments

Comments
 (0)