about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/hardware/auto-epp.nix
blob: 84b6a337d28a26c5157f4d35f7c1a50424843f0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ config, lib, pkgs, ... }:

let
  cfg = config.services.auto-epp;
  format = pkgs.formats.ini {};

  inherit (lib) mkOption types;
in {
  options = {
    services.auto-epp = {
      enable = lib.mkEnableOption (lib.mdDoc "auto-epp for amd active pstate");

      package = lib.mkPackageOptionMD pkgs "auto-epp" {};

      settings = mkOption {
        type = types.submodule {
          freeformType = format.type;
          options = {
            Settings = {
              epp_state_for_AC = mkOption {
                type = types.str;
                default = "balance_performance";
                description = lib.mdDoc ''
                  energy_performance_preference when on plugged in

                  ::: {.note}
                  See available epp states by running:
                  {command}`cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences`
                  :::
                '';
              };

              epp_state_for_BAT = mkOption {
                type = types.str;
                default = "power";
                description = lib.mdDoc ''
                  `energy_performance_preference` when on battery

                  ::: {.note}
                  See available epp states by running:
                  {command}`cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences`
                  :::
                '';
              };
            };
          };
        };
        default = {};
        description = lib.mdDoc ''
          Settings for the auto-epp application.
          See upstream example: <https://github.com/jothi-prasath/auto-epp/blob/master/sample-auto-epp.conf>
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {

    boot.kernelParams = [
      "amd_pstate=active"
    ];

    environment.etc."auto-epp.conf".source = format.generate "auto-epp.conf" cfg.settings;
    systemd.packages = [ cfg.package ];

    systemd.services.auto-epp = {
      after = [ "multi-user.target" ];
      wantedBy  = [ "multi-user.target" ];
      description = "auto-epp - Automatic EPP Changer for amd-pstate-epp";
      serviceConfig = {
        Type = "simple";
        User = "root";
        ExecStart = lib.getExe cfg.package;
        Restart = "on-failure";
      };
    };
  };

  meta.maintainers = with lib.maintainers; [ lamarios ];
}