auto-cpufreq/nix/module.nix

55 lines
1.4 KiB
Nix
Raw Normal View History

2023-10-13 16:31:59 +02:00
inputs: {
config,
lib,
pkgs,
...
}:
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
inherit (lib) types;
2024-06-04 15:11:33 +02:00
inherit (lib.modules) mkIf mkForce;
inherit (lib.options) mkOption mkEnableOption;
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 = ''
2023-10-13 16:31:59 +02:00
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 {
2024-05-25 17:02:57 +02:00
environment.systemPackages = [ defaultPackage ];
2023-10-13 16:31:59 +02:00
2024-05-25 17:02:57 +02:00
systemd = {
packages = [ defaultPackage ];
services.auto-cpufreq = {
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ bash coreutils ];
overrideStrategy = "asDropin";
serviceConfig.WorkingDirectory = "";
serviceConfig.ExecStart = mkForce [
""
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}"
];
};
2023-09-16 11:36:01 +02:00
};
2023-10-13 16:31:59 +02:00
};
}