From 0c30936230899379a48ab8f4a65814bbda0e2640 Mon Sep 17 00:00:00 2001
From: Myned <dev@bjork.tech>
Date: Wed, 26 Mar 2025 02:52:11 -0500
Subject: [PATCH] kdeconnect: enable and work around env in gamescope session

---
 options/custom/services/default.nix    |  2 +-
 options/custom/services/kdeconnect.nix | 30 +++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/options/custom/services/default.nix b/options/custom/services/default.nix
index dc29e54..390e599 100644
--- a/options/custom/services/default.nix
+++ b/options/custom/services/default.nix
@@ -17,7 +17,7 @@ with lib; {
       dbus.enable = true;
       flatpak.enable = true;
       fwupd.enable = true;
-      #// kdeconnect.enable = true;
+      kdeconnect.enable = true;
       libinput.enable = true;
       logind.enable = true;
       openrazer.enable = true;
diff --git a/options/custom/services/kdeconnect.nix b/options/custom/services/kdeconnect.nix
index d1cf951..cf2b24c 100644
--- a/options/custom/services/kdeconnect.nix
+++ b/options/custom/services/kdeconnect.nix
@@ -1,15 +1,39 @@
 {
   config,
   lib,
+  pkgs,
   ...
 }:
 with lib; let
   cfg = config.custom.services.kdeconnect;
 in {
-  options.custom.services.kdeconnect.enable = mkOption {default = false;};
+  options.custom.services.kdeconnect = {
+    enable = mkOption {default = false;};
+    display = mkOption {default = null;};
+    package = mkOption {default = mkForce pkgs.kdePackages.kdeconnect-kde;};
+  };
 
-  config.home-manager.users.${config.custom.username} = mkIf cfg.enable {
+  config = mkIf cfg.enable {
     # https://github.com/KDE/kdeconnect-kde
-    services.kdeconnect.enable = true;
+    programs.kdeconnect = {
+      enable = true;
+      package = cfg.package;
+    };
+
+    home-manager.sharedModules = [
+      {
+        services.kdeconnect = {
+          enable = true;
+          package = cfg.package;
+        };
+
+        # HACK: Manually set DISPLAY variable if specified
+        systemd.user.services.kdeconnect = mkIf (!isNull cfg.display) {
+          Service = {
+            Environment = ["DISPLAY=:${toString cfg.display}"];
+          };
+        };
+      }
+    ];
   };
 }