Skip to content

Commit

Permalink
lib/pathsIn: filter only nix files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacman99 committed Mar 28, 2021
1 parent 4de7b88 commit 8ecdd0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/lists.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
pathsIn = dir:
let
fullPath = name: "${toString dir}/${name}";
filter = lib.hasSuffix ".nix";
paths = lib.attrNames (lib.optionalAttrs
(builtins.pathExists dir) (builtins.readDir dir));
in
map fullPath (lib.attrNames (lib.optionalAttrs
(builtins.pathExists dir) (builtins.readDir dir)));
map fullPath (builtins.filter filter paths);
}
7 changes: 3 additions & 4 deletions tests/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ lib.runTests {

testPathsIn =
let testPaths = pkgs.runCommandNoCC "test-paths-in" { } ''
mkdir -p $out/{foo,bar,baz}
mkdir -p $out/{foo.nix,bar,baz.nix}
'';
in
{
expr = pathsIn testPaths;

expected = [
"${testPaths}/bar"
"${testPaths}/baz"
"${testPaths}/foo"
"${testPaths}/baz.nix"
"${testPaths}/foo.nix"
];
};

Expand Down

0 comments on commit 8ecdd0b

Please sign in to comment.