2024-01-02 11:29:13 +00:00
|
|
|
{ config, lib, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
maintainers = [ maintainers.joachifm ];
|
|
|
|
};
|
|
|
|
|
|
|
|
options = {
|
|
|
|
security.lockKernelModules = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Disable kernel module loading once the system is fully initialised.
|
2021-09-18 10:52:07 +00:00
|
|
|
Module loading is disabled until the next reboot. Problems caused
|
2020-04-24 23:36:52 +00:00
|
|
|
by delayed module loading can be fixed by adding the module(s) in
|
2022-08-12 12:06:08 +00:00
|
|
|
question to {option}`boot.kernelModules`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.security.lockKernelModules {
|
|
|
|
boot.kernelModules = concatMap (x:
|
2023-07-15 17:15:38 +00:00
|
|
|
optionals (x.device != null) (
|
|
|
|
if x.fsType == "vfat"
|
|
|
|
then [ "vfat" "nls-cp437" "nls-iso8859-1" ]
|
|
|
|
else [ x.fsType ])
|
|
|
|
) config.system.build.fileSystems;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
systemd.services.disable-kernel-module-loading = {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Disable kernel module loading";
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
wants = [ "systemd-udevd.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
wantedBy = [ config.systemd.defaultUnit ];
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
after =
|
|
|
|
[ "firewall.service"
|
|
|
|
"systemd-modules-load.service"
|
2021-09-22 15:38:15 +00:00
|
|
|
config.systemd.defaultUnit
|
2021-09-18 10:52:07 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
unitConfig.ConditionPathIsReadWrite = "/proc/sys/kernel";
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
serviceConfig =
|
|
|
|
{ Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
TimeoutSec = 180;
|
|
|
|
};
|
|
|
|
|
|
|
|
script = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
${config.systemd.package}/bin/udevadm settle
|
2021-09-18 10:52:07 +00:00
|
|
|
echo -n 1 >/proc/sys/kernel/modules_disabled
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|