-
Notifications
You must be signed in to change notification settings - Fork 1
/
packagesets.nix
63 lines (56 loc) · 1.85 KB
/
packagesets.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ lib }:
let
inherit (builtins)
readDir
;
inherit (lib.attrsets)
mapAttrs
mapAttrsToList
mergeAttrsList
;
in
rec {
# Package paths for a directory, this is intened to be used with
# builtins.readDir, in which the contents can use this function to map over
# the results
# Type: Path -> _ -> String -> AttrsOf Path
mkNamesForDirectory = baseDirectory: _: type:
if type != "directory" then
# Ignore files, and only assume that directories will be imported by default
{ }
else
mapAttrs
(name: _: baseDirectory + "/${name}")
(readDir (baseDirectory));
# This is expected to be passed a directory which contains subdirectories which
# correspond to packages.
# Example:
# pkgs/
# openssl/
# default.nix
# curl/
# default.nix
# In this case, `pkgs/` would be the subdirectory, and openssl and curl
# would be added through the resulting overlay
#
# Type: Path -> Overlay
mkAutoCalledPackageDir = baseDirectory:
let
namesForShard = mkNamesForDirectory baseDirectory;
# This is defined up here in order to allow reuse of the value (it's kind of expensive to compute)
# if the overlay has to be applied multiple times
packageFiles = mergeAttrsList (mapAttrsToList namesForShard (readDir baseDirectory));
in
# TODO: Consider optimising this using `builtins.deepSeq packageFiles`,
# which could free up the above thunks and reduce GC times.
# Currently this would be hard to measure until we have more packages
# and ideally https://github.com/NixOS/nix/pull/8895
self: super:
{
# Used to verify call by-name usage
_internalCallByNamePackageFile = file: self.callPackage file { };
}
// mapAttrs
(name: value: self._internalCallByNamePackageFile value)
packageFiles;
}