summaryrefslogtreecommitdiffstats
path: root/ci/eval/pre-eval.nix
blob: eff8204a7bd52a159ac2536ba399462b112605a0 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# This file does a fast pre-evaluation of Nixpkgs to determine:
# - paths: A *superset* of all attrpaths of derivations which might be part of a release on *any* platform.
# - attrPathsDisallowedForInternalUse: Attribute paths whose meta.problems has problems whose kinds should not be used internally in Nixpkgs
#
# This expression runs single-threaded under all current Nix
# implementations, but much faster and with much less memory
# used than ./outpaths.nix itself.
#
# Once you have the list of attrnames you can split it up into
# $NUM_CORES batches and evaluate the outpaths separately for each
# batch, in parallel.
#
# To dump the result:
#
#   nix-instantiate --eval --strict --json ci/eval/pre-eval.nix -A result
#
{
  lib ? import (path + "/lib"),
  trace ? false,
  path ? ./../..,
  extraNixpkgsConfigJson ? "{}",
}:
let

  # TODO: Use mapAttrsToListRecursiveCond when this PR lands:
  # https://github.com/NixOS/nixpkgs/pull/395160
  listAttrs =
    path: value:
    let
      result =
        if path == [ "AAAAAASomeThingsFailToEvaluate" ] || !(lib.isAttrs value) then
          [ ]
        else if lib.isDerivation value then
          [
            {
              inherit path value;
            }
          ]
        else
          lib.pipe value [
            (lib.mapAttrsToList (
              name: value:
              lib.addErrorContext "while evaluating package set attribute path '${
                lib.showAttrPath (path ++ [ name ])
              }'" (listAttrs (path ++ [ name ]) value)
            ))
            lib.concatLists
          ];
    in
    lib.traceIf trace "** ${lib.showAttrPath path}" result;

  outpaths = import ./outpaths.nix {
    inherit path;
    extraNixpkgsConfig = builtins.fromJSON extraNixpkgsConfigJson;
    attrNamesOnly = true;
  };

  list =
    map
      (path: {
        inherit path;
        # This looks a bit weird, but the only reason we care about this value
        # is for the meta.problems check below, and stdenv's certainly don't
        # have any problems, so this is fine :)
        value = { };
      })
      [
        # Some of the following are based on variants, which are disabled with `attrNamesOnly = true`.
        # Until these have been removed from release.nix / hydra, we manually add them to the list.
        [
          "pkgsLLVM"
          "stdenv"
        ]
        [
          "pkgsArocc"
          "stdenv"
        ]
        [
          "pkgsZig"
          "stdenv"
        ]
        [
          "pkgsStatic"
          "stdenv"
        ]
        [
          "pkgsMusl"
          "stdenv"
        ]
      ]
    ++ listAttrs [ ] outpaths;
  paths = map (attrs: attrs.path) list;
  names = map lib.showAttrPath paths;

  inherit (import ../../pkgs/stdenv/generic/problems.nix { inherit lib; })
    disallowNixpkgsInternalUseKinds
    ;

  # Determine the list of attributes whose packages have any meta.problems
  # with a kind that's disallowed from internal Nixpkgs use
  attrPathsDisallowedForInternalUse = lib.pipe list [
    (lib.map (
      attrs:
      attrs
      // {
        problematicProblems = builtins.tryEval (
          lib.filterAttrs (name: problem: disallowNixpkgsInternalUseKinds ? ${problem.kind}) (
            attrs.value.meta.problems or { }
          )
        );
      }
    ))
    (lib.filter (attrs: attrs.problematicProblems.success && attrs.problematicProblems.value != { }))
    (lib.map (attrs: {
      attrPath = attrs.path;
      reason = "it has certain meta.problems whose kinds are disallowed: ${
        lib.generators.toPretty { } attrs.problematicProblems.value
      }";
    }))
  ];
in
{
  # TODO: Do we still need these? Probably not
  inherit paths names;
  result = {
    inherit paths attrPathsDisallowedForInternalUse;
  };
}