Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ with pkgs;

config = callPackage ./config.nix { };

top-level = callPackage ./top-level { };

haskell = callPackage ./haskell { };

hooks = callPackage ./hooks { };
Expand Down
47 changes: 47 additions & 0 deletions pkgs/test/top-level/default.nix
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 14 additions & 2 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down