1{ config, lib, pkgs, ... }:
2with lib;
3let
4 cfg = config.services.auto-cpufreq;
5 cfgFilename = "auto-cpufreq.conf";
6 cfgFile = format.generate cfgFilename cfg.settings;
7
8 format = pkgs.formats.ini {};
9in {
10 options = {
11 services.auto-cpufreq = {
12 enable = mkEnableOption (lib.mdDoc "auto-cpufreq daemon");
13
14 settings = mkOption {
15 description = lib.mdDoc ''
16 Configuration for `auto-cpufreq`.
17
18 See its [example configuration file] for supported settings.
19 [example configuration file]: https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto-cpufreq.conf-example
20 '';
21
22 default = {};
23 type = types.submodule { freeformType = format.type; };
24 };
25 };
26 };
27
28 config = mkIf cfg.enable {
29 environment.systemPackages = [ pkgs.auto-cpufreq ];
30
31 systemd = {
32 packages = [ pkgs.auto-cpufreq ];
33 services.auto-cpufreq = {
34 # Workaround for https://github.com/NixOS/nixpkgs/issues/81138
35 wantedBy = [ "multi-user.target" ];
36 path = with pkgs; [ bash coreutils ];
37
38 serviceConfig.ExecStart = [
39 ""
40 "${lib.getExe pkgs.auto-cpufreq} --daemon --config ${cfgFile}"
41 ];
42 };
43 };
44 };
45}