summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/test/default.nix17
-rw-r--r--pkgs/test/pkg-config-packages.nix24
2 files changed, 39 insertions, 2 deletions
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index 8ff0e163395..82134b051d4 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -51,7 +51,22 @@ with pkgs;
 
   php = recurseIntoAttrs (callPackages ./php {});
 
-  pkg-configPackages = callPackage ./pkg-config-packages.nix { };
+  pkg-configPackages =
+    let
+      # pkg-configPackages test needs a Nixpkgs with allowUnsupportedPlatform
+      # in order to filter out the unsupported packages without throwing any errors
+      # tryEval would be too fragile, masking different problems as if they're
+      # unsupported platform problems.
+      allPkgs = import ../top-level {
+        system = pkgs.stdenv.hostPlatform.system;
+        localSystem = pkgs.stdenv.hostPlatform.system;
+        config = {
+          allowUnsupportedSystem = true;
+        };
+        overlays = [];
+      };
+    in
+    allPkgs.callPackage ./pkg-config-packages.nix { };
 
   rustCustomSysroot = callPackage ./rust-sysroot {};
   buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { };
diff --git a/pkgs/test/pkg-config-packages.nix b/pkgs/test/pkg-config-packages.nix
index d61902cf1f4..8e4e5253f9b 100644
--- a/pkgs/test/pkg-config-packages.nix
+++ b/pkgs/test/pkg-config-packages.nix
@@ -1,6 +1,8 @@
 { lib, pkg-config, pkg-configPackages, runCommand }:
 let
-  allTests = lib.mapAttrs (k: v: if v == null then null else makePkgConfigTest k v) pkg-configPackages;
+  inherit (lib.strings) escapeNixIdentifier;
+
+  allTests = lib.mapAttrs (k: v: if v == null then null else makePkgConfigTestMaybe k v) pkg-configPackages;
 
   # nix-build rejects attribute names with periods
   # This will build those regardless.
@@ -10,6 +12,26 @@ let
     touch $out
   '';
 
+  makePkgConfigTestMaybe = moduleName: pkg:
+    if ! lib.isDerivation pkg
+    then
+      throw "pkg-config module `${escapeNixIdentifier moduleName}` is not defined to be a derivation. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs."
+
+    else if ! pkg?meta.unsupported
+    then
+      throw "pkg-config module `${escapeNixIdentifier moduleName}` does not have a `meta.unsupported` attribute. This can't be right. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs."
+
+    else if pkg.meta.unsupported
+    then
+      # We return `null` instead of doing a `filterAttrs`, because with
+      # `filterAttrs` the evaluator would not be able to return the attribute
+      # set without first evaluating all of the attribute _values_. This would
+      # be rather expensive, and severly slow down the use case of getting a
+      # single test, which we want to do in `passthru.tests`, or interactively.
+      null
+
+    else makePkgConfigTest moduleName pkg;
+
   makePkgConfigTest = moduleName: pkg: runCommand "check-pkg-config-${moduleName}" {
     nativeBuildInputs = [ pkg-config ];
     buildInputs = [ pkg ];