From f80047be52b6dcdbcb8ebebae67e5abe572443ca Mon Sep 17 00:00:00 2001
From: Jan Bulthuis <git@bulthuis.dev>
Date: Thu, 18 Jul 2024 07:09:56 +0200
Subject: [PATCH] Fixed system wide configuration system for user specific
 modules

---
 modules/users/default.nix                           |  4 ++--
 .../users/modules/desktop/lock-screen/waylock.nix   |  8 --------
 modules/users/system.nix                            | 13 -------------
 modules/users/systemwide/waylock.nix                | 10 ++++++++++
 4 files changed, 12 insertions(+), 23 deletions(-)
 delete mode 100644 modules/users/system.nix
 create mode 100644 modules/users/systemwide/waylock.nix

diff --git a/modules/users/default.nix b/modules/users/default.nix
index ef07303..308304c 100644
--- a/modules/users/default.nix
+++ b/modules/users/default.nix
@@ -41,8 +41,8 @@ in {
     # Import home manager
     <home-manager/nixos>
 
-    # Import system configuration setup
-    # ./system.nix
+    # Import system wide configuration required for user modules
+    ./systemwide/waylock.nix
   ];
 
   options = {
diff --git a/modules/users/modules/desktop/lock-screen/waylock.nix b/modules/users/modules/desktop/lock-screen/waylock.nix
index 2f0f20b..3539fb7 100644
--- a/modules/users/modules/desktop/lock-screen/waylock.nix
+++ b/modules/users/modules/desktop/lock-screen/waylock.nix
@@ -6,17 +6,9 @@ let
 in {
   options.modules.waylock = {
     enable = mkEnableOption "waylock";
-    system = mkOption {
-      type = types.attrsOf types.anything;
-      description = "System wide configuration to apply if module is enabled";
-    };
   };
 
   config = {
-    modules.waylock.system = mkForce {
-      security.pam.services.waylock = {};
-    };
-
     home.packages = mkIf cfg.enable (with pkgs; [
       waylock
     ]);
diff --git a/modules/users/system.nix b/modules/users/system.nix
deleted file mode 100644
index 9708505..0000000
--- a/modules/users/system.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ lib, config, pkgs, ... }:
-
-with lib;
-let
-  users = config.home-manager.users;
-  allModules = flatten (map (user: (attrValues user.modules)) (attrValues users));
-  modules = filter (module: module?system && module?enable) allModules;
-  configs = map (module: module.system) modules;
-  combined = (foldl (a: b: recursiveUpdate a b) {} configs);
-in {
-  # Add the combined systemwide config required by the user modules.
-  config = combined;
-}
\ No newline at end of file
diff --git a/modules/users/systemwide/waylock.nix b/modules/users/systemwide/waylock.nix
new file mode 100644
index 0000000..c683175
--- /dev/null
+++ b/modules/users/systemwide/waylock.nix
@@ -0,0 +1,10 @@
+{ lib, config, pkgs, ... }:
+
+with lib;
+let
+  enabled = any (user: user.modules.waylock.enable) (attrValues config.home-manager.users);
+in {
+  config = mkIf enabled {
+    security.pam.services.waylock = {};
+  };
+}
\ No newline at end of file