From e0a3123035b36f512f0729712327a850fa63ec0e Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 17 Mar 2024 06:17:19 -0500 Subject: [PATCH] split find-modules into it's own file --- lib/default.nix | 25 ++----------------------- lib/find-modules.nix | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 lib/find-modules.nix diff --git a/lib/default.nix b/lib/default.nix index cb30116..0d13ca5 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,10 +5,11 @@ inherit (inputs) nixpkgs; lib = nixpkgs.lib.extend (import ./extended.nix); - inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir filter listToAttrs; + inherit (builtins) mapAttrs readDir filter listToAttrs; inherit (lib) nixosSystem genAttrs isNixFile; inherit (lib.filesystem) listFilesRecursive; + inherit (import ./find-modules.nix {inherit lib;}) findModulesList; #supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; supportedSystems = ["x86_64-linux"]; in rec { @@ -39,29 +40,7 @@ in rec { specialArgs = {inherit inputs lib self;}; }; mapHosts = dir: mapAttrs (name: _: mkSystem name) (readDir dir); - findModules = _: listToAttrs (findModulesList ../modules); - # https://github.com/balsoft/nixos-config/blob/73cc2c3a8bb62a9c3980a16ae70b2e97af6e1abd/flake.nix#L109-L120 - findModulesList = dir: - concatLists (attrValues (mapAttrs - (name: type: - if type == "regular" - then [ - { - name = elemAt (match "(.*)\\.nix" name) 0; - value = dir + "/${name}"; - } - ] - else if - (readDir (dir + "/${name}")) - ? "default.nix" - then [ - { - inherit name; - value = dir + "/${name}"; - } - ] - else findModulesList (dir + "/${name}")) (readDir dir))); oizysFlake = _: { nixosModules = findModules {}; diff --git a/lib/find-modules.nix b/lib/find-modules.nix new file mode 100644 index 0000000..f6dbe89 --- /dev/null +++ b/lib/find-modules.nix @@ -0,0 +1,25 @@ +{...}: let + inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir; +in rec { + # https://github.com/balsoft/nixos-config/blob/73cc2c3a8bb62a9c3980a16ae70b2e97af6e1abd/flake.nix#L109-L120 + findModulesList = dir: + concatLists (attrValues (mapAttrs + (name: type: + if type == "regular" + then [ + { + name = elemAt (match "(.*)\\.nix" name) 0; + value = dir + "/${name}"; + } + ] + else if + (readDir (dir + "/${name}")) + ? "default.nix" + then [ + { + inherit name; + value = dir + "/${name}"; + } + ] + else findModulesList (dir + "/${name}")) (readDir dir))); +}