| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  | { config, lib, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-14 22:42:01 +02:00
										 |  |  |   meta = { | 
					
						
							|  |  |  |     maintainers = [ maintainers.joachifm ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  |   options = { | 
					
						
							|  |  |  |     security.lockKernelModules = mkOption { | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       default = false; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         Disable kernel module loading once the system is fully initialised. | 
					
						
							|  |  |  |         Module loading is disabled until the next reboot.  Problems caused | 
					
						
							|  |  |  |         by delayed module loading can be fixed by adding the module(s) in | 
					
						
							|  |  |  |         question to <option>boot.kernelModules</option>. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf config.security.lockKernelModules { | 
					
						
							| 
									
										
										
										
											2017-09-22 23:45:04 +02:00
										 |  |  |     boot.kernelModules = concatMap (x: | 
					
						
							|  |  |  |       if x.device != null | 
					
						
							|  |  |  |         then | 
					
						
							|  |  |  |           if x.fsType == "vfat" | 
					
						
							|  |  |  |             then [ "vfat" "nls-cp437" "nls-iso8859-1" ] | 
					
						
							|  |  |  |             else [ x.fsType ] | 
					
						
							|  |  |  |         else []) config.system.build.fileSystems; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  |     systemd.services.disable-kernel-module-loading = rec { | 
					
						
							|  |  |  |       description = "Disable kernel module loading"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       wantedBy = [ config.systemd.defaultUnit ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 01:10:29 +02:00
										 |  |  |       after = [ "systemd-udev-settle.service" "firewall.service" "systemd-modules-load.service" ] ++ wantedBy; | 
					
						
							| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-30 14:42:15 +02:00
										 |  |  |       unitConfig.ConditionPathIsReadWrite = "/proc/sys/kernel"; | 
					
						
							| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         Type = "oneshot"; | 
					
						
							|  |  |  |         RemainAfterExit = true; | 
					
						
							| 
									
										
										
										
											2017-09-10 01:10:29 +02:00
										 |  |  |         ExecStart = "/bin/sh -c 'echo -n 1 >/proc/sys/kernel/modules_disabled'"; | 
					
						
							| 
									
										
										
										
											2017-04-06 16:12:21 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |