at 18.09-beta 1.3 kB view raw
1{ config, lib, ... }: 2 3with lib; 4 5{ 6 options = { 7 security.lockKernelModules = mkOption { 8 type = types.bool; 9 default = false; 10 description = '' 11 Disable kernel module loading once the system is fully initialised. 12 Module loading is disabled until the next reboot. Problems caused 13 by delayed module loading can be fixed by adding the module(s) in 14 question to <option>boot.kernelModules</option>. 15 ''; 16 }; 17 }; 18 19 config = mkIf config.security.lockKernelModules { 20 boot.kernelModules = concatMap (x: 21 if x.device != null 22 then 23 if x.fsType == "vfat" 24 then [ "vfat" "nls-cp437" "nls-iso8859-1" ] 25 else [ x.fsType ] 26 else []) config.system.build.fileSystems; 27 28 systemd.services.disable-kernel-module-loading = rec { 29 description = "Disable kernel module loading"; 30 31 wantedBy = [ config.systemd.defaultUnit ]; 32 33 after = [ "systemd-udev-settle.service" "firewall.service" "systemd-modules-load.service" ] ++ wantedBy; 34 35 unitConfig.ConditionPathIsReadWrite = "/proc/sys/kernel"; 36 37 serviceConfig = { 38 Type = "oneshot"; 39 RemainAfterExit = true; 40 ExecStart = "/bin/sh -c 'echo -n 1 >/proc/sys/kernel/modules_disabled'"; 41 }; 42 }; 43 }; 44}