summary refs log tree commit diff
path: root/pkgs/stdenv/generic/default.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2015-11-27 20:49:26 +0100
committerProfpatsch <mail@profpatsch.de>2015-11-27 21:56:28 +0100
commitee07543ccd9422a82b248d283946c75a72003a81 (patch)
tree0e979d210531595efe51b0ac849bb7a20130b068 /pkgs/stdenv/generic/default.nix
parentc6932509b881a12867b7e1897c6b69ee991e98bd (diff)
downloadnixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar.gz
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar.bz2
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar.lz
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar.xz
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.tar.zst
nixpkgs-ee07543ccd9422a82b248d283946c75a72003a81.zip
stdenv: `licenseAllowed` -> `checkValidity`
Rename and make it a true function (that can be re-used and could be
moved to the library).
Diffstat (limited to 'pkgs/stdenv/generic/default.nix')
-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 246ca3696d5..1a2ca5038b2 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