1 # This file turns the pkgs/by-name directory (see its README.md for more info) into an overlay that adds all the defined packages.
2 # No validity checks are done here,
3 # instead this file is optimised for performance,
4 # and validity checks are done by CI on PRs.
6 # Type: Path -> Overlay
9 # Because of Nix's import-value cache, importing lib is free
10 lib = import ../../lib;
16 inherit (lib.attrsets)
22 # Package files for a single shard
23 # Type: String -> String -> AttrsOf Path
24 namesForShard = shard: type:
25 if type != "directory" then
26 # Ignore all non-directories. Technically only README.md is allowed as a file in the base directory, so we could alternatively:
27 # - Assume that README.md is the only file and change the condition to `shard == "README.md"` for a minor performance improvement.
28 # This would however cause very poor error messages if there's other files.
29 # - Ensure that README.md is the only file, throwing a better error message if that's not the case.
30 # However this would make for a poor code architecture, because one type of error would have to be duplicated in the validity checks and here.
31 # Additionally in either of those alternatives, we would have to duplicate the hardcoding of "README.md"
35 (name: _: baseDirectory + "/${shard}/${name}/package.nix")
36 (readDir (baseDirectory + "/${shard}"));
38 # The attribute set mapping names to the package files defining them
39 # This is defined up here in order to allow reuse of the value (it's kind of expensive to compute)
40 # if the overlay has to be applied multiple times
41 packageFiles = mergeAttrsList (mapAttrsToList namesForShard (readDir baseDirectory));
43 # TODO: Consider optimising this using `builtins.deepSeq packageFiles`,
44 # which could free up the above thunks and reduce GC times.
45 # Currently this would be hard to measure until we have more packages
46 # and ideally https://github.com/NixOS/nix/pull/8895
49 self.callPackage file { }