at 16.09-beta 2.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7cfg = config.services.tlp; 8 9enableRDW = config.networking.networkmanager.enable; 10 11tlp = pkgs.tlp.override { 12 inherit enableRDW; 13}; 14 15# XXX: We can't use writeTextFile + readFile here because it triggers 16# TLP build to get the .drv (even on --dry-run). 17confFile = pkgs.runCommand "tlp" 18 { config = cfg.extraConfig; 19 passAsFile = [ "config" ]; 20 } 21 '' 22 cat ${tlp}/etc/default/tlp > $out 23 cat $configPath >> $out 24 ''; 25 26in 27 28{ 29 30 ###### interface 31 32 options = { 33 34 services.tlp = { 35 36 enable = mkOption { 37 type = types.bool; 38 default = false; 39 description = "Whether to enable the TLP daemon."; 40 }; 41 42 extraConfig = mkOption { 43 type = types.str; 44 default = ""; 45 description = "Additional configuration variables for TLP"; 46 }; 47 48 }; 49 50 }; 51 52 53 ###### implementation 54 55 config = mkIf cfg.enable { 56 57 powerManagement.scsiLinkPolicy = null; 58 powerManagement.cpuFreqGovernor = null; 59 60 systemd.services = { 61 tlp = { 62 description = "TLP system startup/shutdown"; 63 64 after = [ "multi-user.target" ]; 65 wantedBy = [ "multi-user.target" ]; 66 before = [ "shutdown.target" ]; 67 restartTriggers = [ confFile ]; 68 69 serviceConfig = { 70 Type = "oneshot"; 71 RemainAfterExit = true; 72 ExecStart = "${tlp}/bin/tlp init start"; 73 ExecStop = "${tlp}/bin/tlp init stop"; 74 }; 75 }; 76 77 tlp-sleep = { 78 description = "TLP suspend/resume"; 79 80 wantedBy = [ "sleep.target" ]; 81 before = [ "sleep.target" ]; 82 83 unitConfig = { 84 StopWhenUnneeded = true; 85 }; 86 87 serviceConfig = { 88 Type = "oneshot"; 89 RemainAfterExit = true; 90 ExecStart = "${tlp}/bin/tlp suspend"; 91 ExecStop = "${tlp}/bin/tlp resume"; 92 }; 93 }; 94 }; 95 96 services.udev.packages = [ tlp ]; 97 98 environment.etc = [{ source = confFile; 99 target = "default/tlp"; 100 } 101 ] ++ optional enableRDW { 102 source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm"; 103 target = "NetworkManager/dispatcher.d/99tlp-rdw-nm"; 104 }; 105 106 environment.systemPackages = [ tlp ]; 107 108 boot.kernelModules = [ "msr" ]; 109 110 }; 111 112}