2020-04-24 23:36:52 +00:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
|
|
|
|
{
|
2021-09-18 10:52:07 +00:00
|
|
|
config = lib.mkIf (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexec-tools) {
|
|
|
|
environment.systemPackages = [ pkgs.kexec-tools ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.prepare-kexec =
|
|
|
|
{ description = "Preparation for kexec";
|
|
|
|
wantedBy = [ "kexec.target" ];
|
|
|
|
before = [ "systemd-kexec.service" ];
|
|
|
|
unitConfig.DefaultDependencies = false;
|
|
|
|
serviceConfig.Type = "oneshot";
|
2021-09-18 10:52:07 +00:00
|
|
|
path = [ pkgs.kexec-tools ];
|
2020-04-24 23:36:52 +00:00
|
|
|
script =
|
|
|
|
''
|
|
|
|
# Don't load the current system profile if we already have a kernel loaded
|
|
|
|
if [[ 1 = "$(</sys/kernel/kexec_loaded)" ]] ; then
|
|
|
|
echo "kexec kernel has already been loaded, prepare-kexec skipped"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
p=$(readlink -f /nix/var/nix/profiles/system)
|
|
|
|
if ! [[ -d $p ]]; then
|
|
|
|
echo "Could not find system profile for prepare-kexec"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Loading NixOS system via kexec."
|
2024-09-19 14:19:46 +00:00
|
|
|
exec kexec --load "$p/kernel" --initrd="$p/initrd" --append="$(cat "$p/kernel-params") init=$p/init"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|