about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2015-01-24 07:10:48 +0100
committerDomen Kožar <domen@dev.si>2015-01-24 07:10:48 +0100
commitfde45d217e6f8e74d23576a0181f9b5831d02dfc (patch)
treef110289e9df35fb66e81901f40216ff0906068b4 /nixos
parentad026dab9808eb6917a78703ebb20475bd122a7d (diff)
parentb7b3a0972d80b6e5d4c8430972c72ea648224b1c (diff)
downloadnixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar.gz
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar.bz2
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar.lz
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar.xz
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.tar.zst
nixlib-fde45d217e6f8e74d23576a0181f9b5831d02dfc.zip
Merge pull request #5531 from abbradar/tlp
tlp: add package
Diffstat (limited to 'nixos')
-rwxr-xr-xnixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/hardware/tlp.nix93
2 files changed, 94 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 2a2a7b004163..4e0d3b77fe30 100755
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -149,6 +149,7 @@
   ./services/hardware/pommed.nix
   ./services/hardware/sane.nix
   ./services/hardware/tcsd.nix
+  ./services/hardware/tlp.nix
   ./services/hardware/thinkfan.nix
   ./services/hardware/udev.nix
   ./services/hardware/udisks2.nix
diff --git a/nixos/modules/services/hardware/tlp.nix b/nixos/modules/services/hardware/tlp.nix
new file mode 100644
index 000000000000..f221c82e2eda
--- /dev/null
+++ b/nixos/modules/services/hardware/tlp.nix
@@ -0,0 +1,93 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+cfg = config.services.tlp;
+
+tlp = pkgs.tlp.override { kmod = config.system.sbin.modprobe; };
+
+confFile = pkgs.writeText "tlp" (builtins.readFile "${tlp}/etc/default/tlp" + cfg.extraConfig);
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.tlp = {
+
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = "Whether to enable the TLP daemon.";
+      };
+
+      extraConfig = mkOption {
+        type = types.str;
+        default = "";
+        description = "Additional configuration variables for TLP";
+      };
+
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf cfg.enable {
+
+    systemd.services = {
+      tlp = {
+        description = "TLP system startup/shutdown";
+
+        after = [ "multi-user.target" ];
+        wantedBy = [ "multi-user.target" ];
+        before = [ "shutdown.target" ];
+
+        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";
+                       }
+                      ] ++ optional tlp.enableRDW {
+                        source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm";
+                        target = "NetworkManager/dispatcher.d/99tlp-rdw-nm";
+                      };
+
+    environment.systemPackages = [ tlp ];
+
+  };
+
+}