summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2015-11-29 16:04:03 +0100
committerPeter Simons <simons@cryp.to>2015-11-29 16:04:03 +0100
commit5e46f431f4436f80096377c4e3a850614e3fbecb (patch)
tree94ff1360887e7492159a6b14132a9bd62036b995
parent072aa5000fef0c71f589806d6e62e81ce40eef50 (diff)
parentee07543ccd9422a82b248d283946c75a72003a81 (diff)
downloadnixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar.gz
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar.bz2
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar.lz
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar.xz
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.tar.zst
nixlib-5e46f431f4436f80096377c4e3a850614e3fbecb.zip
Merge pull request #11309 from Profpatsch/refactor-stdenv-generic
stdenv: `licenseAllowed` -> `checkValidity`
-rw-r--r--pkgs/stdenv/generic/default.nix42
1 files changed, 29 insertions, 13 deletions
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 246ca3696d58..1a2ca5038b20 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -111,30 +111,41 @@ let
           builtins.unsafeGetAttrPos "name" attrs;
       pos'' = if pos' != null then "‘" + pos'.file + ":" + toString pos'.line + "’" else "«unknown-file»";
 
-      throwEvalHelp = unfreeOrBroken: whatIsWrong:
-        assert builtins.elem unfreeOrBroken ["Unfree" "Broken" "blacklisted"];
+      throwEvalHelp = { reason, errormsg }:
+        # uppercase the first character of string s
+        let up = s: with lib;
+          let cs = lib.stringToCharacters s;
+          in concatStrings (singleton (toUpper (head cs)) ++ tail cs);
+        in
+        assert builtins.elem reason ["unfree" "broken" "blacklisted"];
 
-        throw ("Package ‘${attrs.name or "«name-missing»"}’ in ${pos''} ${whatIsWrong}, refusing to evaluate."
-        + (lib.strings.optionalString (unfreeOrBroken != "blacklisted") ''
+        throw ("Package ‘${attrs.name or "«name-missing»"}’ in ${pos''} ${errormsg}, refusing to evaluate."
+        + (lib.strings.optionalString (reason != "blacklisted") ''
 
           For `nixos-rebuild` you can set
-            { nixpkgs.config.allow${unfreeOrBroken} = true; }
+            { nixpkgs.config.allow${up reason} = true; }
           in configuration.nix to override this.
           For `nix-env` you can add
-            { allow${unfreeOrBroken} = true; }
+            { allow${up reason} = true; }
           to ~/.nixpkgs/config.nix.
         ''));
 
-      licenseAllowed = attrs:
+      # Check if a derivation is valid, that is whether it passes checks for
+      # e.g brokenness or license.
+      #
+      # Return { valid: Bool } and additionally
+      # { reason: String; errormsg: String } if it is not valid, where
+      # reason is one of "unfree", "blacklisted" or "broken".
+      checkValidity = attrs:
         if hasDeniedUnfreeLicense attrs && !(hasWhitelistedLicense attrs) then
-          throwEvalHelp "Unfree" "has an unfree license (‘${showLicense attrs.meta.license}’)"
+          { valid = false; reason = "unfree"; errormsg = "has an unfree license (‘${showLicense attrs.meta.license}’)"; }
         else if hasBlacklistedLicense attrs then
-          throwEvalHelp "blacklisted" "has a blacklisted license (‘${showLicense attrs.meta.license}’)"
+          { valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
         else if !allowBroken && attrs.meta.broken or false then
-          throwEvalHelp "Broken" "is marked as broken"
+          { valid = false; reason = "broken"; errormsg = "is marked as broken"; }
         else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
-          throwEvalHelp "Broken" "is not supported on ‘${result.system}’"
-        else true;
+          { valid = false; reason = "broken"; errormsg = "is not supported on ‘${result.system}’"; }
+        else { valid = true; };
 
       outputs' =
         outputs ++
@@ -144,7 +155,12 @@ let
         (if separateDebugInfo then [ ../../build-support/setup-hooks/separate-debug-info.sh ] else []);
 
     in
-      assert licenseAllowed attrs;
+
+      # Throw an error if trying to evaluate an non-valid derivation
+      assert let v = checkValidity attrs;
+             in if !v.valid
+               then throwEvalHelp (removeAttrs v ["valid"])
+               else true;
 
       lib.addPassthru (derivation (
         (removeAttrs attrs