summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Trubach <mr.trubach@icloud.com>2023-09-12 16:55:32 +0300
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2023-09-13 10:05:20 +0000
commit17f77f56875e4d8363445f73ab9393e547ed94f4 (patch)
tree15c664fbd6c22dbe81d617692ace16eac8aa0871
parentMerge pull request #254812 from NixOS/backport-254777-to-release-23.05 (diff)
downloadnixpkgs-origin/backport-254763-to-release-23.05.tar.gz
pkgs/top-level: use lib.systems.equals for crossSystemorigin/backport-254763-to-release-23.05
Fixes otherwise equivalent systems being treated as different by packages that compare `stdenv.*Platform`s using `==` operator. (cherry picked from commit d4063e0330ec9f68037d4dbdd12aec3376e679ba)
-rw-r--r--pkgs/test/default.nix2
-rw-r--r--pkgs/test/top-level/default.nix47
-rw-r--r--pkgs/top-level/default.nix16
3 files changed, 63 insertions, 2 deletions
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index b9d75c790da6..693e10dc65e5 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -25,6 +25,8 @@ with pkgs;
config = callPackage ./config.nix { };
+ top-level = callPackage ./top-level { };
+
haskell = callPackage ./haskell { };
hooks = callPackage ./hooks { };
diff --git a/pkgs/test/top-level/default.nix b/pkgs/test/top-level/default.nix
new file mode 100644
index 000000000000..fdb9fe09a88b
--- /dev/null
+++ b/pkgs/test/top-level/default.nix
@@ -0,0 +1,47 @@
+{ lib, pkgs, ... }:
+let
+ nixpkgsFun = import ../../top-level;
+in
+lib.recurseIntoAttrs {
+ platformEquality =
+ let
+ configsLocal = [
+ # crossSystem is implicitly set to localSystem.
+ {
+ localSystem = { system = "x86_64-linux"; };
+ }
+ {
+ localSystem = { system = "aarch64-linux"; };
+ crossSystem = null;
+ }
+ # Both systems explicitly set to the same string.
+ {
+ localSystem = { system = "x86_64-linux"; };
+ crossSystem = { system = "x86_64-linux"; };
+ }
+ # Vendor and ABI inferred from system double.
+ {
+ localSystem = { system = "aarch64-linux"; };
+ crossSystem = { config = "aarch64-unknown-linux-gnu"; };
+ }
+ ];
+ configsCross = [
+ # GNU is inferred from double, but config explicitly requests musl.
+ {
+ localSystem = { system = "aarch64-linux"; };
+ crossSystem = { config = "aarch64-unknown-linux-musl"; };
+ }
+ # Cross-compile from AArch64 to x86-64.
+ {
+ localSystem = { system = "aarch64-linux"; };
+ crossSystem = { system = "x86_64-unknown-linux-gnu"; };
+ }
+ ];
+
+ pkgsLocal = map nixpkgsFun configsLocal;
+ pkgsCross = map nixpkgsFun configsCross;
+ in
+ assert lib.all (p: p.buildPlatform == p.hostPlatform) pkgsLocal;
+ assert lib.all (p: p.buildPlatform != p.hostPlatform) pkgsCross;
+ pkgs.emptyFile;
+}
diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix
index ba00e78ce2e6..5c224802d5bf 100644
--- a/pkgs/top-level/default.nix
+++ b/pkgs/top-level/default.nix
@@ -61,10 +61,22 @@ in let
localSystem = lib.systems.elaborate args.localSystem;
# Condition preserves sharing which in turn affects equality.
+ #
+ # See `lib.systems.equals` documentation for more details.
+ #
+ # Note that it is generally not possible to compare systems as given in
+ # parameters, e.g. if systems are initialized as
+ #
+ # localSystem = { system = "x86_64-linux"; };
+ # crossSystem = { config = "x86_64-unknown-linux-gnu"; };
+ #
+ # Both systems are semantically equivalent as the same vendor and ABI are
+ # inferred from the system double in `localSystem`.
crossSystem =
- if crossSystem0 == null || crossSystem0 == args.localSystem
+ let system = lib.systems.elaborate crossSystem0; in
+ if crossSystem0 == null || lib.systems.equals system localSystem
then localSystem
- else lib.systems.elaborate crossSystem0;
+ else system;
# Allow both:
# { /* the config */ } and