feat: add fs.get-directories-with-default helper to eliminate duplicate directory filtering

This commit is contained in:
anntnzrb
2025-10-08 23:41:21 -05:00
parent 9969d5d8e3
commit 06620a8e41
3 changed files with 16 additions and 4 deletions

View File

@@ -99,6 +99,20 @@ in
in
mapAttrsToList (name: kind: "${path}/${name}") filtered-entries;
## Get directories containing default.nix at a given path.
## Example Usage:
## ```nix
## get-directories-with-default ./systems/x86_64-linux
## ```
## Result:
## ```nix
## [ "./systems/x86_64-linux/my-host" ]
## ```
#@ Path -> [Path]
get-directories-with-default =
path:
builtins.filter (dir: pathExists "${dir}/default.nix") (get-directories path);
## Get files at a given path.
## Example Usage:
## ```nix

View File

@@ -179,8 +179,7 @@ in
get-target-homes-metadata =
target:
let
homes = snowfall-lib.fs.get-directories target;
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
existing-homes = snowfall-lib.fs.get-directories-with-default target;
create-home-metadata =
path:
let

View File

@@ -106,8 +106,7 @@ in
get-target-systems-metadata =
target:
let
systems = snowfall-lib.fs.get-directories target;
existing-systems = builtins.filter (system: builtins.pathExists "${system}/default.nix") systems;
existing-systems = snowfall-lib.fs.get-directories-with-default target;
create-system-metadata = path: {
path = "${path}/default.nix";
# We are building flake outputs based on file contents. Nix doesn't like this