From 5e420c24556053e2a5ad3ca69993afb42fffbc54 Mon Sep 17 00:00:00 2001 From: ckie Date: Tue, 3 May 2022 22:12:34 +0300 Subject: [PATCH] stdenv/check-meta: turn validity.valid into a str This will allow for adding more validity types in the future, such as a warning type. (which is in the next commit in this series) This is NOT a breaking change because validity.valid is never exposed outside of `stdenv.mkDerivation`. --- pkgs/stdenv/generic/check-meta.nix | 27 ++++++++++++++----------- pkgs/stdenv/generic/make-derivation.nix | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index e0ead55d1a78..5d4f3579b915 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -277,28 +277,31 @@ let insecure = isMarkedInsecure attrs; } // (if hasDeniedUnfreeLicense attrs && !(hasAllowlistedLicense attrs) then - { valid = false; reason = "unfree"; errormsg = "has an unfree license (‘${showLicense attrs.meta.license}’)"; } + { valid = "no"; reason = "unfree"; errormsg = "has an unfree license (‘${showLicense attrs.meta.license}’)"; } else if hasBlocklistedLicense attrs then - { valid = false; reason = "blocklisted"; errormsg = "has a blocklisted license (‘${showLicense attrs.meta.license}’)"; } + { valid = "no"; reason = "blocklisted"; errormsg = "has a blocklisted license (‘${showLicense attrs.meta.license}’)"; } else if !allowBroken && attrs.meta.broken or false then - { valid = false; reason = "broken"; errormsg = "is marked as broken"; } + { valid = "no"; reason = "broken"; errormsg = "is marked as broken"; } else if !allowUnsupportedSystem && hasUnsupportedPlatform attrs then - { valid = false; reason = "unsupported"; errormsg = "is not supported on ‘${hostPlatform.system}’"; } + { valid = "no"; reason = "unsupported"; errormsg = "is not supported on ‘${hostPlatform.system}’"; } else if !(hasAllowedInsecure attrs) then - { valid = false; reason = "insecure"; errormsg = "is marked as insecure"; } + { valid = "no"; reason = "insecure"; errormsg = "is marked as insecure"; } else if checkOutputsToInstall attrs then - { valid = false; reason = "broken-outputs"; errormsg = "has invalid meta.outputsToInstall"; } + { valid = "no"; reason = "broken-outputs"; errormsg = "has invalid meta.outputsToInstall"; } else let res = checkMeta (attrs.meta or {}); in if res != [] then - { valid = false; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; } - else { valid = true; }); + { valid = "no"; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; } + else { valid = "yes"; }); assertValidity = { meta, attrs }: let validity = checkValidity attrs; in validity // { - # Throw an error if trying to evaluate an non-valid derivation - handled = if !validity.valid - then handleEvalIssue { inherit meta attrs; } { inherit (validity) reason errormsg; } - else true; + # Throw an error if trying to evaluate a non-valid derivation + # or, alternatively, just output a warning message. + handled = + { + no = handleEvalIssue { inherit meta attrs; } { inherit (validity) reason errormsg; }; + yes = true; + }.${validity.valid}; }; in assertValidity diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index d1b93874a25a..53e391ab63f8 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -370,7 +370,7 @@ else let } // { # Expose the result of the checks for everyone to see. inherit (validity) unfree broken unsupported insecure; - available = validity.valid + available = validity.valid != "no" && (if config.checkMetaRecursively or false then lib.all (d: d.meta.available or true) references else true);