Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: fix crossSystem localSystem comparison #237427

Closed
wants to merge 3 commits into from
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: 1 addition & 1 deletion pkgs/stdenv/custom/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays, crossOverlays ? []
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;

let
bootStages = import ../. {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;

let
inherit (localSystem) system;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let

# Select the appropriate stages for the platform `system'.
in
if crossSystem != localSystem || crossOverlays != [] then stagesCross
if !lib.systems.equals crossSystem localSystem || crossOverlays != [] then stagesCross
else if config ? replaceStdenv then stagesCustom
else if localSystem.isLinux then stagesLinux
else if localSystem.isDarwin then stagesDarwin
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/freebsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays, crossOverlays ? []
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;
let inherit (localSystem) system;
fetchURL = import <nix/fetchurl.nix>;
trivialBuilder = (import ./trivial-builder.nix);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
in files
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;

let
inherit (localSystem) system;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/native/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays, crossOverlays ? []
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;

let
inherit (localSystem) system;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
, ...
}:

assert crossSystem == localSystem;
assert lib.systems.equals crossSystem localSystem;

bootStages ++ [
(prevStage: {
Expand Down
21 changes: 17 additions & 4 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,24 @@ in let

localSystem = lib.systems.elaborate args.localSystem;

# Condition preserves sharing which in turn affects equality.
# Condition preserves sharing which in turn improves equality within this Nixpkgs.
#
# Use `lib.systems.equals` to compare systems.
crossSystem =
if crossSystem0 == null || crossSystem0 == args.localSystem
then localSystem
else lib.systems.elaborate crossSystem0;
if crossSystem0 == null || lib.systems.equals crossSystem0 args.localSystem
Copy link
Member Author

@Artturin Artturin Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://gist.github.com/GrahamcOfBorg/1e800ef80702f76206b24b79c9f0dc1d

error: value is a string while a set was expected

crossSystem0 and args.localSystem haven't been elaborated so they're possibly just strings

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crossSystem0 and args.localSystem haven't been elaborated so they're possibly just strings

IMHO we should elaborate unconditionally here.

then
# This makes `crossSystem == localSystem` so that comparisons with `==`
# work **in the context of this single Nixpkgs invocation**.
#
# Equality is still broken when comparing between two Nixpkgs instances:
#
# (import <nixpkgs> {}).stdenv.hostPlatform
# != (import <nixpkgs> {}).stdenv.hostPlatform
localSystem
else
# It's a truly different system, so no significant equality problems.
# We only have to elaborate it, just like we did for localSystem above.
lib.systems.elaborate crossSystem0;

# Allow both:
# { /* the config */ } and
Expand Down