1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
pov,
hostConfig,
config,
lib,
...
}:
let
inherit (lib) types;
cfg = lib.getAttrFromPath pov config;
in
{
option = {
type = types.bool;
default = false;
};
config = lib.mkIf (cfg.enable && cfg.kernel) {
environment = {
# memoryAllocator.provider = mkDefault "scudo"; # Breaks stuff
# variables.SCUDO_OPTIONS = mkDefault "ZeroContents=1"; # Breaks stuff
};
boot = {
blacklistedKernelModules = [
# Obscure network protocols
"ax25"
"netrom"
"rose"
# Old or rare or insufficiently audited filesystems
"adfs"
"affs"
"bfs"
"befs"
"cramfs"
"efs"
"erofs"
"exofs"
"freevxfs"
"f2fs"
"hfs"
"hpfs"
"jfs"
"minix"
"nilfs2"
"ntfs"
"omfs"
"qnx4"
"qnx6"
"sysv"
"ufs"
];
kernel.sysctl = {
"kernel.yama.ptrace_scope" = lib.mkOverride 500 1;
"kernel.kptr_restrict" = lib.mkOverride 500 2;
"net.core.bpf_jit_enable" = lib.mkDefault false;
"kernel.ftrace_enabled" = lib.mkDefault false;
};
kernelParams = lib.mkMerge [
[
# Slab/slub sanity checks, redzoning, and poisoning
"slub_debug=FZP"
# Overwrite free'd memory
"page_poison=1"
# Enable page allocator randomization
"page_alloc.shuffle=1"
]
# Disable hibernation (allows replacing the running kernel) unless requested
(lib.mkIf (!hostConfig.hardware.allowHibernation) [ "nohibernate" ])
];
};
# Disable kernel module loading once the system is fully initialised.
# FIXME: Remove reverse dependencies
security.lockKernelModules = lib.mkDefault (!config.modules.presets.graphical.enable);
# Prevent replacing the running kernel image w/o reboot
boot.kernel.sysctl."kernel.kexec_load_disabled" = lib.mkDefault true;
};
}