2018-07-20 20:56:59 +00:00
|
|
|
{ pkgs, lib, ... }:
|
2013-09-16 17:15:42 +02:00
|
|
|
|
|
|
|
{
|
2021-09-03 10:17:21 -04:00
|
|
|
config = lib.mkIf (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexec-tools) {
|
|
|
|
environment.systemPackages = [ pkgs.kexec-tools ];
|
2013-09-16 17:15:42 +02:00
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
systemd.services.prepare-kexec = {
|
2018-02-27 20:34:13 -05:00
|
|
|
description = "Preparation for kexec";
|
|
|
|
wantedBy = [ "kexec.target" ];
|
|
|
|
before = [ "systemd-kexec.service" ];
|
|
|
|
unitConfig.DefaultDependencies = false;
|
|
|
|
serviceConfig.Type = "oneshot";
|
2021-09-03 10:17:21 -04:00
|
|
|
path = [ pkgs.kexec-tools ];
|
2018-02-27 20:34:13 -05:00
|
|
|
script = ''
|
2019-04-26 00:33:40 +02:00
|
|
|
# Don't load the current system profile if we already have a kernel loaded
|
2019-04-29 22:43:16 +02:00
|
|
|
if [[ 1 = "$(</sys/kernel/kexec_loaded)" ]] ; then
|
|
|
|
echo "kexec kernel has already been loaded, prepare-kexec skipped"
|
|
|
|
exit 0
|
|
|
|
fi
|
2019-04-26 00:33:40 +02:00
|
|
|
|
2018-02-27 20:34:13 -05:00
|
|
|
p=$(readlink -f /nix/var/nix/profiles/system)
|
2019-04-29 22:43:16 +02:00
|
|
|
if ! [[ -d $p ]]; then
|
|
|
|
echo "Could not find system profile for prepare-kexec"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Loading NixOS system via kexec."
|
2023-11-30 17:13:42 +01:00
|
|
|
exec kexec --load "$p/kernel" --initrd="$p/initrd" --append="$(cat "$p/kernel-params") init=$p/init"
|
2018-02-27 20:34:13 -05:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|