| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  | let | 
					
						
							|  |  |  |   cfg = config.security.rngd; | 
					
						
							|  |  |  | in | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  | { | 
					
						
							|  |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |     security.rngd = { | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2020-08-23 15:12:13 +02:00
										 |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2020-08-23 15:12:13 +02:00
										 |  |  |           Whether to enable the rng daemon.  Devices that the kernel recognises | 
					
						
							|  |  |  |           as entropy sources are handled automatically by krngd. | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       debug = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = "Whether to enable debug output (-d)."; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |   config = mkIf cfg.enable { | 
					
						
							| 
									
										
										
										
											2013-01-16 12:33:18 +01:00
										 |  |  |     systemd.services.rngd = { | 
					
						
							| 
									
										
										
										
											2012-11-26 08:45:23 -05:00
										 |  |  |       bindsTo = [ "dev-random.device" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       after = [ "dev-random.device" ]; | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 18:53:52 -05:00
										 |  |  |       # Clean shutdown without DefaultDependencies | 
					
						
							|  |  |  |       conflicts = [ "shutdown.target" ]; | 
					
						
							|  |  |  |       before = [ | 
					
						
							|  |  |  |         "sysinit.target" | 
					
						
							|  |  |  |         "shutdown.target" | 
					
						
							|  |  |  |       ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  |       description = "Hardware RNG Entropy Gatherer Daemon"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-18 00:30:11 +02:00
										 |  |  |       # rngd may have to start early to avoid entropy starvation during boot with encrypted swap | 
					
						
							|  |  |  |       unitConfig.DefaultDependencies = false; | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         ExecStart = "${pkgs.rng-tools}/sbin/rngd -f" | 
					
						
							|  |  |  |           + optionalString cfg.debug " -d"; | 
					
						
							| 
									
										
										
										
											2019-10-18 00:30:11 +02:00
										 |  |  |         # PrivateTmp would introduce a circular dependency if /tmp is on tmpfs and swap is encrypted, | 
					
						
							|  |  |  |         # thus depending on rngd before swap, while swap depends on rngd to avoid entropy starvation. | 
					
						
							| 
									
										
										
										
											2019-05-07 22:53:09 -05:00
										 |  |  |         NoNewPrivileges = true; | 
					
						
							|  |  |  |         PrivateNetwork = true; | 
					
						
							|  |  |  |         ProtectSystem = "full"; | 
					
						
							|  |  |  |         ProtectHome = true; | 
					
						
							| 
									
										
										
										
											2019-05-06 01:43:35 -05:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2012-11-22 02:07:25 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |