diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-24 16:49:21 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-24 16:49:21 +0100 |
commit | 10c82665cb197b68ff0d9bb02e12a4287f1b8925 (patch) | |
tree | 49070405014d2ced07eb3201bd625cde25dbc9b8 | |
parent | chore: Initial Commit (diff) | |
download | nix-library-10c82665cb197b68ff0d9bb02e12a4287f1b8925.zip |
feat(by-name-overlay.nix): Support non-sharded by-name directories prime
-rw-r--r-- | by-name-overlay.nix | 47 |
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` |