Refactor loadImports function to add recursive capability of import
This commit is contained in:
parent
2c997cddce
commit
b54be83fd7
7 changed files with 31 additions and 28 deletions
|
|
@ -1,3 +0,0 @@
|
||||||
{lib, ...}: {
|
|
||||||
imports = lib.youthlic.loadImports ./.;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{lib, ...}: {
|
|
||||||
imports = lib.youthlic.loadImports ./.;
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +1,35 @@
|
||||||
final: _prev: {
|
final: _prev: {
|
||||||
youthlic = {
|
youthlic = {
|
||||||
loadImports' = dir: f:
|
loadImports' = dir: f:
|
||||||
if (builtins.pathExists dir && (builtins.readFileType dir) == "directory")
|
final.pipe dir [
|
||||||
then
|
final.youthlic.loadImports
|
||||||
with final;
|
f
|
||||||
pipe dir [
|
];
|
||||||
builtins.readDir
|
loadImports = dir:
|
||||||
attrNames
|
with final;
|
||||||
(filter (name: name != "default.nix"))
|
if !(pathExists dir && builtins.readFileType dir == "directory")
|
||||||
f
|
then []
|
||||||
(map (name: dir + "/${name}"))
|
else let
|
||||||
]
|
items = pipe dir [builtins.readDir attrNames];
|
||||||
else [];
|
in
|
||||||
loadImports = with final; flip youthlic.loadImports' (x: x);
|
pipe items [
|
||||||
|
(concatMap
|
||||||
|
(name: let
|
||||||
|
path = dir + "/${name}";
|
||||||
|
type = builtins.readFileType path;
|
||||||
|
in
|
||||||
|
if type == "directory"
|
||||||
|
then
|
||||||
|
if pathExists (path + "/default.nix")
|
||||||
|
then [path]
|
||||||
|
else youthlic.loadImports path
|
||||||
|
else if type == "regular"
|
||||||
|
then
|
||||||
|
if hasSuffix ".nix" name
|
||||||
|
then [path]
|
||||||
|
else []
|
||||||
|
else []))
|
||||||
|
(filter (name: !hasSuffix "/default.nix" (toString name)))
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{lib, ...}: {
|
|
||||||
imports = lib.youthlic.loadImports ./.;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{lib, ...}: {
|
{lib, ...}: {
|
||||||
imports = with lib; youthlic.loadImports' ./. (filter (name: name != "top-level"));
|
imports = with lib; youthlic.loadImports' ./. (filter (name: !hasSuffix "/top-level" (toString name)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{lib, ...}: {
|
|
||||||
imports = lib.youthlic.loadImports ./.;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{lib, ...}: {
|
|
||||||
imports = lib.youthlic.loadImports ./.;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue