From e5e5fd10b798d292ab981385d1e4c6cbb3699f53 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 13 Jun 2023 00:17:16 +0300 Subject: [PATCH 1/3] stdenv: fix crossSystem localSystem comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this appears to fix the following issue for some reason ``` nix-repl> (import ./. { localSystem.system = "x86_64-linux"; crossSystem.system = "x86_64-linux"; }).bash «derivation /nix/store/5lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv» nix-repl> (import ./. { localSystem.system = "x86_64-linux"; crossSystem = "x86_64-linux"; }).bash «derivation /nix/store/1whiq03rsfrmch2ds3jhyqjaczfz97lb-bash-5.2-p15-x86_64-unknown-linux-gnu.drv» ``` fixed ``` nix-repl> (import ./. { localSystem.system = "x86_64-linux"; crossSystem = "x86_64-linux"; }).bash «derivation /nix/store/5lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv» ``` --- pkgs/stdenv/default.nix | 2 +- pkgs/stdenv/linux/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 7a2ad665e09d7..bc61a2ab174d9 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -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 diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 9cfe21e3640d4..fb0bc94ad4ca3 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -95,7 +95,7 @@ in files }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; let inherit (localSystem) system; From 4e32b2a8b452e3e3ca9a33e4f2b8108524c3896f Mon Sep 17 00:00:00 2001 From: Artturin Date: Thu, 15 Jun 2023 23:37:44 +0300 Subject: [PATCH 2/3] treewide: use lib.systems.equals to compare systems --- pkgs/stdenv/custom/default.nix | 2 +- pkgs/stdenv/darwin/default.nix | 2 +- pkgs/stdenv/freebsd/default.nix | 2 +- pkgs/stdenv/native/default.nix | 2 +- pkgs/stdenv/nix/default.nix | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/custom/default.nix b/pkgs/stdenv/custom/default.nix index 4c7380118f7d5..7f1fe3e404235 100644 --- a/pkgs/stdenv/custom/default.nix +++ b/pkgs/stdenv/custom/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays, crossOverlays ? [] }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; let bootStages = import ../. { diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index a83f727cfe17c..a51e7622d5357 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -36,7 +36,7 @@ } }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; let inherit (localSystem) system; diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index de66085876052..c284c9b8948ef 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays, crossOverlays ? [] }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; let inherit (localSystem) system; fetchURL = import ; trivialBuilder = (import ./trivial-builder.nix); diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index bae4ff2c93b26..38ff1f9c3bcdc 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays, crossOverlays ? [] }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; let inherit (localSystem) system; diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index e9e9936ccd801..7089fb8f1bb56 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -4,7 +4,7 @@ , ... }: -assert crossSystem == localSystem; +assert lib.systems.equals crossSystem localSystem; bootStages ++ [ (prevStage: { From 87c34c6f266caacd11dd619c8275b9e78484007e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 16 Jun 2023 19:33:05 +0200 Subject: [PATCH 3/3] pkgs/top-level: Improve crossSystem equality early on This is a workaround that lets us use `==` on systems despite the functions that would make `==` always return `false` if a workaround like this is not applied. The real solution is to either use `lib.systems.equals` for all such comparisons, or to remove all functions from the elaborated systems. --- pkgs/top-level/default.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index ba00e78ce2e62..addf7b39a8c95 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -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 + 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 {}).stdenv.hostPlatform + # != (import {}).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