forked from pub-solar/os
Merge #224
224: Allow for directories in module-list r=nrdxp a=Pacman99 fixes #221 building on #222 this PR improves the lib functions pathsToImportedAttrs and pathsIn. First to add support for directories. This does not support actually passing a file in a directory, so `./matrix/default.nix` won't work but `./matrix` will - I should probably document this somewhere. Also I moved the filtering for nix files to `pathsIn`, since its only necessary for auto-import. We can assume that users would pass proper files in `module-list.nix`. Co-authored-by: Pacman99 <pachum99@gmail.com>
This commit is contained in:
commit
f14dcdaf78
|
@ -12,13 +12,16 @@ rec {
|
||||||
# Generate an attribute set by mapping a function over a list of values.
|
# Generate an attribute set by mapping a function over a list of values.
|
||||||
genAttrs' = values: f: lib.listToAttrs (map f values);
|
genAttrs' = values: f: lib.listToAttrs (map f values);
|
||||||
|
|
||||||
# Convert a list of file paths to attribute set
|
# Convert a list of file paths to attribute set where
|
||||||
# that has the filenames stripped of nix extension as keys
|
# the key is the folder or filename stripped of nix
|
||||||
# and imported content of the file as value.
|
# extension and imported content of the file as value.
|
||||||
#
|
#
|
||||||
pathsToImportedAttrs = paths:
|
pathsToImportedAttrs = paths:
|
||||||
let
|
let
|
||||||
paths' = lib.filter (lib.hasSuffix ".nix") paths;
|
paths' = lib.filter
|
||||||
|
(path: lib.hasSuffix ".nix" path
|
||||||
|
|| lib.pathExists "${path}/default.nix")
|
||||||
|
paths;
|
||||||
in
|
in
|
||||||
genAttrs' paths' (path: {
|
genAttrs' paths' (path: {
|
||||||
name = lib.removeSuffix ".nix"
|
name = lib.removeSuffix ".nix"
|
||||||
|
|
|
@ -46,13 +46,15 @@ lib.runTests {
|
||||||
testPathsToImportedAttrs = {
|
testPathsToImportedAttrs = {
|
||||||
expr =
|
expr =
|
||||||
pathsToImportedAttrs [
|
pathsToImportedAttrs [
|
||||||
./testPathsToImportedAttrs/foo.nix
|
"${self}/tests/testPathsToImportedAttrs/dir"
|
||||||
./testPathsToImportedAttrs/bar.nix
|
"${self}/tests/testPathsToImportedAttrs/foo.nix"
|
||||||
./testPathsToImportedAttrs/t.nix
|
"${self}/tests/testPathsToImportedAttrs/bar.nix"
|
||||||
./testPathsToImportedAttrs/f.nix
|
"${self}/tests/testPathsToImportedAttrs/t.nix"
|
||||||
|
"${self}/tests/testPathsToImportedAttrs/f.nix"
|
||||||
];
|
];
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
dir = { a = 5; };
|
||||||
foo = { bar = 1; };
|
foo = { bar = 1; };
|
||||||
bar = { foo = 2; };
|
bar = { foo = 2; };
|
||||||
t = true;
|
t = true;
|
||||||
|
|
1
tests/testPathsToImportedAttrs/dir/default.nix
Normal file
1
tests/testPathsToImportedAttrs/dir/default.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{ a = 5; }
|
Loading…
Reference in a new issue