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