2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-17 22:21:37 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2012-03-17 22:21:37 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
crashdump = config.boot.crashDump;
|
2012-03-18 10:02:58 +00:00
|
|
|
|
|
|
|
kernelParams = concatStringsSep " " crashdump.kernelParams;
|
2012-09-05 07:55:02 +00:00
|
|
|
|
2012-03-17 22:21:37 +00:00
|
|
|
in
|
|
|
|
###### interface
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
boot = {
|
|
|
|
crashDump = {
|
|
|
|
enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2012-03-17 22:21:37 +00:00
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2012-03-17 22:21:37 +00:00
|
|
|
If enabled, NixOS will set up a kernel that will
|
2017-10-25 20:00:52 +00:00
|
|
|
boot on crash, and leave the user in systemd rescue
|
|
|
|
to be able to save the crashed kernel dump at
|
|
|
|
/proc/vmcore.
|
2012-03-17 22:21:37 +00:00
|
|
|
It also activates the NMI watchdog.
|
|
|
|
'';
|
|
|
|
};
|
2017-10-25 20:00:52 +00:00
|
|
|
reservedMemory = mkOption {
|
|
|
|
default = "128M";
|
2021-01-22 10:10:26 +00:00
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2017-10-25 20:00:52 +00:00
|
|
|
The amount of memory reserved for the crashdump kernel.
|
|
|
|
If you choose a too high value, dmesg will mention
|
|
|
|
"crashkernel reservation failed".
|
2012-03-17 22:21:37 +00:00
|
|
|
'';
|
|
|
|
};
|
2012-03-18 10:02:58 +00:00
|
|
|
kernelParams = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.listOf types.str;
|
2017-10-25 20:00:52 +00:00
|
|
|
default = [ "1" "boot.shell_on_fail" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2012-03-18 10:02:58 +00:00
|
|
|
Parameters that will be passed to the kernel kexec-ed on crash.
|
|
|
|
'';
|
|
|
|
};
|
2012-03-17 22:21:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf crashdump.enable {
|
|
|
|
boot = {
|
|
|
|
postBootCommands = ''
|
2017-10-25 20:00:52 +00:00
|
|
|
echo "loading crashdump kernel...";
|
2021-09-03 14:17:21 +00:00
|
|
|
${pkgs.kexec-tools}/sbin/kexec -p /run/current-system/kernel \
|
2012-07-16 15:27:59 +00:00
|
|
|
--initrd=/run/current-system/initrd \
|
2017-10-25 20:00:52 +00:00
|
|
|
--reset-vga --console-vga \
|
2019-04-26 10:02:11 +00:00
|
|
|
--command-line="init=$(readlink -f /run/current-system/init) irqpoll maxcpus=1 reset_devices ${kernelParams}"
|
2012-03-17 22:21:37 +00:00
|
|
|
'';
|
|
|
|
kernelParams = [
|
2017-10-25 20:00:52 +00:00
|
|
|
"crashkernel=${crashdump.reservedMemory}"
|
2012-07-18 19:50:18 +00:00
|
|
|
"nmi_watchdog=panic"
|
2012-09-05 07:55:02 +00:00
|
|
|
"softlockup_panic=1"
|
2012-03-17 22:21:37 +00:00
|
|
|
];
|
2017-10-25 20:00:52 +00:00
|
|
|
kernelPatches = [ {
|
|
|
|
name = "crashdump-config";
|
|
|
|
patch = null;
|
|
|
|
extraConfig = ''
|
2012-03-17 22:21:37 +00:00
|
|
|
CRASH_DUMP y
|
|
|
|
DEBUG_INFO y
|
|
|
|
PROC_VMCORE y
|
2012-07-18 19:50:18 +00:00
|
|
|
LOCKUP_DETECTOR y
|
|
|
|
HARDLOCKUP_DETECTOR y
|
2012-03-17 22:21:37 +00:00
|
|
|
'';
|
2017-10-25 20:00:52 +00:00
|
|
|
} ];
|
2012-03-17 22:21:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|