| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cfg = config.services.tlp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 17:24:08 +03:00
										 |  |  | enableRDW = config.networking.networkmanager.enable; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tlp = pkgs.tlp.override { | 
					
						
							|  |  |  |   inherit enableRDW; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-05 16:21:47 +03:00
										 |  |  | # XXX: We can't use writeTextFile + readFile here because it triggers | 
					
						
							|  |  |  | # TLP build to get the .drv (even on --dry-run). | 
					
						
							|  |  |  | confFile = pkgs.runCommand "tlp" | 
					
						
							|  |  |  |   { config = cfg.extraConfig; | 
					
						
							|  |  |  |     passAsFile = [ "config" ]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   ''
 | 
					
						
							|  |  |  |     cat ${tlp}/etc/default/tlp > $out | 
					
						
							|  |  |  |     cat $configPath >> $out | 
					
						
							|  |  |  |   '';
 | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.tlp = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = "Whether to enable the TLP daemon."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       extraConfig = mkOption { | 
					
						
							| 
									
										
										
										
											2016-10-23 19:33:41 +02:00
										 |  |  |         type = types.lines; | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  |         default = ""; | 
					
						
							|  |  |  |         description = "Additional configuration variables for TLP"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 20:22:05 +03:00
										 |  |  |     powerManagement.scsiLinkPolicy = null; | 
					
						
							|  |  |  |     powerManagement.cpuFreqGovernor = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 10:09:25 +02:00
										 |  |  |     systemd.sockets."systemd-rfkill".enable = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  |     systemd.services = { | 
					
						
							| 
									
										
										
										
											2017-04-11 02:08:53 +03:00
										 |  |  |       "systemd-rfkill@".enable = false; | 
					
						
							|  |  |  |       "systemd-rfkill".enable = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  |       tlp = { | 
					
						
							|  |  |  |         description = "TLP system startup/shutdown"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         after = [ "multi-user.target" ]; | 
					
						
							|  |  |  |         wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |         before = [ "shutdown.target" ]; | 
					
						
							| 
									
										
										
										
											2016-07-03 22:45:54 +03:00
										 |  |  |         restartTriggers = [ confFile ]; | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         serviceConfig = { | 
					
						
							|  |  |  |           Type = "oneshot"; | 
					
						
							|  |  |  |           RemainAfterExit = true; | 
					
						
							|  |  |  |           ExecStart = "${tlp}/bin/tlp init start"; | 
					
						
							|  |  |  |           ExecStop = "${tlp}/bin/tlp init stop"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       tlp-sleep = { | 
					
						
							|  |  |  |         description = "TLP suspend/resume"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         wantedBy = [ "sleep.target" ]; | 
					
						
							|  |  |  |         before = [ "sleep.target" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         unitConfig = { | 
					
						
							|  |  |  |           StopWhenUnneeded = true; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         serviceConfig = { | 
					
						
							|  |  |  |           Type = "oneshot"; | 
					
						
							|  |  |  |           RemainAfterExit = true; | 
					
						
							|  |  |  |           ExecStart = "${tlp}/bin/tlp suspend"; | 
					
						
							|  |  |  |           ExecStop = "${tlp}/bin/tlp resume"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.udev.packages = [ tlp ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     environment.etc = [{ source = confFile; | 
					
						
							|  |  |  |                          target = "default/tlp"; | 
					
						
							|  |  |  |                        } | 
					
						
							| 
									
										
										
										
											2015-11-09 17:24:08 +03:00
										 |  |  |                       ] ++ optional enableRDW { | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  |                         source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm"; | 
					
						
							|  |  |  |                         target = "NetworkManager/dispatcher.d/99tlp-rdw-nm"; | 
					
						
							|  |  |  |                       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     environment.systemPackages = [ tlp ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 17:24:08 +03:00
										 |  |  |     boot.kernelModules = [ "msr" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 18:12:11 +03:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |