4 config = lib.mkIf (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexec-tools) {
5 environment.systemPackages = [ pkgs.kexec-tools ];
7 systemd.services.prepare-kexec =
8 { description = "Preparation for kexec";
9 wantedBy = [ "kexec.target" ];
10 before = [ "systemd-kexec.service" ];
11 unitConfig.DefaultDependencies = false;
12 serviceConfig.Type = "oneshot";
13 path = [ pkgs.kexec-tools ];
16 # Don't load the current system profile if we already have a kernel loaded
17 if [[ 1 = "$(</sys/kernel/kexec_loaded)" ]] ; then
18 echo "kexec kernel has already been loaded, prepare-kexec skipped"
22 p=$(readlink -f /nix/var/nix/profiles/system)
23 if ! [[ -d $p ]]; then
24 echo "Could not find system profile for prepare-kexec"
27 echo "Loading NixOS system via kexec."
28 exec kexec --load "$p/kernel" --initrd="$p/initrd" --append="$(cat "$p/kernel-params") init=$p/init"