auto-cpufreq/nix/module.nix

43 lines
1.3 KiB
Nix

inputs: { config, lib, pkgs, options, ... }:
with lib; let
cfg = config.programs.auto-cpufreq;
system = "x86_64-linux";
defaultPackage = inputs.self.packages.${system}.default;
cfgFilename = "auto-cpufreq.conf";
cfgFile = format.generate cfgFilename cfg.settings;
format = pkgs.formats.ini {};
in {
options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
settings = mkOption {
description = lib.mdDoc ''
Configuration for `auto-cpufreq`.
See its [example configuration file] for supported settings.
[example configuration file]: https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto-cpufreq.conf-example
'';
default = {};
type = types.submodule { freeformType = format.type; };
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ defaultPackage ];
services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = {
overrideStrategy = "asDropin";
serviceConfig.ExecStart = lib.mkForce [
""
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}"
];
};
};
}