From 3b2d16743e3ce64b596c09ab9c6e4a88bb81f0a6 Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 26 Sep 2026 23:49:03 -0400 Subject: [PATCH] refactor(dotfiles): share Nix file discovery --- src/dotfiles/default.nix | 2 +- src/dotfiles/guests.nix | 5 +---- src/dotfiles/registry.nix | 18 ++++++------------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/dotfiles/default.nix b/src/dotfiles/default.nix index 245364c..2a53e2a 100644 --- a/src/dotfiles/default.nix +++ b/src/dotfiles/default.nix @@ -17,7 +17,7 @@ let util = import ./util.nix { inherit lib; }; registry = import ./registry.nix { - inherit lib; + inherit lib util; hosts = self.nixosConfigurations; root = root + "/registry"; }; diff --git a/src/dotfiles/guests.nix b/src/dotfiles/guests.nix index ba4cad9..896ff97 100644 --- a/src/dotfiles/guests.nix +++ b/src/dotfiles/guests.nix @@ -276,10 +276,7 @@ let }; }; - names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles); - guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) ( - builtins.readDir root - ); + names = map (path: lib.removeSuffix ".nix" (builtins.baseNameOf path)) files; in { imports = files ++ map mkGuest names; diff --git a/src/dotfiles/registry.nix b/src/dotfiles/registry.nix index 8d6c2e0..6950765 100644 --- a/src/dotfiles/registry.nix +++ b/src/dotfiles/registry.nix @@ -2,20 +2,14 @@ hosts, lib, root, + util, }: let - definitions = - lib.mapAttrs' - ( - name: _type: - let - path = root + "/${name}"; - in - lib.nameValuePair (registryName name) (mkRegistry path) - ) - ( - lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root) - ); + definitions = lib.listToAttrs ( + map (path: lib.nameValuePair (registryName (builtins.baseNameOf path)) (mkRegistry path)) ( + util.collectNixFiles root + ) + ); registryName = fileName: lib.removeSuffix ".nix" fileName;