summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--by-name-overlay.nix47
1 files changed, 28 insertions, 19 deletions
diff --git a/by-name-overlay.nix b/by-name-overlay.nix
index 4d700a8..80aebf4 100644
--- a/by-name-overlay.nix
+++ b/by-name-overlay.nix
@@ -7,6 +7,7 @@
finalizeFunction,
coImportsNameFunction ? null,
coImportsWarnMessageObject ? null,
+ useShards ? true,
}: let
# Takes a list of attrs as input and returns one merged attr set.
flattenAttrs = list:
@@ -43,27 +44,35 @@
namesForShard = shard: type:
if type != "directory"
then warn "Ignored non-directory, whilst importing by-name directory (${fileName}): '${shard}'" {}
- else let
- mkPath = name: _type: let
- path = baseDirectory + "/${shard}/${name}" + "/${fileName}";
- coImportPath =
- if coImportsNameFunction != null
- then
- coImportsNameFunction
- {inherit shard name;}
- else path;
- in
- if builtins.pathExists path
+ else if useShards
+ then namesForElement shard type
+ else namesForElement "." type;
+
+ namesForElement = shard: _type: let
+ mkPath = name: type: let
+ path = baseDirectory + "/${shard}/${name}" + "/${fileName}";
+ coImportPath =
+ if coImportsNameFunction != null
then
- if builtins.pathExists coImportPath
- then path
- else warn "'${builtins.toString coImportPath}' does not exist. Should include ${coImportsWarnMessageObject} for '${shard}/${name}'" path
- else warn "'${builtins.toString path}' does not exist. Skipped" null;
+ coImportsNameFunction
+ {inherit shard name;}
+ else path;
in
- filterAttrs (name: value: value != null)
- (builtins.mapAttrs
- mkPath
- (builtins.readDir (baseDirectory + "/${shard}")));
+ if builtins.pathExists path
+ then
+ if type != "directory"
+ then
+ # The `namesForShard` function should have already printed a warning.
+ null
+ else if builtins.pathExists coImportPath
+ then path
+ else warn "'${builtins.toString coImportPath}' does not exist. Should include ${coImportsWarnMessageObject} for '${shard}/${name}'" path
+ else warn "'${builtins.toString path}' does not exist. Skipped" null;
+ in
+ filterAttrs (name: value: value != null)
+ (builtins.mapAttrs
+ mkPath
+ (builtins.readDir (baseDirectory + "/${shard}")));
# A list of all module paths.
# These can the be simply injected into `import`