@@ -81,6 +81,9 @@ rec {
8181 inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags;
8282 })
8383 else let
84+ references = nativeBuildInputs ++ buildInputs
85+ ++ propagatedNativeBuildInputs ++ propagatedBuildInputs;
86+
8487 dependencies = map (map lib.chooseDevOutputs) [
8588 [
8689 (map (drv: drv.__spliced.buildBuild or drv) depsBuildBuild)
@@ -140,9 +143,12 @@ rec {
140143 (lib.concatLists propagatedDependencies));
141144 in
142145 {
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
144149 (stdenv.hostPlatform != stdenv.buildPlatform)
145150 ("-" + stdenv.hostPlatform.config);
151+
146152 builder = attrs.realBuilder or stdenv.shell;
147153 args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
148154 inherit stdenv;
@@ -197,46 +203,59 @@ rec {
197203 doInstallCheck = doInstallCheck && (stdenv.hostPlatform == stdenv.buildPlatform);
198204 });
199205
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+
200214 # The meta attribute is passed in the resulting attribute set,
201215 # but it's not part of the actual derivation, i.e., it's not
202216 # passed to the builder and is not a dependency. But since we
203217 # 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+
205223 # If the packager hasn't specified `outputsToInstall`, choose a default,
206224 # which is the name of `p.bin or p.out or p`;
207225 # if he has specified it, it will be overridden below in `// meta`.
208226 # Note: This default probably shouldn't be globally configurable.
209227 # Services and users should specify outputs explicitly,
210228 # 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) )];
216234 }
217235 // 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+ };
222246
223247 in
224248
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+
242261}