2020-05-03 16:42:00 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-06-07 14:03:12 +00:00
|
|
|
# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-05-03 16:42:00 +00:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
if [ $EUID -ne 0 ]; then
|
|
|
|
exec sudo "$0" "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
echo "Usage: $0 hostname" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
depot_parent() {
|
|
|
|
pd="$(readlink -f "$1")/"
|
|
|
|
if [ "${pd#*/depot/}" = "$pd" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
pd="$(readlink -f "${pd%/depot/*}/depot")"
|
|
|
|
echo "$pd"
|
|
|
|
}
|
|
|
|
|
|
|
|
depot_path() {
|
|
|
|
pd="$(depot_parent "$PWD")"
|
|
|
|
if [ "$pd" = "" ]; then
|
|
|
|
pd="$(depot_parent "$(readlink -f "$0")")"
|
|
|
|
fi
|
|
|
|
echo "$pd"
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly targethostname="$1"
|
|
|
|
readonly depot="$(depot_path)"
|
|
|
|
if [ "$depot" = "" ]; then
|
|
|
|
echo "This script needs to be executed in-depot (or the script itself should be in-depot)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
readonly system="$(nix-build -E '(import "'"$(depot_path)"'" {}).ops.nixos.'"${targethostname}" --no-out-link)"
|
|
|
|
nix-env -p /nix/var/nix/profiles/system --set "$system"
|
2020-06-07 14:03:12 +00:00
|
|
|
"$system/bin/switch-to-configuration" switch
|