|
81 | 81 | inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags; |
82 | 82 | }) |
83 | 83 | else let |
| 84 | + references = nativeBuildInputs ++ buildInputs |
| 85 | + ++ propagatedNativeBuildInputs ++ propagatedBuildInputs; |
| 86 | + |
84 | 87 | dependencies = map (map lib.chooseDevOutputs) [ |
85 | 88 | [ |
86 | 89 | (map (drv: drv.__spliced.buildBuild or drv) depsBuildBuild) |
@@ -140,9 +143,12 @@ rec { |
140 | 143 | (lib.concatLists propagatedDependencies)); |
141 | 144 | in |
142 | 145 | { |
143 | | - name = name + lib.optionalString |
| 146 | + # A hack to make `nix-env -qa` and `nix search` ignore broken packages. |
| 147 | + # TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix. |
| 148 | + name = assert validity.handled; name + lib.optionalString |
144 | 149 | (stdenv.hostPlatform != stdenv.buildPlatform) |
145 | 150 | ("-" + stdenv.hostPlatform.config); |
| 151 | + |
146 | 152 | builder = attrs.realBuilder or stdenv.shell; |
147 | 153 | args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; |
148 | 154 | inherit stdenv; |
@@ -197,46 +203,59 @@ rec { |
197 | 203 | doInstallCheck = doInstallCheck && (stdenv.hostPlatform == stdenv.buildPlatform); |
198 | 204 | }); |
199 | 205 |
|
| 206 | + validity = import ./check-meta.nix { |
| 207 | + inherit lib config meta derivationArg; |
| 208 | + mkDerivationArg = attrs; |
| 209 | + # Nix itself uses the `system` field of a derivation to decide where |
| 210 | + # to build it. This is a bit confusing for cross compilation. |
| 211 | + inherit (stdenv) system; |
| 212 | + }; |
| 213 | + |
200 | 214 | # The meta attribute is passed in the resulting attribute set, |
201 | 215 | # but it's not part of the actual derivation, i.e., it's not |
202 | 216 | # passed to the builder and is not a dependency. But since we |
203 | 217 | # include it in the result, it *is* available to nix-env for queries. |
204 | | - meta = { } |
| 218 | + meta = { |
| 219 | + # `name` above includes cross-compilation cruft (and is under assert), |
| 220 | + # lets have a clean always accessible version here. |
| 221 | + inherit name; |
| 222 | + |
205 | 223 | # If the packager hasn't specified `outputsToInstall`, choose a default, |
206 | 224 | # which is the name of `p.bin or p.out or p`; |
207 | 225 | # if he has specified it, it will be overridden below in `// meta`. |
208 | 226 | # Note: This default probably shouldn't be globally configurable. |
209 | 227 | # Services and users should specify outputs explicitly, |
210 | 228 | # unless they are comfortable with this default. |
211 | | - // { outputsToInstall = |
212 | | - let |
213 | | - outs = outputs'; # the value passed to derivation primitive |
214 | | - hasOutput = out: builtins.elem out outs; |
215 | | - in [( lib.findFirst hasOutput null (["bin" "out"] ++ outs) )]; |
| 229 | + outputsToInstall = |
| 230 | + let |
| 231 | + outs = outputs'; # the value passed to derivation primitive |
| 232 | + hasOutput = out: builtins.elem out outs; |
| 233 | + in [( lib.findFirst hasOutput null (["bin" "out"] ++ outs) )]; |
216 | 234 | } |
217 | 235 | // attrs.meta or {} |
218 | | - # Fill `meta.position` to identify the source location of the package. |
219 | | - // lib.optionalAttrs (pos != null) |
220 | | - { position = pos.file + ":" + toString pos.line; } |
221 | | - ; |
| 236 | + # Fill `meta.position` to identify the source location of the package. |
| 237 | + // lib.optionalAttrs (pos != null) { |
| 238 | + position = pos.file + ":" + toString pos.line; |
| 239 | + # Expose the result of the checks for everyone to see. |
| 240 | + } // { |
| 241 | + evaluates = validity.valid |
| 242 | + && (if config.checkMetaRecursively or false |
| 243 | + then lib.all (d: d.meta.evaluates or true) references |
| 244 | + else true); |
| 245 | + }; |
222 | 246 |
|
223 | 247 | in |
224 | 248 |
|
225 | | - lib.addPassthru |
226 | | - (derivation (import ./check-meta.nix |
227 | | - { |
228 | | - inherit lib config meta derivationArg; |
229 | | - mkDerivationArg = attrs; |
230 | | - # Nix itself uses the `system` field of a derivation to decide where |
231 | | - # to build it. This is a bit confusing for cross compilation. |
232 | | - inherit (stdenv) system; |
233 | | - })) |
234 | | - ( { |
235 | | - overrideAttrs = f: mkDerivation (attrs // (f attrs)); |
236 | | - inherit meta passthru; |
237 | | - } // |
238 | | - # Pass through extra attributes that are not inputs, but |
239 | | - # should be made available to Nix expressions using the |
240 | | - # derivation (e.g., in assertions). |
241 | | - passthru); |
| 249 | + lib.extendDerivation |
| 250 | + validity.handled |
| 251 | + ({ |
| 252 | + overrideAttrs = f: mkDerivation (attrs // (f attrs)); |
| 253 | + inherit meta passthru; |
| 254 | + } // |
| 255 | + # Pass through extra attributes that are not inputs, but |
| 256 | + # should be made available to Nix expressions using the |
| 257 | + # derivation (e.g., in assertions). |
| 258 | + passthru) |
| 259 | + (derivation derivationArg); |
| 260 | + |
242 | 261 | } |
0 commit comments