Skip to content

Don't trigger the evaluation of apple-sdk in Linux stdenv - #409574

Merged
reckenrode merged 1 commit into
NixOS:masterfrom
zhaofengli:dont-eval-apple-sdk-in-linux-stdenv
May 22, 2025
Merged

reckenrode merged 1 commit into
NixOS:masterfrom
zhaofengli:dont-eval-apple-sdk-in-linux-stdenv

Conversation

@zhaofengli

Copy link
Copy Markdown
Member

During the Apple SDK revamp of #346043, cc-wrapper and bintools-wrapper were modified to automatically add a fallback SDK if $DEVELOPER_DIR is not set. However, because of the order of the && operands, apple-sdk is always evaluated even when it's not needed.

Let's flip the && operands so we only trigger the evaluation when targeting Darwin. This should speed things up too.

Example

Apply this simple patch:

diff --git a/pkgs/by-name/ap/apple-sdk/package.nix b/pkgs/by-name/ap/apple-sdk/package.nix
index 04b32f07a642..67e76d634d1c 100644
--- a/pkgs/by-name/ap/apple-sdk/package.nix
+++ b/pkgs/by-name/ap/apple-sdk/package.nix
@@ -46,6 +46,7 @@ let
     # This has to happen last.
     ++ [
       (callPackage ./common/run-build-phase-hooks.nix { })
+      (self: super: builtins.trace "SDK hash: ${super.src.outputHash}" super)
     ]
   );
 in

And watch everything explode on Linux while it tries to call fetchSDK with the bootstrap fetchurl:

$ nix-instantiate --system x86_64-linux -A hello
error:
       … while evaluating r
         at /home/zhaofeng/Git/nixpkgs/pkgs/top-level/default.nix:91:11:
           90|       (x: throwIfNot (lib.isFunction x) "All crossOverlays passed to nixpkgs must be functions.")
           91|       (r: r)
             |           ^
           92|       crossOverlays;

       … while evaluating cur
         at /home/zhaofeng/Git/nixpkgs/pkgs/stdenv/booter.nix:80:5:
           79|     in
           80|     cur;
             |     ^
           81|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: function 'anonymous lambda' called with unexpected arguments 'version', 'pname', 'nativeBuildInputs', 'recursiveHash' and 'postFetch'
       at /home/zhaofeng/Git/nixpkgs/pkgs/build-support/fetchurl/boot.nix:7:1:
            6|
            7| {
             | ^
            8|   url ? builtins.head urls,

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

During the Apple SDK revamp of NixOS#346043, cc-wrapper and bintools-wrapper
were modified to automatically add a fallback SDK if $DEVELOPER_DIR is
not set [^1]. However, because of the order of the && operands,
apple-sdk is always evaluated even when it's not needed.

Flip the && operands so we only trigger the evaluation when targeting
Darwin.

[^1]: 51755b0
@nix-owners
nix-owners Bot requested a review from Ericson2314 May 21, 2025 23:15
@github-actions github-actions Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 21, 2025

@reckenrode reckenrode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Let’s backport this to 24.12 and 25.05.

@reckenrode
reckenrode merged commit 4fbe10f into NixOS:master May 22, 2025
@nixpkgs-ci

nixpkgs-ci Bot commented May 22, 2025

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-24.11:

@nixpkgs-ci

nixpkgs-ci Bot commented May 22, 2025

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-25.05:

@nixpkgs-ci nixpkgs-ci Bot added the 8.has: port to stable This PR already has a backport to the stable release. label May 22, 2025
@zhaofengli
zhaofengli deleted the dont-eval-apple-sdk-in-linux-stdenv branch May 23, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants