1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 crashdump = config.boot.crashDump; 7 8 kernelParams = concatStringsSep " " crashdump.kernelParams; 9 10in 11###### interface 12{ 13 options = { 14 boot = { 15 crashDump = { 16 enable = mkOption { 17 type = types.bool; 18 default = false; 19 description = '' 20 If enabled, NixOS will set up a kernel that will 21 boot on crash, and leave the user to a stage1 debug1devices 22 interactive shell to be able to save the crashed kernel dump. 23 It also activates the NMI watchdog. 24 ''; 25 }; 26 kernelPackages = mkOption { 27 type = types.package; 28 default = pkgs.linuxPackages; 29 # We don't want to evaluate all of linuxPackages for the manual 30 # - some of it might not even evaluate correctly. 31 defaultText = "pkgs.linuxPackages"; 32 example = literalExample "pkgs.linuxPackages_2_6_25"; 33 description = '' 34 This will override the boot.kernelPackages, and will add some 35 kernel configuration parameters for the crash dump to work. 36 ''; 37 }; 38 kernelParams = mkOption { 39 type = types.listOf types.str; 40 default = [ "debug1devices" ]; 41 description = '' 42 Parameters that will be passed to the kernel kexec-ed on crash. 43 ''; 44 }; 45 }; 46 }; 47 }; 48 49###### implementation 50 51 config = mkIf crashdump.enable { 52 boot = { 53 postBootCommands = '' 54 ${pkgs.kexectools}/sbin/kexec -p /run/current-system/kernel \ 55 --initrd=/run/current-system/initrd \ 56 --append="init=$(readlink -f /run/current-system/init) system=$(readlink -f /run/current-system) irqpoll maxcpus=1 reset_devices ${kernelParams}" --reset-vga --console-vga 57 ''; 58 kernelParams = [ 59 "crashkernel=64M" 60 "nmi_watchdog=panic" 61 "softlockup_panic=1" 62 "idle=poll" 63 ]; 64 kernelPackages = mkOverride 50 (crashdump.kernelPackages // { 65 kernel = crashdump.kernelPackages.kernel.override 66 (attrs: { 67 extraConfig = (optionalString (attrs ? extraConfig) attrs.extraConfig) + 68 '' 69 CRASH_DUMP y 70 DEBUG_INFO y 71 PROC_VMCORE y 72 LOCKUP_DETECTOR y 73 HARDLOCKUP_DETECTOR y 74 ''; 75 }); 76 }); 77 }; 78 }; 79}