about summary refs log tree commit diff
path: root/pkgs/stdenv/generic
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@yahoo.com>2018-03-18 13:51:03 -0400
committerGitHub <noreply@github.com>2018-03-18 13:51:03 -0400
commit2fa2197a96fec6a15623bfab96b27d2b1fbe8949 (patch)
tree07fc5a426396813f0afc123d2a3860dc9331bad7 /pkgs/stdenv/generic
parent38c4c3acd7d8a7eb31672e83cec04cc17afdbac5 (diff)
parenteae19f3c28503a8623b0fee10bfb0b3322122637 (diff)
downloadnixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar.gz
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar.bz2
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar.lz
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar.xz
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.tar.zst
nixlib-2fa2197a96fec6a15623bfab96b27d2b1fbe8949.zip
Merge pull request #34444 from obsidiansystems/meta-check
lib: Fix #30902
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r--pkgs/stdenv/generic/check-meta.nix33
-rw-r--r--pkgs/stdenv/generic/make-derivation.nix7
2 files changed, 22 insertions, 18 deletions
diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix
index a1878dc01367..4774d7602437 100644
--- a/pkgs/stdenv/generic/check-meta.nix
+++ b/pkgs/stdenv/generic/check-meta.nix
@@ -1,11 +1,9 @@
 # Checks derivation meta and attrs for problems (like brokenness,
 # licenses, etc).
 
-{ lib, config, system, meta, derivationArg, mkDerivationArg }:
+{ lib, config, hostPlatform, meta }:
 
 let
-  attrs = mkDerivationArg; # TODO: probably get rid of passing this one
-
   # See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
   # for why this defaults to false, but I (@copumpkin) want to default it to true soon.
   shouldCheckMeta = config.checkMeta or false;
@@ -123,7 +121,7 @@ let
 
       '';
 
-  handleEvalIssue = { reason , errormsg ? "" }:
+  handleEvalIssue = attrs: { reason , errormsg ? "" }:
     let
       msg = ''
         Package ‘${attrs.name or "«name-missing»"}’ in ${pos_str} ${errormsg}, refusing to evaluate.
@@ -146,7 +144,7 @@ let
     license = either (listOf lib.types.attrs) (either lib.types.attrs str);
     maintainers = listOf (attrsOf str);
     priority = int;
-    platforms = listOf str;
+    platforms = listOf (either str lib.systems.parsed.types.system);
     hydraPlatforms = listOf str;
     broken = bool;
 
@@ -175,6 +173,11 @@ let
     else "key '${k}' is unrecognized; expected one of: \n\t      [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
   checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
 
+  checkPlatform = attrs: let
+      raw = attrs.meta.platforms;
+      uniform = map (x: if builtins.isString x then { system = x; } else { parsed = x; }) raw;
+    in lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
+
   # Check if a derivation is valid, that is whether it passes checks for
   # e.g brokenness or license.
   #
@@ -188,19 +191,21 @@ let
       { valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
     else if !allowBroken && attrs.meta.broken or false then
       { valid = false; reason = "broken"; errormsg = "is marked as broken"; }
-    else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
-      { valid = false; reason = "broken"; errormsg = "is not supported on ‘${system}’"; }
+    else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !(checkPlatform attrs) then
+      { valid = false; reason = "broken"; errormsg = "is not supported on ‘${hostPlatform.config}’"; }
     else if !(hasAllowedInsecure attrs) then
       { valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
     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; };
 
-   validity = checkValidity attrs;
+  assertValidity = attrs: let
+      validity = checkValidity attrs;
+    in validity // {
+      # Throw an error if trying to evaluate an non-valid derivation
+      handled = if !validity.valid
+        then handleEvalIssue attrs (removeAttrs validity ["valid"])
+        else true;
+  };
 
-in validity // {
-  # Throw an error if trying to evaluate an non-valid derivation
-  handled = if !validity.valid
-    then handleEvalIssue (removeAttrs validity ["valid"])
-    else true;
-}
+in assertValidity
diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix
index e8f78d7401f1..46df958b8396 100644
--- a/pkgs/stdenv/generic/make-derivation.nix
+++ b/pkgs/stdenv/generic/make-derivation.nix
@@ -204,12 +204,11 @@ rec {
         });
 
       validity = import ./check-meta.nix {
-        inherit lib config meta derivationArg;
-        mkDerivationArg = attrs;
+        inherit lib config meta;
         # Nix itself uses the `system` field of a derivation to decide where
         # to build it. This is a bit confusing for cross compilation.
-        inherit (stdenv) system;
-      };
+        inherit (stdenv) hostPlatform;
+      } 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