auto-cpufreq/nix/module.nix

46 lines
1.2 KiB
Nix
Raw Normal View History

2023-10-13 16:31:59 +02:00
inputs: {
config,
lib,
pkgs,
options,
...
}:
2023-09-16 11:36:01 +02:00
with lib; let
2023-10-13 16:31:59 +02:00
cfg = config.programs.auto-cpufreq;
2023-10-13 23:47:47 +02:00
inherit (pkgs.stdenv.hostPlatform) system;
2023-10-13 16:31:59 +02:00
defaultPackage = inputs.self.packages.${system}.default;
cfgFilename = "auto-cpufreq.conf";
cfgFile = format.generate cfgFilename cfg.settings;
2023-09-16 11:36:01 +02:00
2023-10-13 16:31:59 +02:00
format = pkgs.formats.ini {};
2023-09-16 11:36:01 +02:00
in {
2023-10-13 16:31:59 +02:00
options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
2023-09-16 11:36:01 +02:00
2023-10-13 16:31:59 +02:00
settings = mkOption {
description = mdDoc ''
Configuration for `auto-cpufreq`.
2023-09-16 11:36:01 +02:00
2023-10-13 16:31:59 +02:00
See its [example configuration file] for supported settings.
[example configuration file]: https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto-cpufreq.conf-example
'';
2023-09-16 11:36:01 +02:00
2023-10-13 16:31:59 +02:00
default = {};
type = types.submodule {freeformType = format.type;};
2023-09-16 11:36:01 +02:00
};
2023-10-13 16:31:59 +02:00
};
config = mkIf cfg.enable {
environment.systemPackages = [defaultPackage];
services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = {
overrideStrategy = "asDropin";
serviceConfig.ExecStart = mkForce [
""
2023-10-13 16:39:10 +02:00
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}"
2023-10-13 16:31:59 +02:00
];
2023-09-16 11:36:01 +02:00
};
2023-10-13 16:31:59 +02:00
};
}