2018-03-28 13:16:13 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-07-09 17:07:28 +00:00
|
|
|
|
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
readonly PLIST_DEST=/Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
2021-02-07 21:34:24 +00:00
|
|
|
NIX_FIRST_BUILD_UID="301"
|
|
|
|
NIX_BUILD_USER_NAME_TEMPLATE="_nixbld%d"
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
dsclattr() {
|
|
|
|
/usr/bin/dscl . -read "$1" \
|
|
|
|
| awk "/$2/ { print \$2 }"
|
|
|
|
}
|
2017-07-13 21:22:54 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_validate_assumptions() {
|
|
|
|
if [ "$(uname -s)" != "Darwin" ]; then
|
|
|
|
failure "This script is for use with macOS!"
|
2017-07-13 23:03:35 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_service_installed_check() {
|
|
|
|
[ -e "$PLIST_DEST" ]
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_service_uninstall_directions() {
|
2017-07-10 02:08:14 +00:00
|
|
|
cat <<EOF
|
2018-03-28 13:16:13 +00:00
|
|
|
$1. Delete $PLIST_DEST
|
2017-07-09 17:07:28 +00:00
|
|
|
|
|
|
|
sudo launchctl unload $PLIST_DEST
|
|
|
|
sudo rm $PLIST_DEST
|
|
|
|
|
|
|
|
EOF
|
2018-03-28 13:16:13 +00:00
|
|
|
}
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_service_setup_note() {
|
2017-07-09 17:07:28 +00:00
|
|
|
cat <<EOF
|
2018-03-28 13:16:13 +00:00
|
|
|
- load and start a LaunchDaemon (at $PLIST_DEST) for nix-daemon
|
2017-07-09 17:07:28 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2020-09-11 17:06:01 +00:00
|
|
|
poly_extra_try_me_commands(){
|
|
|
|
:
|
|
|
|
}
|
|
|
|
poly_extra_setup_instructions(){
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_configure_nix_daemon_service() {
|
|
|
|
_sudo "to set up the nix-daemon as a LaunchDaemon" \
|
2019-10-09 01:17:27 +00:00
|
|
|
cp -f "/nix/var/nix/profiles/default$PLIST_DEST" "$PLIST_DEST"
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
_sudo "to load the LaunchDaemon plist for nix-daemon" \
|
|
|
|
launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
_sudo "to start the nix-daemon" \
|
|
|
|
launchctl start org.nixos.nix-daemon
|
2017-07-09 17:07:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_group_exists() {
|
|
|
|
/usr/bin/dscl . -read "/Groups/$1" > /dev/null 2>&1
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_group_id_get() {
|
|
|
|
dsclattr "/Groups/$1" "PrimaryGroupID"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_create_build_group() {
|
|
|
|
_sudo "Create the Nix build group, $NIX_BUILD_GROUP_NAME" \
|
|
|
|
/usr/sbin/dseditgroup -o create \
|
|
|
|
-r "Nix build group for nix-daemon" \
|
|
|
|
-i "$NIX_BUILD_GROUP_ID" \
|
|
|
|
"$NIX_BUILD_GROUP_NAME" >&2
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_exists() {
|
|
|
|
/usr/bin/dscl . -read "/Users/$1" > /dev/null 2>&1
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_id_get() {
|
|
|
|
dsclattr "/Users/$1" "UniqueID"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_hidden_get() {
|
|
|
|
dsclattr "/Users/$1" "IsHidden"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_hidden_set() {
|
|
|
|
_sudo "in order to make $1 a hidden user" \
|
|
|
|
/usr/bin/dscl . -create "/Users/$1" "IsHidden" "1"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_home_get() {
|
|
|
|
dsclattr "/Users/$1" "NFSHomeDirectory"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_home_set() {
|
|
|
|
_sudo "in order to give $1 a safe home directory" \
|
|
|
|
/usr/bin/dscl . -create "/Users/$1" "NFSHomeDirectory" "$2"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_note_get() {
|
|
|
|
dsclattr "/Users/$1" "RealName"
|
2017-07-10 02:08:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_note_set() {
|
|
|
|
_sudo "in order to give $username a useful note" \
|
|
|
|
/usr/bin/dscl . -create "/Users/$1" "RealName" "$2"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_shell_get() {
|
|
|
|
dsclattr "/Users/$1" "UserShell"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_shell_set() {
|
|
|
|
_sudo "in order to give $1 a safe home directory" \
|
|
|
|
/usr/bin/dscl . -create "/Users/$1" "UserShell" "$2"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_in_group_check() {
|
|
|
|
username=$1
|
|
|
|
group=$2
|
|
|
|
dseditgroup -o checkmember -m "$username" "$group" > /dev/null 2>&1
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_in_group_set() {
|
|
|
|
username=$1
|
|
|
|
group=$2
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
_sudo "Add $username to the $group group"\
|
|
|
|
/usr/sbin/dseditgroup -o edit -t user \
|
|
|
|
-a "$username" "$group"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_primary_group_get() {
|
|
|
|
dsclattr "/Users/$1" "PrimaryGroupID"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_user_primary_group_set() {
|
|
|
|
_sudo "to let the nix daemon use this user for builds (this might seem redundant, but there are two concepts of group membership)" \
|
|
|
|
/usr/bin/dscl . -create "/Users/$1" "PrimaryGroupID" "$2"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
poly_create_build_user() {
|
|
|
|
username=$1
|
|
|
|
uid=$2
|
|
|
|
builder_num=$3
|
2017-07-09 17:07:28 +00:00
|
|
|
|
2018-03-28 13:16:13 +00:00
|
|
|
_sudo "Creating the Nix build user (#$builder_num), $username" \
|
|
|
|
/usr/bin/dscl . create "/Users/$username" \
|
|
|
|
UniqueID "${uid}"
|
2017-07-09 17:07:28 +00:00
|
|
|
}
|