13 writeShellApplication {
14 name = "${hostName}-switch";
19 # shellcheck disable=SC2027
20 # shellcheck disable=SC2035
21 # shellcheck disable=SC2086
25 chmod -R g-rwx,o-rwx ./**/*.gpg
26 trap 'git reset ./**/*.gpg' EXIT
27 git rm -rf --cached --ignore-unmatch ./**/*.gpg # prevent copying to /nix/store
29 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
30 nix-store --add-root hosts/${hostName}.root --indirect --realise ${nixos}
32 target="''${NIXOS_TARGET:-${lib.escapeShellArg config.install.target}}"
34 nix copy --to "ssh://''${target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${nixos}
36 ${config.security.initrd.install}
37 target="''${NIXOS_TARGET:-${lib.escapeShellArg config.install.target}}"
39 if ssh "$target" set -x ';' \
40 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
41 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
42 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
51 ${profile}/bin/switch-to-configuration switch
54 ${nixos}/bin/switch-to-configuration test
56 ssh "$target" -o ControlPath=none set -x ';' \
57 systemctl stop nixos-fallback.service ';' \
58 nix-env --profile ${profile} --set '${nixos}' ';' \
59 ${nixos}/bin/switch-to-configuration boot '&&' \
60 nix-env --delete-generations 7d --profile ${profile}
63 echo WARNING: switch-to-configuration was not registered at boot
65 ssh "$target" -o ControlPath=none set -x ';' \
66 systemctl stop nixos-fallback.service