|
1 | | -# Takes a path to nixpkgs and a path to the json-encoded list of attributes to check. |
2 | | -# Returns an value containing information on each requested attribute, |
| 1 | +# Takes a path to nixpkgs and a path to the json-encoded list of `pkgs/by-name` attributes. |
| 2 | +# Returns a value containing information on all Nixpkgs attributes |
3 | 3 | # which is decoded on the Rust side. |
4 | 4 | # See ./eval.rs for the meaning of the returned values |
5 | 5 | { |
|
9 | 9 | let |
10 | 10 | attrs = builtins.fromJSON (builtins.readFile attrsPath); |
11 | 11 |
|
12 | | - nixpkgsPathLength = builtins.stringLength (toString nixpkgsPath) + 1; |
13 | | - removeNixpkgsPrefix = builtins.substring nixpkgsPathLength (-1); |
14 | | - |
15 | | - # We need access to the `callPackage` arguments of each attribute. |
16 | | - # The only way to do so is to override `callPackage` with our own version that adds this information to the result, |
17 | | - # and then try to access this information. |
| 12 | + # We need to check whether attributes are defined manually e.g. in |
| 13 | + # `all-packages.nix`, automatically by the `pkgs/by-name` overlay, or |
| 14 | + # neither. The only way to do so is to override `callPackage` and |
| 15 | + # `_internalCallByNamePackageFile` with our own version that adds this |
| 16 | + # information to the result, and then try to access it. |
18 | 17 | overlay = final: prev: { |
19 | 18 |
|
20 | | - # Information for attributes defined using `callPackage` |
| 19 | + # Adds information to each attribute about whether it's manually defined using `callPackage` |
21 | 20 | callPackage = fn: args: |
22 | 21 | addVariantInfo (prev.callPackage fn args) { |
23 | | - Manual = { |
24 | | - path = |
25 | | - if builtins.isPath fn then |
26 | | - removeNixpkgsPrefix (toString fn) |
27 | | - else |
28 | | - null; |
29 | | - empty_arg = |
30 | | - args == { }; |
31 | | - }; |
| 22 | + # This is a manual definition of the attribute, and it's a callPackage, specifically a semantic callPackage |
| 23 | + ManualDefinition.is_semantic_call_package = true; |
32 | 24 | }; |
33 | 25 |
|
34 | | - # Information for attributes that are auto-called from pkgs/by-name. |
35 | | - # This internal attribute is only used by pkgs/by-name |
| 26 | + # Adds information to each attribute about whether it's automatically |
| 27 | + # defined by the `pkgs/by-name` overlay. This internal attribute is only |
| 28 | + # used by that overlay. |
| 29 | + # This overrides the above `callPackage` information (we don't need that |
| 30 | + # one, since `pkgs/by-name` always uses `callPackage` underneath. |
36 | 31 | _internalCallByNamePackageFile = file: |
37 | 32 | addVariantInfo (prev._internalCallByNamePackageFile file) { |
38 | | - Auto = null; |
| 33 | + AutoDefinition = null; |
39 | 34 | }; |
40 | 35 |
|
41 | 36 | }; |
|
50 | 45 | else |
51 | 46 | # It's very rare that callPackage doesn't return an attribute set, but it can occur. |
52 | 47 | # In such a case we can't really return anything sensible that would include the info, |
53 | | - # so just don't return the info and let the consumer handle it. |
| 48 | + # so just don't return the value directly and treat it as if it wasn't a callPackage. |
54 | 49 | value; |
55 | 50 |
|
56 | 51 | pkgs = import nixpkgsPath { |
|
62 | 57 | system = "x86_64-linux"; |
63 | 58 | }; |
64 | 59 |
|
65 | | - attrInfo = name: value: |
66 | | - if ! builtins.isAttrs value then |
67 | | - { |
68 | | - NonAttributeSet = null; |
69 | | - } |
70 | | - else if ! value ? _callPackageVariant then |
71 | | - { |
72 | | - NonCallPackage = null; |
73 | | - } |
74 | | - else |
75 | | - { |
76 | | - CallPackage = { |
77 | | - call_package_variant = value._callPackageVariant; |
78 | | - is_derivation = pkgs.lib.isDerivation value; |
79 | | - location = builtins.unsafeGetAttrPos name pkgs; |
| 60 | + # See AttributeInfo in ./eval.rs for the meaning of this |
| 61 | + attrInfo = name: value: { |
| 62 | + location = builtins.unsafeGetAttrPos name pkgs; |
| 63 | + attribute_variant = |
| 64 | + if ! builtins.isAttrs value then |
| 65 | + { NonAttributeSet = null; } |
| 66 | + else |
| 67 | + { |
| 68 | + AttributeSet = { |
| 69 | + is_derivation = pkgs.lib.isDerivation value; |
| 70 | + definition_variant = |
| 71 | + if ! value ? _callPackageVariant then |
| 72 | + { ManualDefinition.is_semantic_call_package = false; } |
| 73 | + else |
| 74 | + value._callPackageVariant; |
| 75 | + }; |
80 | 76 | }; |
81 | | - }; |
| 77 | + }; |
82 | 78 |
|
| 79 | + # Information on all attributes that are in pkgs/by-name. |
83 | 80 | byNameAttrs = builtins.listToAttrs (map (name: { |
84 | 81 | inherit name; |
85 | 82 | value.ByName = |
86 | 83 | if ! pkgs ? ${name} then |
87 | 84 | { Missing = null; } |
88 | 85 | else |
| 86 | + # Evaluation failures are not allowed, so don't try to catch them |
89 | 87 | { Existing = attrInfo name pkgs.${name}; }; |
90 | 88 | }) attrs); |
91 | 89 |
|
92 | 90 | # Information on all attributes that exist but are not in pkgs/by-name. |
93 | 91 | # We need this to enforce pkgs/by-name for new packages |
94 | 92 | nonByNameAttrs = builtins.mapAttrs (name: value: |
95 | 93 | let |
| 94 | + # Packages outside `pkgs/by-name` often fail evaluation, |
| 95 | + # so we need to handle that |
96 | 96 | output = attrInfo name value; |
97 | 97 | result = builtins.tryEval (builtins.deepSeq output null); |
98 | 98 | in |
|
0 commit comments