Created
February 26, 2020 03:48
-
-
Save lovesegfault/66c8efceca5a11bd849fcf4bc6db8acb 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; | |
}; | |
mkTlpConfig = tlpConfig: generators.toKeyValue { | |
mkKeyValue = generators.mkKeyValueDefault { | |
mkValueString = val: | |
if isInt val then toString val | |
else if isString val then "\"${val}\"" | |
else if true == val then "1" | |
else if false == val then "0" | |
else if isList val then "\"" + (concatStringsSep " " val) + "\"" | |
else err "invalid value provided to mkTlpConfig:" (toString val); | |
} "="; | |
} tlpConfig; | |
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