feat(nixos): capture kernel lockups as panics on headless servers (#529)

Assisted-by: DeepSeek Harness (claude-opus-5-5)
This commit is contained in:
ryan4yin | 二花 authored and GitHub committed 2026-11-17 21:04:51 +08:00
1 parent bd2b8594f7
commit 9b1a716aa8
4 files changed
+30

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ in
{
imports = [
disko.nixosModules.default
../../modules/nixos/headless-recovery.nix
../../modules/nixos/power.nix
../../modules/nixos/watchdog.nix
# disks
+1
View File
@@ -12,6 +12,7 @@ in
{
# CPU policy belongs to physical hosts; guests do not control hardware frequency.
imports = [
../modules/nixos/headless-recovery.nix
../modules/nixos/power.nix
../modules/nixos/watchdog.nix
];
+26
View File
@@ -0,0 +1,26 @@
{ pkgs, ... }:
{
# Headless physical servers: turn silent kernel failures into panics, so efi_pstore keeps the
# dmesg and kernel.panic reboots. Desktops stay out: a GPU driver oops would drop the session.
# hung_task_panic stays off: a stalled USB disk would trip it.
# Armed 5 minutes after boot, so an oops during boot cannot loop panic-reboots before SSH is up.
systemd.services.panic-on-lockup = {
description = "Panic on kernel oops, lockup or RCU stall";
path = [ pkgs.procps ];
serviceConfig.Type = "oneshot";
script = ''
sysctl -w kernel.panic_on_oops=1
sysctl -w kernel.softlockup_panic=1
sysctl -w kernel.hardlockup_panic=1
sysctl -w kernel.panic_on_rcu_stall=1
'';
};
systemd.timers.panic-on-lockup = {
wantedBy = [ "timers.target" ];
timerConfig.OnBootSec = "5min";
};
# Keep the panic text visible on an attached monitor.
boot.kernelParams = [ "consoleblank=0" ];
# A failed mount continues the boot with SSH instead of waiting on a console sulogin.
systemd.enableEmergencyMode = false;
}
+2
View File
@@ -3,4 +3,6 @@
# a host without a hardware watchdog only logs that /dev/watchdog is missing.
systemd.settings.Manager.RuntimeWatchdogSec = "30s";
boot.kernel.sysctl."kernel.panic" = 20; # seconds; the default 0 hangs forever
# A hard reset keeps only what journald fsynced; the default 5min loses the lead-up to a freeze.
services.journald.settings.Journal.SyncIntervalSec = "5s";
}