main
 1# This file provides all the buildable and cacheable packages and
 2# package outputs in your package set. These are what gets built by CI,
 3# so if you correctly mark packages as
 4#
 5# - broken (using `meta.broken`),
 6# - unfree (using `meta.license.free`), and
 7# - locally built (using `preferLocalBuild`)
 8#
 9# then your CI will be able to build and cache only those packages for
10# which this is possible.
11{pkgs ? import <nixpkgs> {}}:
12with builtins; let
13  isReserved = n:
14    n
15    == "lib"
16    || n == "overlays"
17    || n == "nixosModules"
18    || n == "homeModules"
19    || n == "darwinModules"
20    || n == "flakeModules";
21  isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
22  isBuildable = p: let
23    licenseFromMeta = p.meta.license or [];
24    licenseList =
25      if builtins.isList licenseFromMeta
26      then licenseFromMeta
27      else [licenseFromMeta];
28  in
29    !(p.meta.broken or false)
30    && !(p.meta.nurRenamed or false)
31    && !(p.meta.nurDeprecated or false)
32    && builtins.all (license: license.free or true) licenseList;
33  isCacheable = p: !(p.preferLocalBuild or false);
34  shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false;
35
36  nameValuePair = n: v: {
37    name = n;
38    value = v;
39  };
40
41  concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
42
43  flattenPkgs = s: let
44    f = p:
45      if shouldRecurseForDerivations p
46      then flattenPkgs p
47      else if isDerivation p
48      then [p]
49      else [];
50  in
51    concatMap f (attrValues s);
52
53  outputsOf = p: map (o: p.${o}) p.outputs;
54
55  nurAttrs = import ./default.nix {inherit pkgs;};
56
57  nurPkgs = flattenPkgs (
58    listToAttrs (
59      map (n: nameValuePair n nurAttrs.${n}) (filter (n: !isReserved n) (attrNames nurAttrs))
60    )
61  );
62in rec {
63  buildPkgs = filter isBuildable nurPkgs;
64  cachePkgs = filter isCacheable buildPkgs;
65
66  buildOutputs = concatMap outputsOf buildPkgs;
67  cacheOutputs = concatMap outputsOf cachePkgs;
68}