Last active
February 26, 2020 03:15
-
-
Save lovesegfault/2f0a2517d7f71c061437cf91123cd37c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
with lib; | |
let | |
cfg = config.services.tlp; | |
enableRDW = config.networking.networkmanager.enable; | |
tlp = pkgs.tlp.override { | |
inherit enableRDW; | |
}; | |
mkConfigOption = opt: val: "${opt}=${val}\n"; | |
mkConfigString = opt: val: mkConfigOption opt "\"${val}\""; | |
mkConfigBool = opt: val: if val == false then mkConfigOption opt 0 else mkConfigOption opt 1; | |
mkConfigList = opt: val: mkConfigOption opt (concatStringsSep " " val); | |
in | |
{ | |
###### interface | |
options = { | |
services.tlp = { | |
enable = mkOption { | |
type = types.bool; | |
default = false; | |
description = "Whether to enable the TLP power management daemon."; | |
}; | |
extraConfig = mkOption { | |
type = types.lines; | |
default = ""; | |
description = "Additional configuration variables for TLP"; | |
}; | |
}; | |
}; | |
###### implementation | |
config = mkIf cfg.enable { | |
boot.kernelModules = [ "msr" ]; | |
environment.etc = { | |
"tlp.conf".source = extraConfig; | |
} // optionalAttrs enableRDW { | |
"NetworkManager/dispatcher.d/99tlp-rdw-nm".source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm"; | |
}; | |
environment.systemPackages = [ tlp ]; | |
# FIXME: When the config is parametrized we need to move these into a | |
# conditional on the relevant options being enabled. | |
powerManagement = { | |
scsiLinkPolicy = null; | |
cpuFreqGovernor = null; | |
cpufreq.max = null; | |
cpufreq.min = null; | |
}; | |
services.udev.packages = [ tlp ]; | |
systemd = { | |
packages = [ tlp ]; | |
sockets.systemd-rfkill.enable = false; | |
services.systemd-rfkill.enable = false; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment