about summary refs log tree commit diff
path: root/modules/nixfiles/solaar.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2022-09-10 15:49:40 +0300
committerAzat Bahawi <azat@bahawi.net>2022-09-10 15:49:40 +0300
commitdcb02e0ea80821d60185569fb88ec66bea3f3f08 (patch)
treea2ab8943f94ce8f1ae1359051c7e42551c80806e /modules/nixfiles/solaar.nix
parent2022-09-07 (diff)
2022-09-10
Diffstat (limited to 'modules/nixfiles/solaar.nix')
-rw-r--r--modules/nixfiles/solaar.nix51
1 files changed, 51 insertions, 0 deletions
diff --git a/modules/nixfiles/solaar.nix b/modules/nixfiles/solaar.nix
new file mode 100644
index 0000000..073beb0
--- /dev/null
+++ b/modules/nixfiles/solaar.nix
@@ -0,0 +1,51 @@
+{
+  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.
+          ExecStartPre = let
+            pkg = 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
+              '';
+            };
+          in "${pkg}/bin/solaar-pre";
+          ExecStart = "${pkgs.solaar}/bin/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