summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/solaar.nix
blob: 320e8559b8db4d57e8987b3ba4116a805c3dcc21 (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
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
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.programs.solaar;
  inherit (lib)
    mkEnableOption
    mkIf
    mkOption
    types
    maintainers
    mkPackageOption
    ;
in
{
  options.programs.solaar = {
    enable = mkEnableOption "Solaar, the open source driver for Logitech devices.";

    package = mkPackageOption pkgs "solaar" { };

    userService = {
      enable = mkEnableOption "Enable the solaar systemd service for each user.";

      window = mkOption {
        type = types.enum [
          "show"
          "hide"
          "only"
        ];
        default = "hide";
        description = ''
          Start with window showing / hidden / only (no tray icon).
        '';
      };

      batteryIcons = mkOption {
        type = types.enum [
          "regular"
          "symbolic"
          "solaar"
        ];
        default = "regular";
        description = ''
          Prefer regular battery / symbolic battery / solaar icons.
        '';
      };

      extraArgs = mkOption {
        type = types.listOf types.str;
        default = [ ];
        example = [ "--restart-on-wake-up" ];
        description = ''
          Extra arguments to pass to Solaar.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    hardware.logitech.wireless.enable = lib.mkDefault true;
    environment.systemPackages = [ cfg.package ];

    systemd.user.services.solaar = mkIf cfg.userService.enable {
      description = "Solaar, the open source driver for Logitech devices";
      wantedBy = [ "graphical-session.target" ];
      partOf = [ "graphical-session.target" ];
      after = [ "dbus.service" ];
      serviceConfig = {
        Type = "simple";
        ExecStart = lib.escapeShellArgs (
          [
            (lib.getExe cfg.package)
            "--window"
            cfg.userService.window
            "--battery-icons"
            cfg.userService.batteryIcons
          ]
          ++ cfg.userService.extraArgs
        );
        Restart = "on-failure";
        RestartSec = "5";
      };
    };
  };

  meta = {
    maintainers = [ maintainers.Svenum ];
  };
}