{ config, pkgs, lib, ... }: { systemd.services."nixos-fallback" = { after = [ "sshd.service" ]; #wantedBy = [ "multi-user.target" ]; serviceConfig = { ExecStart = pkgs.writeShellScript "nixos-fallback-start" '' set -ux # Note that even if switch-to-configuration test # restarts nixos-fallback.service, # it does not change the system profile. profile=/nix/var/nix/profiles/system fallback=$(readlink -e /root/nixos-fallback || readlink -e $profile) sleep $((10 * 60)) nix-env --profile $profile --set $fallback $fallback/bin/switch-to-configuration switch #systemctl reboot ''; }; }; }