diff options
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r-- | pkgs/stdenv/generic/check-meta.nix | 52 | ||||
-rw-r--r-- | pkgs/stdenv/generic/make-derivation.nix | 62 |
2 files changed, 70 insertions, 44 deletions
diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 7f317c787b0..63fd00d266e 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -390,6 +390,55 @@ let # ----- else { valid = "yes"; }); + + # The meta attribute is passed in the resulting attribute set, + # but it's not part of the actual derivation, i.e., it's not + # passed to the builder and is not a dependency. But since we + # include it in the result, it *is* available to nix-env for queries. + # Example: + # meta = checkMeta.commonMeta { inherit validity attrs pos references; }; + # validity = checkMeta.assertValidity { inherit meta attrs; }; + commonMeta = { validity, attrs, pos ? null, references ? [ ] }: + let + outputs = attrs.outputs or [ "out" ]; + in + { + # `name` derivation attribute includes cross-compilation cruft, + # is under assert, and is sanitized. + # Let's have a clean always accessible version here. + name = attrs.name or "${attrs.pname}-${attrs.version}"; + + # If the packager hasn't specified `outputsToInstall`, choose a default, + # which is the name of `p.bin or p.out or p` along with `p.man` when + # present. + # + # If the packager has specified it, it will be overridden below in + # `// meta`. + # + # Note: This default probably shouldn't be globally configurable. + # Services and users should specify outputs explicitly, + # unless they are comfortable with this default. + outputsToInstall = + let + hasOutput = out: builtins.elem out outputs; + in + [ (lib.findFirst hasOutput null ([ "bin" "out" ] ++ outputs)) ] + ++ lib.optional (hasOutput "man") "man"; + } + // attrs.meta or { } + # Fill `meta.position` to identify the source location of the package. + // lib.optionalAttrs (pos != null) { + position = pos.file + ":" + toString pos.line; + } // { + # Expose the result of the checks for everyone to see. + inherit (validity) unfree broken unsupported insecure; + + available = validity.valid != "no" + && (if config.checkMetaRecursively or false + then lib.all (d: d.meta.available or true) references + else true); + }; + assertValidity = { meta, attrs }: let validity = checkValidity attrs; in validity // { @@ -401,6 +450,7 @@ let warn = handleEvalWarning { inherit meta attrs; } { inherit (validity) reason errormsg; }; yes = true; }.${validity.valid}; + }; -in assertValidity +in { inherit assertValidity commonMeta; } diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 50d4b58615b..40ad357739b 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -294,6 +294,7 @@ else let (["meta" "passthru" "pos" "checkInputs" "installCheckInputs" "nativeCheckInputs" "nativeInstallCheckInputs" + "__contentAddressed" "__darwinAllowLocalNetworking" "__impureHostDeps" "__propagatedImpureHostDeps" "sandboxProfile" "propagatedSandboxProfile"] @@ -309,6 +310,7 @@ else let hostSuffix = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix) "-${stdenv.hostPlatform.config}"; + # Disambiguate statically built packages. This was originally # introduce as a means to prevent nix-env to get confused between # nix and nixStatic. This should be also achieved by moving the @@ -319,7 +321,10 @@ else let lib.strings.sanitizeDerivationName ( if attrs ? name then attrs.name + hostSuffix - else "${attrs.pname}${staticMarker}${hostSuffix}-${attrs.version}" + else + # we cannot coerce null to a string below + assert lib.assertMsg (attrs ? version && attrs.version != null) "The ‘version’ attribute cannot be null."; + "${attrs.pname}${staticMarker}${hostSuffix}-${attrs.version}" ); }) // lib.optionalAttrs __structuredAttrs { env = checkedEnv; } // { builder = attrs.realBuilder or stdenv.shell; @@ -497,46 +502,8 @@ else let lib.mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedRequisites; }; - validity = checkMeta { inherit meta attrs; }; - - # The meta attribute is passed in the resulting attribute set, - # but it's not part of the actual derivation, i.e., it's not - # passed to the builder and is not a dependency. But since we - # include it in the result, it *is* available to nix-env for queries. - meta = { - # `name` above includes cross-compilation cruft, - # is under assert, and is sanitized. - # Let's have a clean always accessible version here. - name = attrs.name or "${attrs.pname}-${attrs.version}"; - - # If the packager hasn't specified `outputsToInstall`, choose a default, - # which is the name of `p.bin or p.out or p` along with `p.man` when - # present. - # - # If the packager has specified it, it will be overridden below in - # `// meta`. - # - # Note: This default probably shouldn't be globally configurable. - # Services and users should specify outputs explicitly, - # unless they are comfortable with this default. - outputsToInstall = - let - hasOutput = out: builtins.elem out outputs; - in [( lib.findFirst hasOutput null (["bin" "out"] ++ outputs) )] - ++ lib.optional (hasOutput "man") "man"; - } - // attrs.meta or {} - # Fill `meta.position` to identify the source location of the package. - // lib.optionalAttrs (pos != null) { - position = pos.file + ":" + toString pos.line; - } // { - # Expose the result of the checks for everyone to see. - inherit (validity) unfree broken unsupported insecure; - available = validity.valid != "no" - && (if config.checkMetaRecursively or false - then lib.all (d: d.meta.available or true) references - else true); - }; + meta = checkMeta.commonMeta { inherit validity attrs pos references; }; + validity = checkMeta.assertValidity { inherit meta attrs; }; checkedEnv = let @@ -578,16 +545,25 @@ lib.extendDerivation # binaries). By writing this to $out, Nix can find and register # them as runtime dependencies (since Nix greps for store paths # through $out to find them) - args = [ "-c" "export > $out" ]; + args = [ "-c" '' + export > $out + for var in $passAsFile; do + pathVar="''${var}Path" + printf "%s" "$(< "''${!pathVar}")" >> $out + done + '' ]; # inputDerivation produces the inputs; not the outputs, so any # restrictions on what used to be the outputs don't serve a purpose # anymore. + allowedReferences = null; + allowedRequisites = null; disallowedReferences = [ ]; disallowedRequisites = [ ]; }); - inherit meta passthru overrideAttrs; + inherit passthru overrideAttrs; + inherit meta; } // # Pass through extra attributes that are not inputs, but # should be made available to Nix expressions using the |