diff --git a/lib/attrs.nix b/lib/attrs.nix index 0d082aa..de7dc5d 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -12,13 +12,16 @@ rec { # Generate an attribute set by mapping a function over a list of values. genAttrs' = values: f: lib.listToAttrs (map f values); - # Convert a list of file paths to attribute set - # that has the filenames stripped of nix extension as keys - # and imported content of the file as value. + # Convert a list of file paths to attribute set where + # the key is the folder or filename stripped of nix + # extension and imported content of the file as value. # pathsToImportedAttrs = paths: let - paths' = lib.filter (lib.hasSuffix ".nix") paths; + paths' = lib.filter + (path: lib.hasSuffix ".nix" path + || lib.pathExists "${path}/default.nix") + paths; in genAttrs' paths' (path: { name = lib.removeSuffix ".nix" diff --git a/tests/lib.nix b/tests/lib.nix index 3b181cc..d3ca9ad 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -46,13 +46,15 @@ lib.runTests { testPathsToImportedAttrs = { expr = pathsToImportedAttrs [ - ./testPathsToImportedAttrs/foo.nix - ./testPathsToImportedAttrs/bar.nix - ./testPathsToImportedAttrs/t.nix - ./testPathsToImportedAttrs/f.nix + "${self}/tests/testPathsToImportedAttrs/dir" + "${self}/tests/testPathsToImportedAttrs/foo.nix" + "${self}/tests/testPathsToImportedAttrs/bar.nix" + "${self}/tests/testPathsToImportedAttrs/t.nix" + "${self}/tests/testPathsToImportedAttrs/f.nix" ]; expected = { + dir = { a = 5; }; foo = { bar = 1; }; bar = { foo = 2; }; t = true; diff --git a/tests/testPathsToImportedAttrs/dir/default.nix b/tests/testPathsToImportedAttrs/dir/default.nix new file mode 100644 index 0000000..01cb926 --- /dev/null +++ b/tests/testPathsToImportedAttrs/dir/default.nix @@ -0,0 +1 @@ +{ a = 5; }