#! @shell@ -e # Allow the location of NixOS sources and the system configuration # file to be overridden. NIXOS=${NIXOS:-/etc/nixos/nixos} NIXPKGS=${NIXPKGS:-/etc/nixos/nixpkgs} NIXOS_CONFIG=${NIXOS_CONFIG:-/etc/nixos/configuration.nix} export NIXPKGS # must be exported so that a non default location is passed to nixos/default.nix showSyntax() { # !!! more or less cut&paste from # system/switch-to-configuration.sh (which we call, of course). cat <&1 | grep -q 'running'; then export NIX_REMOTE=${NIX_REMOTE:-daemon} fi # Pull the manifests defined in the configuration (the "manifests" # attribute). Wonderfully hacky. if test -n "$pullManifest"; then manifests=$(nix-instantiate --eval-only --xml --strict $NIXOS -A manifests \ | grep '&2 if ! nix-build $NIXOS -A config.environment.nix -o $tmpDir/nix $extraBuildFlags > /dev/null; then if ! nix-build $NIXOS -A nixFallback -o $tmpDir/nix $extraBuildFlags > /dev/null; then nix-build $NIXPKGS -A nixUnstable -o $tmpDir/nix $extraBuildFlags > /dev/null fi fi PATH=$tmpDir/nix/bin:$PATH 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 test -z "$rollback"; then echo "building the system configuration..." >&2 if test "$action" = switch -o "$action" = boot; then nix-env -p /nix/var/nix/profiles/system -f $NIXOS --set -A system $extraBuildFlags pathToConfig=/nix/var/nix/profiles/system elif test "$action" = test -o "$action" = build -o "$action" = dry-run; then nix-build $NIXOS -A system -K -k $extraBuildFlags > /dev/null pathToConfig=./result elif test "$action" = build-vm; then nix-build $NIXOS -A vm -K -k $extraBuildFlags > /dev/null pathToConfig=./result else showSyntax fi else # test -n "$rollback" if test "$action" = switch -o "$action" = boot; then nix-env --rollback -p /nix/var/nix/profiles/system pathToConfig=/nix/var/nix/profiles/system elif test "$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 test "$action" = switch -o "$action" = boot -o "$action" = test; then $pathToConfig/bin/switch-to-configuration "$action" fi if test "$action" = test; then cat >&2 <&2 <