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 "auto-cpufreq daemon";
13
14 settings = mkOption {
15 description = ''
16 Configuration for `auto-cpufreq`.
17
18 The available options can be found in [the example configuration file](https://github.com/AdnanHodzic/auto-cpufreq/blob/v${pkgs.auto-cpufreq.version}/auto-cpufreq.conf-example).
19 '';
20
21 default = {};
22 type = types.submodule { freeformType = format.type; };
23 };
24 };
25 };
26
27 config = mkIf cfg.enable {
28 environment.systemPackages = [ pkgs.auto-cpufreq ];
29
30 systemd = {
31 packages = [ pkgs.auto-cpufreq ];
32 services.auto-cpufreq = {
33 # Workaround for https://github.com/NixOS/nixpkgs/issues/81138
34 wantedBy = [ "multi-user.target" ];
35 path = with pkgs; [ bash coreutils ];
36
37 serviceConfig.WorkingDirectory = "";
38 serviceConfig.ExecStart = [
39 ""
40 "${lib.getExe pkgs.auto-cpufreq} --daemon --config ${cfgFile}"
41 ];
42 };
43 };
44 };
45
46 # uses attributes of the linked package
47 meta = {
48 buildDocsInSandbox = false;
49 maintainers = with lib.maintainers; [ nicoo ];
50 };
51}