2016-12-12 16:34:43 +00:00
|
|
|
|
#! @shell@
|
|
|
|
|
set -e
|
|
|
|
|
set -o pipefail
|
|
|
|
|
export PATH=@path@:$PATH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showSyntax() {
|
2016-12-19 23:05:01 +00:00
|
|
|
|
echo "darwin-rebuild [--help] {build | switch} [{--profile-name | -p} name]" >&2
|
|
|
|
|
echo " [--verbose...] [-v...] [-Q] [{--max-jobs | -j} number] [--cores number]" >&2
|
2016-12-22 22:27:29 +00:00
|
|
|
|
echo " [--dry-run] [--keep-failed] [-K] [--fallback] [--show-trace] [-I path]" >&2
|
2016-12-19 23:05:01 +00:00
|
|
|
|
echo " [--option name value] [--arg name value] [--argstr name value]" >&2
|
2016-12-15 20:52:53 +00:00
|
|
|
|
exec man darwin-rebuild
|
|
|
|
|
exit 1
|
2016-12-12 16:34:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Parse the command line.
|
|
|
|
|
origArgs=("$@")
|
2016-12-19 23:05:01 +00:00
|
|
|
|
extraBuildFlags=()
|
|
|
|
|
profile=@profile@
|
2016-12-12 16:34:43 +00:00
|
|
|
|
action=
|
|
|
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
2016-12-15 20:52:53 +00:00
|
|
|
|
i="$1"; shift 1
|
|
|
|
|
case "$i" in
|
|
|
|
|
--help)
|
|
|
|
|
showSyntax
|
|
|
|
|
;;
|
|
|
|
|
switch|build)
|
|
|
|
|
action="$i"
|
|
|
|
|
;;
|
2016-12-22 22:25:32 +00:00
|
|
|
|
--show-trace|--no-build-hook|--dry-run|--keep-failed|-K|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|-Q)
|
2016-12-19 23:05:01 +00:00
|
|
|
|
extraBuildFlags+=("$i")
|
|
|
|
|
;;
|
|
|
|
|
--max-jobs|-j|--cores|-I)
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
echo "$0: ‘$i’ requires an argument"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
j="$1"; shift 1
|
|
|
|
|
extraBuildFlags+=("$i" "$j")
|
|
|
|
|
;;
|
|
|
|
|
--arg|--argstr|--option)
|
|
|
|
|
if [ -z "$1" -o -z "$2" ]; then
|
|
|
|
|
echo "$0: ‘$i’ requires two arguments"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
j="$1"; shift 1
|
|
|
|
|
k="$1"; shift 1
|
|
|
|
|
extraBuildFlags+=("$i" "$j" "$k")
|
|
|
|
|
;;
|
|
|
|
|
--profile-name|-p)
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
echo "$0: ‘--profile-name’ requires an argument"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if [ "$1" != system ]; then
|
|
|
|
|
profile="/nix/var/nix/profiles/system-profiles/$1"
|
|
|
|
|
mkdir -p -m 0755 "$(dirname "$profile")"
|
|
|
|
|
fi
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
2016-12-15 20:52:53 +00:00
|
|
|
|
*)
|
|
|
|
|
echo "$0: unknown option \`$i'"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2016-12-12 16:34:43 +00:00
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -z "$action" ]; then showSyntax; fi
|
|
|
|
|
|
|
|
|
|
echo "building the system configuration..." >&2
|
|
|
|
|
if [ "$action" = switch -o "$action" = build ]; then
|
2016-12-19 23:05:01 +00:00
|
|
|
|
systemConfig="$(nix-build '<darwin>' ${extraBuildFlags[@]} --no-out-link -A system)"
|
2016-12-12 16:34:43 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2016-12-22 22:25:32 +00:00
|
|
|
|
if [ -z "$systemConfig" ]; then exit 0; fi
|
|
|
|
|
|
2016-12-14 14:45:45 +00:00
|
|
|
|
if [ "$action" = build ]; then
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo $systemConfig
|
2016-12-14 14:45:45 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2016-12-12 16:34:43 +00:00
|
|
|
|
if [ "$action" = switch ]; then
|
2016-12-19 23:05:01 +00:00
|
|
|
|
if [ "$USER" != root -a ! -w $(dirname "$profile") ]; then
|
|
|
|
|
sudo nix-env -p $profile --set $systemConfig
|
2016-12-15 20:52:53 +00:00
|
|
|
|
else
|
2016-12-19 23:05:01 +00:00
|
|
|
|
nix-env -p $profile --set $systemConfig
|
2016-12-15 20:52:53 +00:00
|
|
|
|
fi
|
2016-12-14 14:45:45 +00:00
|
|
|
|
|
2016-12-15 20:52:53 +00:00
|
|
|
|
if [ "$USER" != root ]; then
|
|
|
|
|
sudo $systemConfig/activate
|
|
|
|
|
else
|
|
|
|
|
$systemConfig/activate
|
|
|
|
|
fi
|
2016-12-14 14:45:45 +00:00
|
|
|
|
|
2016-12-15 20:52:53 +00:00
|
|
|
|
$systemConfig/activate-user
|
2016-12-12 16:34:43 +00:00
|
|
|
|
fi
|