#! @shell@ -e showSyntax() { # !!! more or less cut&paste from # system/switch-to-configuration.sh (which we call, of course). cat <&2 if ! nix-build '' -A config.environment.nix -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then if ! nix-build '' -A nixFallback -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then nix-build '' -A nixUnstable -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null fi fi PATH=$tmpDir/nix/bin:$PATH fi # Update the version suffix if we're building from Git (so that # nixos-version shows something useful). if nixos=$(nix-instantiate --find-file nixos "${extraBuildFlags[@]}"); then suffix=$($SHELL $nixos/modules/installer/tools/get-version-suffix "${extraBuildFlags[@]}") if [ -n "$suffix" ]; then echo -n "$suffix" > "$nixos/.version-suffix" fi fi # Either upgrade the configuration in the system profile (for "switch" # or "boot"), or just build it and create a symlink "result" in the # current directory (for "build" and "test"). if [ -z "$rollback" ]; then echo "building the system configuration..." >&2 if [ "$action" = switch -o "$action" = boot ]; then nix-env "${extraBuildFlags[@]}" -p /nix/var/nix/profiles/system -f '' --set -A system pathToConfig=/nix/var/nix/profiles/system elif [ "$action" = test -o "$action" = build -o "$action" = dry-run ]; then nix-build '' -A system -K -k "${extraBuildFlags[@]}" > /dev/null pathToConfig=./result elif [ "$action" = build-vm ]; then nix-build '' -A vm -K -k "${extraBuildFlags[@]}" > /dev/null pathToConfig=./result elif [ "$action" = build-vm-with-bootloader ]; then nix-build '' -A vmWithBootLoader -K -k "${extraBuildFlags[@]}" > /dev/null pathToConfig=./result else showSyntax fi else # [ -n "$rollback" ] if [ "$action" = switch -o "$action" = boot ]; then nix-env --rollback -p /nix/var/nix/profiles/system pathToConfig=/nix/var/nix/profiles/system elif [ "$action" = test -o "$action" = build ]; then systemNumber=$( nix-env -p /nix/var/nix/profiles/system --list-generations | sed -n '/current/ {g; p;}; s/ *\([0-9]*\).*/\1/; h' ) ln -sT /nix/var/nix/profiles/system-${systemNumber}-link ./result pathToConfig=./result else showSyntax fi fi # If we're not just building, then make the new configuration the boot # default and/or activate it now. if [ "$action" = switch -o "$action" = boot -o "$action" = test ]; then # Just in case the new configuration hangs the system, do a sync now. sync $pathToConfig/bin/switch-to-configuration "$action" fi if [ "$action" = build-vm ]; then cat >&2 <