Skip to content

Commit fa4bbe5

Browse files
committed
installer: allow overriding of NIX_FIRST_BUILD_ID on darwin
because there are often already users in the 300 range and it's painful to work around. revives #6466
1 parent 5d5b25f commit fa4bbe5

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

scripts/install-darwin-multi-user.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
set -eu
44
set -o pipefail
55

6+
# System specific settings
7+
export NIX_FIRST_BUILD_UID="${NIX_FIRST_BUILD_UID:-301}"
8+
export NIX_BUILD_USER_NAME_TEMPLATE="_nixbld%d"
9+
610
readonly NIX_DAEMON_DEST=/Library/LaunchDaemons/org.nixos.nix-daemon.plist
711
# create by default; set 0 to DIY, use a symlink, etc.
812
readonly NIX_VOLUME_CREATE=${NIX_VOLUME_CREATE:-1} # now default
9-
NIX_FIRST_BUILD_UID="301"
10-
NIX_BUILD_USER_NAME_TEMPLATE="_nixbld%d"
1113

1214
# caution: may update times on / if not run as normal non-root user
1315
read_only_root() {

scripts/install-multi-user.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ readonly RED='\033[31m'
2525
readonly NIX_USER_COUNT=${NIX_USER_COUNT:-32}
2626
readonly NIX_BUILD_GROUP_ID="${NIX_BUILD_GROUP_ID:-30000}"
2727
readonly NIX_BUILD_GROUP_NAME="nixbld"
28-
# darwin installer needs to override these
29-
NIX_FIRST_BUILD_UID="${NIX_FIRST_BUILD_UID:-30001}"
30-
NIX_BUILD_USER_NAME_TEMPLATE="nixbld%d"
28+
# each system specific installer must set these:
29+
# NIX_FIRST_BUILD_UID
30+
# NIX_BUILD_USER_NAME_TEMPLATE
3131
# Please don't change this. We don't support it, because the
3232
# default shell profile that comes with Nix doesn't support it.
3333
readonly NIX_ROOT="/nix"
@@ -707,6 +707,12 @@ EOF
707707
fi
708708
}
709709

710+
check_required_system_specific_settings() {
711+
if [ -z "${NIX_FIRST_BUILD_UID+x}" ] || [ -z "${NIX_BUILD_USER_NAME_TEMPLATE+x}" ]; then
712+
failure "Internal error: System specific installer for $(uname) ($1) does not export required settings."
713+
fi
714+
}
715+
710716
welcome_to_nix() {
711717
local -r NIX_UID_RANGES="${NIX_FIRST_BUILD_UID}..$((NIX_FIRST_BUILD_UID + NIX_USER_COUNT - 1))"
712718
local -r RANGE_TEXT=$(echo -ne "${BLUE}(uids [${NIX_UID_RANGES}])${ESC}")
@@ -726,7 +732,9 @@ manager. This will happen in a few stages:
726732
if you are ready to continue.
727733
728734
3. Create the system users ${RANGE_TEXT} and groups ${GROUP_TEXT}
729-
that the Nix daemon uses to run builds.
735+
that the Nix daemon uses to run builds. To create system users
736+
in a different range, exit and run this tool again with
737+
NIX_FIRST_BUILD_UID set.
730738
731739
4. Perform the basic installation of the Nix files daemon.
732740
@@ -968,13 +976,16 @@ main() {
968976
if is_os_darwin; then
969977
# shellcheck source=./install-darwin-multi-user.sh
970978
. "$EXTRACTED_NIX_PATH/install-darwin-multi-user.sh"
979+
check_required_system_specific_settings "install-darwin-multi-user.sh"
971980
elif is_os_linux; then
972981
# shellcheck source=./install-systemd-multi-user.sh
973982
. "$EXTRACTED_NIX_PATH/install-systemd-multi-user.sh" # most of this works on non-systemd distros also
983+
check_required_system_specific_settings "install-systemd-multi-user.sh"
974984
else
975985
failure "Sorry, I don't know what to do on $(uname)"
976986
fi
977987

988+
978989
welcome_to_nix
979990

980991
if ! is_root; then

scripts/install-systemd-multi-user.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
set -eu
44
set -o pipefail
55

6+
# System specific settings
7+
export NIX_FIRST_BUILD_UID="${NIX_FIRST_BUILD_UID:-30001}"
8+
export NIX_BUILD_USER_NAME_TEMPLATE="nixbld%d"
9+
610
readonly SERVICE_SRC=/lib/systemd/system/nix-daemon.service
711
readonly SERVICE_DEST=/etc/systemd/system/nix-daemon.service
812

0 commit comments

Comments
 (0)