summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/hardware/g810-led.nix
blob: 730620054dbdb16ef1ebe1c0014ec0aa60e44208 (plain)
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
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.services.g810-led;
in
{
  options = {
    services.g810-led = {
      enable = lib.mkEnableOption "g810-led, a Linux LED controller for some Logitech G Keyboards";
      earlySetup = lib.mkEnableOption "g810-led in early stage initrd";

      package = lib.mkPackageOption pkgs "g810-led" { };

      profile = lib.mkOption {
        type = lib.types.nullOr lib.types.lines;
        default = null;
        example = ''
          # G810-LED Profile (turn all keys on)

          # Set all keys on
          a ffffff

          # Commit changes
          c
        '';
        description = ''
          Keyboard profile to apply at boot time.

          The upstream repository provides [example configurations](https://github.com/MatMoul/g810-led/tree/master/sample_profiles).
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    environment.etc."g810-led/profile".text = lib.mkIf (cfg.profile != null) cfg.profile;

    boot.initrd = lib.mkIf (cfg.earlySetup && cfg.profile != null) {
      services.udev.packages = [ cfg.package ];
      services.udev.binPackages = [ cfg.package ];

      systemd.contents = {
        "/etc/g810-led/profile".text = cfg.profile;
      };
    };

    services.udev.packages = [ cfg.package ];
  };

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