# Pastebin V3k23wIo { lib, pkgs, config, ... }: { systemd.targets.my-kexec = { requires = ["my-systemd-kexec.service"]; after = ["my-systemd-kexec.service"]; unitConfig = { DefaultDependencies = "no"; AllowIsolate = "yes"; }; }; systemd.services.my-prepare-kexec = { before = ["my-systemd-kexec.service"]; wantedBy = ["my-kexec.target"]; unitConfig.DefaultDependencies = false; serviceConfig.Type = "oneshot"; path = [pkgs.kexectools]; script = '' # Don't load the current system profile if we already have a kernel loaded if [[ 1 = "$( $initrd exec kexec --load $p/kernel --initrd=$initrd --append="$(cat $p/kernel-params) init=$p/init" ''; }; systemd.services.my-systemd-kexec = { requires = ["shutdown.target" "umount.target" "final.target"]; after = ["shutdown.target" "umount.target" "final.target"]; unitConfig.DefaultDependencies = "no"; serviceConfig.Type = "oneshot"; script = '' echo Rebooting via kexec. exec ${pkgs.kexectools}/bin/kexec -e ''; }; }