zaphyra's git: tgcNUR

fork of https://git.transgirl.cafe/zaphoid/tgc-nix-user-repository

commit 6a0fdd23c4ba1ed7c35d33ff22079d889dbc099c
parent 76b9f59feb8c7d0b2b95179e9135e9e77218634d
Author: Katja Ramona Sophie Kwast (zaphyra) <git@zaphyra.eu>
Date: Fri, 22 Aug 2025 17:36:22 +0200

homeManagerModules,nixosModules: add `default.nix`
4 files changed, 90 insertions(+), 43 deletions(-)
M
flake.nix
|
23
+++--------------------
A
homeManagerModules/default.nix
|
14
++++++++++++++
M
lib/collectModules.nix
|
82
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
A
nixosModules/default.nix
|
14
++++++++++++++
diff --git a/flake.nix b/flake.nix
@@ -15,22 +15,7 @@
     inputs:
     (
       let
-        nixpkgsLib = inputs.nixpkgs.lib;
-
-        maintainersAttrset = import ./maintainers.nix;
-
-        modulesScope = {
-          tgcMaintainers = maintainersAttrset;
-          tgcFlake = inputs.self;
-        };
-        homeManagerModules = lib.collectModules {
-          path = ./homeManagerModules;
-          scope = modulesScope;
-        };
-        nixosModules = lib.collectModules {
-          path = ./nixosModules;
-          scope = modulesScope;
-        };
+        lib = import ./lib inputs.nixpkgs.lib inputs;
         modulesTemplate =
           modules:
           modules

@@ -40,8 +25,6 @@
             };
           };
 
-        lib = import ./lib nixpkgsLib inputs;
-
       in
       {
 

@@ -68,8 +51,8 @@
           default = inputs.self.overlays.packages;
         };
 
-        homeManagerModules = modulesTemplate homeManagerModules;
-        nixosModules = (modulesTemplate nixosModules) // {
+        homeManagerModules = modulesTemplate (import ./homeManagerModules inputs.self);
+        nixosModules = (modulesTemplate (import ./nixosModules inputs.self)) // {
           packages = {
             nixpkgs.overlays = [ inputs.self.overlays.default ];
           };
diff --git a/homeManagerModules/default.nix b/homeManagerModules/default.nix
@@ -0,0 +1,14 @@
+tgcFlake:
+(
+  let
+    collectModules = (import ../lib/collectModules.nix { }).collectModules;
+    tgcMaintainers = import ../maintainers.nix;
+  in
+  collectModules {
+    path = ./.;
+    fileName = "default.nix";
+    scope = {
+      inherit tgcMaintainers tgcFlake;
+    };
+  }
+)
diff --git a/lib/collectModules.nix b/lib/collectModules.nix
@@ -1,4 +1,4 @@
-{ lib, self, ... }:
+{ ... }:
 
 {
 

@@ -10,30 +10,66 @@
     }:
     (
       let
-        files = lib.pipe (lib.fileset.fileFilter (file: file.name == fileName) path) [
-          lib.fileset.toList
-          (builtins.map builtins.toString)
-        ];
-      in
-      lib.pipe files [
-        (builtins.map (
-          elem:
+        #some helpers (mostly from nixpkgs or at least derived from that)
+        sublist =
+          start: count: list:
           let
-            pathList = (
-              lib.drop (lib.pipe path [
-                (lib.splitString "/")
-                (lib.length)
-              ]) (lib.splitString "/" elem)
-            );
-            name = lib.pipe pathList [
-              (lib.dropEnd 1)
-              (builtins.concatStringsSep "-")
-              self.toCamelCase
-            ];
-            filePath = path + "/${lib.concatStringsSep "/" pathList}";
+            len = builtins.length list;
           in
-          lib.nameValuePair name (import filePath scope)
-        ))
+          builtins.genList (n: builtins.elemAt list (n + start)) (
+            if start >= len then
+              0
+            else if start + count > len then
+              len - start
+            else
+              count
+          );
+        pipe = builtins.foldl' (x: f: f x);
+        flatten = x: if builtins.isList x then builtins.concatMap (y: flatten y) x else [ x ];
+        drop = count: list: sublist count (builtins.length list) list;
+        splitPath = path: builtins.filter builtins.isString (builtins.split "/" (builtins.toString path));
+
+        #actual logic starts here
+        fileNameLength = builtins.stringLength fileName;
+        basePathLength = builtins.length (splitPath ./.);
+
+        collectFiles =
+          path:
+          pipe (builtins.readDir path) [
+            (builtins.mapAttrs (
+              name: value:
+              if value == "directory" then (collectFiles (path + "/${name}")) else (path + "/${name}")
+            ))
+            builtins.attrValues
+            flatten
+            (builtins.filter (
+              elem:
+              let
+                pathLength = builtins.length (splitPath elem);
+              in
+              (
+                (
+                  let
+                    strLength = builtins.stringLength elem;
+                  in
+                  builtins.substring (strLength - fileNameLength) strLength elem
+                ) == fileName
+              )
+              && (pathLength - 1) != basePathLength
+            ))
+          ];
+
+      in
+      pipe (collectFiles path) [
+        (builtins.map (filePath: {
+          name = (
+            let
+              pathParts = drop basePathLength (splitPath filePath);
+            in
+            builtins.concatStringsSep "-" (sublist 0 ((builtins.length pathParts) - 1) pathParts)
+          );
+          value = import filePath scope;
+        }))
         builtins.listToAttrs
       ]
     );
diff --git a/nixosModules/default.nix b/nixosModules/default.nix
@@ -0,0 +1,14 @@
+tgcFlake:
+(
+  let
+    collectModules = (import ../lib/collectModules.nix { }).collectModules;
+    tgcMaintainers = import ../maintainers.nix;
+  in
+  collectModules {
+    path = ./.;
+    fileName = "default.nix";
+    scope = {
+      inherit tgcMaintainers tgcFlake;
+    };
+  }
+)