about summary refs log tree commit diff
path: root/modules/solaar.nix
blob: 17a04de31bfbeb4c0edd7c1b72969480338b619e (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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.solaar;
in
{
  options.nixfiles.modules.solaar = {
    enable = mkEnableOption "Solaar";
  };

  config = mkIf cfg.enable {
    hm = {
      home.packages = with pkgs; [ solaar ];

      systemd.user.services.solaar = {
        Unit = {
          Description = "Device manager for Logitech devices";
          After = [ "graphical-session-pre.target" ];
          PartOf = [ "graphical-session.target" ];
        };
        Service = {
          # The dirtiest hack I've ever implemented... I should be ashamed of
          # it. Regardless, that shit still doesn't work because each reconnect,
          # /dev/hidraw* is recreated and has default permissions which breaks
          # Solaar. Fuck this shit.
          ExecStartPre = getExe (
            pkgs.writeShellApplication {
              name = "solaar-pre";
              text = ''
                for i in /dev/hidraw*; do
                  if [ -c "$i" ]; then
                    sudo chown root:input "$i"
                    sudo chmod 0660 "$i"
                  fi
                done
              '';
            }
          );
          ExecStart = "${getExe pkgs.solaar "solaar"} --window=hide";
        };
        Install.WantedBy = [ "graphical-session.target" ];
      };
    };

    boot.kernelModules = [
      "hid_logitech_dj"
      "hid_logitech_hidpp"
    ];

    hardware.uinput.enable = true;

    my.extraGroups = [
      "uinput"
      "input"
    ];
  };
}

Consider giving Nix/NixOS a try! <3