1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-04-15 08:46:25 +00:00

implement darwin-rebuild flags

This commit is contained in:
Daiderd Jordan 2016-12-20 00:05:01 +01:00
parent 66f249f22a
commit f317db6bf4
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -5,13 +5,18 @@ export PATH=@path@:$PATH
showSyntax() {
echo "$0: {build|switch}"
echo "darwin-rebuild [--help] {build | switch} [{--profile-name | -p} name]" >&2
echo " [--verbose...] [-v...] [-Q] [{--max-jobs | -j} number] [--cores number]" >&2
echo " [--keep-failed] [-K] [--fallback] [--show-trace] [-I path]" >&2
echo " [--option name value] [--arg name value] [--argstr name value]" >&2
exec man darwin-rebuild
exit 1
}
# Parse the command line.
origArgs=("$@")
extraBuildFlags=()
profile=@profile@
action=
while [ "$#" -gt 0 ]; do
@ -23,6 +28,37 @@ while [ "$#" -gt 0 ]; do
switch|build)
action="$i"
;;
--show-trace|--no-build-hook|--keep-failed|-K|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|-Q)
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
;;
*)
echo "$0: unknown option \`$i'"
exit 1
@ -34,7 +70,7 @@ if [ -z "$action" ]; then showSyntax; fi
echo "building the system configuration..." >&2
if [ "$action" = switch -o "$action" = build ]; then
systemConfig="$(nix-build '<darwin>' --no-out-link -A system)"
systemConfig="$(nix-build '<darwin>' ${extraBuildFlags[@]} --no-out-link -A system)"
fi
if [ "$action" = build ]; then
@ -43,12 +79,10 @@ fi
if [ "$action" = switch ]; then
profileDir=$(dirname @profile@)
if [ "$USER" != root -a ! -w $profileDir ]; then
sudo nix-env -p @profile@ --set $systemConfig
if [ "$USER" != root -a ! -w $(dirname "$profile") ]; then
sudo nix-env -p $profile --set $systemConfig
else
nix-env -p @profile@ --set $systemConfig
nix-env -p $profile --set $systemConfig
fi
if [ "$USER" != root ]; then