about summary refs log tree commit diff
path: root/nixos/modules/services/hardware/asusd.nix
blob: fba9b059bbbb7257dd68d43e83958a1b34bafb9a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{ config, lib, pkgs, ... }:

let
  cfg = config.services.asusd;
  json = pkgs.formats.json { };
  toml = pkgs.formats.toml { };
in
{
  options = {
    services.asusd = {
      enable = lib.mkEnableOption (lib.mdDoc "the asusd service for ASUS ROG laptops");

      enableUserService = lib.mkOption {
        type = lib.types.bool;
        default = false;
        description = lib.mdDoc ''
          Activate the asusd-user service.
        '';
      };

      animeConfig = lib.mkOption {
        type = json.type;
        default = { };
        description = lib.mdDoc ''
          The content of /etc/asusd/anime.conf.
          See https://asus-linux.org/asusctl/#anime-control.
        '';
      };

      asusdConfig = lib.mkOption {
        type = json.type;
        default = { };
        description = lib.mdDoc ''
          The content of /etc/asusd/asusd.conf.
          See https://asus-linux.org/asusctl/.
        '';
      };

      auraConfig = lib.mkOption {
        type = json.type;
        default = { };
        description = lib.mdDoc ''
          The content of /etc/asusd/aura.conf.
          See https://asus-linux.org/asusctl/#led-keyboard-control.
        '';
      };

      profileConfig = lib.mkOption {
        type = lib.types.nullOr lib.types.str;
        default = "";
        description = lib.mdDoc ''
          The content of /etc/asusd/profile.conf.
          See https://asus-linux.org/asusctl/#profiles.
        '';
      };

      ledModesConfig = lib.mkOption {
        type = lib.types.nullOr toml.type;
        default = null;
        description = lib.mdDoc ''
          The content of /etc/asusd/asusd-ledmodes.toml. Leave `null` to use default settings.
          See https://asus-linux.org/asusctl/#led-keyboard-control.
        '';
      };

      userLedModesConfig = lib.mkOption {
        type = lib.types.nullOr toml.type;
        default = null;
        description = lib.mdDoc ''
          The content of /etc/asusd/asusd-user-ledmodes.toml.
          See https://asus-linux.org/asusctl/#led-keyboard-control.
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ pkgs.asusctl ];

    environment.etc =
      let
        maybeConfig = name: cfg: lib.mkIf (cfg != { }) {
          source = json.generate name cfg;
          mode = "0644";
        };
      in
      {
        "asusd/anime.conf" = maybeConfig "anime.conf" cfg.animeConfig;
        "asusd/asusd.conf" = maybeConfig "asusd.conf" cfg.asusdConfig;
        "asusd/aura.conf" = maybeConfig "aura.conf" cfg.auraConfig;
        "asusd/profile.conf" = lib.mkIf (cfg.profileConfig != null) {
          source = pkgs.writeText "profile.conf" cfg.profileConfig;
          mode = "0644";
        };
        "asusd/asusd-ledmodes.toml" = {
          source =
            if cfg.ledModesConfig == null
            then "${pkgs.asusctl}/share/asusd/data/asusd-ledmodes.toml"
            else toml.generate "asusd-ledmodes.toml" cfg.ledModesConfig;
          mode = "0644";
        };
      };

    services.dbus.enable = true;
    systemd.packages = [ pkgs.asusctl ];
    services.dbus.packages = [ pkgs.asusctl ];
    services.udev.packages = [ pkgs.asusctl ];
    services.supergfxd.enable = lib.mkDefault true;

    systemd.user.services.asusd-user.enable = cfg.enableUserService;
  };

  meta.maintainers = pkgs.asusctl.meta.maintainers;
}