at master 1.3 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7 8let 9 cfg = config.boot.kexec; 10in 11{ 12 options.boot.kexec = { 13 enable = lib.mkEnableOption "kexec" // { 14 default = lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexec-tools; 15 defaultText = lib.literalExpression ''lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexec-tools''; 16 }; 17 }; 18 19 config = lib.mkIf cfg.enable { 20 environment.systemPackages = [ pkgs.kexec-tools ]; 21 22 systemd.services.prepare-kexec = { 23 description = "Preparation for kexec"; 24 wantedBy = [ "kexec.target" ]; 25 before = [ "systemd-kexec.service" ]; 26 unitConfig.DefaultDependencies = false; 27 serviceConfig.Type = "oneshot"; 28 path = [ pkgs.kexec-tools ]; 29 script = '' 30 # Don't load the current system profile if we already have a kernel loaded 31 if [[ 1 = "$(</sys/kernel/kexec_loaded)" ]] ; then 32 echo "kexec kernel has already been loaded, prepare-kexec skipped" 33 exit 0 34 fi 35 36 p=$(readlink -f /nix/var/nix/profiles/system) 37 if ! [[ -d $p ]]; then 38 echo "Could not find system profile for prepare-kexec" 39 exit 1 40 fi 41 echo "Loading NixOS system via kexec." 42 exec kexec --load "$p/kernel" --initrd="$p/initrd" --append="$(cat "$p/kernel-params") init=$p/init" 43 ''; 44 }; 45 }; 46}