summaryrefslogtreecommitdiffstats
path: root/ci/eval/outpaths.nix
blob: 512290ce450a8671cde8ebc85bb7a67205bb59a3 (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
129
130
131
132
133
#!/usr/bin/env nix-shell
# When using as a callable script, passing `--argstr path some/path` overrides $PWD.
#!nix-shell -p nix -i "nix-env -qaP --no-name --out-path -f ci/eval/outpaths.nix"

{
  includeBroken ? true, # set this to false to exclude meta.broken packages from the output
  path ? ./../..,

  # used by ./pre-eval.nix
  attrNamesOnly ? false,

  # Set this to `null` to build for builtins.currentSystem only
  systems ? builtins.fromJSON (
    builtins.readFile (path + "/pkgs/top-level/release-supported-systems.json")
  ),

  attrPathsDisallowedForInternalUse ? [ ],

  # Customize the config used to evaluate nixpkgs
  extraNixpkgsConfig ? { },
}:
let
  lib = import (path + "/lib");

  nixpkgsJobs =
    import (path + "/pkgs/top-level/release.nix")
      # Compromise: accuracy vs. resources needed for evaluation.
      {
        inherit attrNamesOnly;
        supportedSystems = if systems == null then [ builtins.currentSystem ] else systems;
        nixpkgsArgs = {
          config = {
            allowAliases = false;
            allowBroken = includeBroken;
            allowUnfree = true;
            allowInsecurePredicate = x: true;
            allowVariants = !attrNamesOnly;
            checkMeta = true;

            # We don't need to care about problems being caught using the
            # standard mechanism, because any problems whose kind is not
            # nixpkgsInternalUseAllowed cause the corresponding attributes to
            # be disallowed entirely for internal use with
            # attrPathsDisallowedForInternalUse, see also ./pre-eval.nix
            problems.matchers = lib.mkForce [
              # We only need to set the broken handler to error, so that CI
              # doesn't evaluate those. No reason it couldn't evaluate them
              # afaik, but this is how it's been before.
              {
                kind = "broken";
                handler = "error";
              }
            ];
            inherit attrPathsDisallowedForInternalUse;

            # Silence the `x86_64-darwin` deprecation warning.
            allowDeprecatedx86_64Darwin = true;

            handleEvalIssue =
              reason: errormsg:
              let
                fatalErrors = [
                  "unknown-meta"
                  "broken-outputs"
                ];
              in
              if builtins.elem reason fatalErrors then
                abort errormsg
              # hydra does not build unfree packages, so tons of them are broken yet not marked meta.broken.
              else if
                !includeBroken
                && builtins.elem reason [
                  "broken"
                  "unfree"
                ]
              then
                throw "broken"
              else if builtins.elem reason [ "unsupported" ] then
                throw "unsupported"
              else
                true;

            inHydra = true;
          }
          // extraNixpkgsConfig;

          __allowFileset = false;
        };
      };

  nixosJobs = import (path + "/nixos/release.nix") {
    inherit attrNamesOnly;
    supportedSystems = lib.filter (lib.hasSuffix "-linux") (
      if systems == null then [ builtins.currentSystem ] else systems
    );
  };

  recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };

  # release-lib leaves recurseForDerivations as empty attrmaps;
  # that would break nix-env and we also need to recurse everywhere.
  tweak = lib.mapAttrs (
    name: val:
    if name == "recurseForDerivations" then
      true
    else if lib.isAttrs val && val.type or null != "derivation" then
      recurseIntoAttrs (tweak val)
    else
      val
  );

  # Some of these contain explicit references to platform(s) we want to avoid;
  # some even (transitively) depend on ~/.nixpkgs/config.nix (!)
  blacklist = [
    "tarball"
    "metrics"
    "manual"
    "darwin-tested"
    "unstable"
    "stdenvBootstrapTools"
    "moduleSystem"
    "lib-tests" # these just confuse the output
  ];

in
tweak (
  (removeAttrs nixpkgsJobs blacklist)
  // {
    nixosTests = lib.filterAttrs (
      name: _: name == "simple-container" || name == "simple-vm"
    ) nixosJobs.tests;
  }
)