From e66fe1db821232271521f853b72a62b0f7c4cf67 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Sat, 26 Apr 2025 18:55:04 -0400
Subject: [PATCH] feat(quickshell): add basic module for quickshell

---
 configurations/wim/default.nix          |  1 +
 modules/desktop/default.nix             |  8 +++++
 modules/desktop/environment/default.nix |  1 +
 modules/quickshell/default.nix          | 41 +++++++++++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 modules/quickshell/default.nix

diff --git a/configurations/wim/default.nix b/configurations/wim/default.nix
index 7211a389..3c3374cc 100644
--- a/configurations/wim/default.nix
+++ b/configurations/wim/default.nix
@@ -79,6 +79,7 @@
     user = mainUser;
 
     ags.enable = true;
+    quickshell.enable = true;
     mainMonitor = "eDP-1";
     isLaptop = true;
     isTouchscreen = true;
diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix
index e4290f87..000cca25 100644
--- a/modules/desktop/default.nix
+++ b/modules/desktop/default.nix
@@ -58,6 +58,14 @@ in {
       '';
     };
 
+    quickshell.enable = mkOption {
+      type = types.bool;
+      default = false;
+      description = ''
+        Whether we want to enable Quickshell for the DE shell.
+      '';
+    };
+
     mainMonitor = mkOption {
       type = types.str;
       description = ''
diff --git a/modules/desktop/environment/default.nix b/modules/desktop/environment/default.nix
index 50cec24e..02580475 100644
--- a/modules/desktop/environment/default.nix
+++ b/modules/desktop/environment/default.nix
@@ -21,6 +21,7 @@ self: {
 in {
   imports = [
     (import ../../ags self)
+    ../../quickshell
 
     ./modules/dconf.nix
     ./modules/printer.nix
diff --git a/modules/quickshell/default.nix b/modules/quickshell/default.nix
new file mode 100644
index 00000000..16ee01c6
--- /dev/null
+++ b/modules/quickshell/default.nix
@@ -0,0 +1,41 @@
+{
+  config,
+  lib,
+  pkgs,
+  ...
+}: let
+  inherit (lib) hasPrefix mkIf removePrefix;
+
+  # Configs
+  cfgDesktop = config.roles.desktop;
+  flakeDir = config.environment.variables.FLAKE;
+
+  qsConfigDir = "${removePrefix "/home/${cfgDesktop.user}/" flakeDir}/modules/quickshell/config";
+in {
+  config = mkIf cfgDesktop.quickshell.enable {
+    assertions = [
+      {
+        assertion = hasPrefix "/home/${cfgDesktop.user}/" flakeDir;
+        message = ''
+          Your $FLAKE environment variable needs to point to a directory in
+          the main users' home to use my quickshell module.
+        '';
+      }
+    ];
+
+    # Machine config
+    environment.systemPackages = [
+      (pkgs.writeShellApplication {
+        name = "quickshell";
+        runtimeInputs = [pkgs.quickshell];
+        text = ''
+          if [ "$#" == 0 ]; then
+              exec qs --path ~/${qsConfigDir}
+          else
+              exec qs "$@"
+          fi
+        '';
+      })
+    ];
+  };
+}