From 2ea12938b987069eb884ea6df25d194c34e8127f Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 21 Apr 2025 18:51:52 -0400 Subject: [PATCH 1/4] apple-sdk: fix broken symlink check --- .../ap/apple-sdk/common/add-core-symbolication.nix | 1 - pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix | 8 ++++++-- pkgs/by-name/ap/apple-sdk/package.nix | 6 ------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/ap/apple-sdk/common/add-core-symbolication.nix b/pkgs/by-name/ap/apple-sdk/common/add-core-symbolication.nix index 68704a0d4a4c..10935377cd22 100644 --- a/pkgs/by-name/ap/apple-sdk/common/add-core-symbolication.nix +++ b/pkgs/by-name/ap/apple-sdk/common/add-core-symbolication.nix @@ -42,7 +42,6 @@ in self: super: { buildPhase = super.buildPhase or "" + '' mkdir -p System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/Headers - ln -s A System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/Current ln -s Versions/Current/Headers System/Library/PrivateFrameworks/CoreSymbolication.framework/Headers cp '${CoreSymbolication}/include/'*.h System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/Headers ''; diff --git a/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix b/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix index f993441c757e..3a07fe78d803 100644 --- a/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix +++ b/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix @@ -38,11 +38,15 @@ self: super: { # Include `libtool` in the toolchain, so `xcrun -find libtool` can find it without requiring `cctools.libtool` # as a `nativeBuildInput`. mkdir -p "$toolchainsPath/usr/bin" - ln -s '${cctools.libtool}/bin/${stdenv.cc.targetPrefix}libtool' "$toolchainsPath/usr/bin/libtool" + if [ -e '${cctools.libtool}/bin/${stdenv.cc.targetPrefix}libtool' ]; then + ln -s '${cctools.libtool}/bin/${stdenv.cc.targetPrefix}libtool' "$toolchainsPath/usr/bin/libtool" + fi # Include additional binutils required by some packages (such as Chromium). for tool in lipo nm otool size strip; do - ln -s '${darwin.binutils-unwrapped}/bin/${stdenv.cc.targetPrefix}'$tool "$toolchainsPath/usr/bin/$tool" + if [ -e '${darwin.binutils-unwrapped}/bin/${stdenv.cc.targetPrefix}'$tool ]; then + ln -s '${darwin.binutils-unwrapped}/bin/${stdenv.cc.targetPrefix}'$tool "$toolchainsPath/usr/bin/$tool" + fi done ''; } diff --git a/pkgs/by-name/ap/apple-sdk/package.nix b/pkgs/by-name/ap/apple-sdk/package.nix index 04b32f07a642..1633010d4f3d 100644 --- a/pkgs/by-name/ap/apple-sdk/package.nix +++ b/pkgs/by-name/ap/apple-sdk/package.nix @@ -58,12 +58,6 @@ stdenvNoCC.mkDerivation ( dontConfigure = true; - # TODO(@connorbaker): - # This is a quick fix unblock builds broken by https://github.com/NixOS/nixpkgs/pull/370750. - # Fails due to a reflexive symlink: - # $out/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/A - dontCheckForBrokenSymlinks = true; - strictDeps = true; setupHooks = [ From 475f17b86511588080ce61cfcb2c36a9a243a868 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 21 Apr 2025 18:51:52 -0400 Subject: [PATCH 2/4] apple-sdk: link CUPS headers into the sysroot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not having the CUPS headers in the sysroot causes problems for Swift’s module importer when it tries to import AppKit, which depends on CUPS headers. The module importer is effectively an unwrapped Clang, so the headers need to be symlinked there instead of just propagated. --- pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix | 9 ++++++--- pkgs/stdenv/darwin/default.nix | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix b/pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix index fe58181980b6..f9551b5b9bad 100644 --- a/pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix +++ b/pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix @@ -56,16 +56,19 @@ self: super: { darwin.libsbuf # Shipped with the SDK only as a library with no headers (lib.getLib darwin.libutil) - # Required by some SDK headers - cupsHeaders ] # x86_64-darwin links the object files from Csu when targeting very old releases ++ lib.optionals stdenvNoCC.hostPlatform.isx86_64 [ darwin.Csu ]; # The Darwin module for Swift requires certain headers to be included in the SDK (and not just be propagated). buildPhase = super.buildPhase or "" + '' - for header in '${lib.getDev libiconv}/include/'* '${lib.getDev ncurses}/include/'*; do + for header in '${lib.getDev libiconv}/include/'* '${lib.getDev ncurses}/include/'* '${cupsHeaders}/include/'*; do ln -s "$header" "usr/include/$(basename "$header")" done ''; + + # Exported to allow the headers to pass the requisites check in the stdenv bootstrap. + passthru = (super.passthru or { }) // { + cups-headers = cupsHeaders; + }; } diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 0edf63dbc71e..0a5a29fad85b 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -1121,6 +1121,7 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check with prevStage; [ apple-sdk + apple-sdk.cups-headers bashNonInteractive bzip2.bin bzip2.out From 8b9d58978473e168bf42f4a116fa514da2d20e10 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 21 Apr 2025 18:51:52 -0400 Subject: [PATCH 3/4] apple-sdk: improve compatibility with Swift Build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swift Build requires additional fields in `MacOSX.platform/Info.plist`, or it won’t recognize the SDK as being from Xcode. Having it recognize the SDK as from Xcode is required for it to use the SDK at all. --- pkgs/by-name/ap/apple-sdk/common/plists.nix | 19 ++++++++++++++++--- .../ap/apple-sdk/common/propagate-xcrun.nix | 3 ++- pkgs/by-name/ap/apple-sdk/package.nix | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/ap/apple-sdk/common/plists.nix b/pkgs/by-name/ap/apple-sdk/common/plists.nix index 33bb1f134c12..70184d89429b 100644 --- a/pkgs/by-name/ap/apple-sdk/common/plists.nix +++ b/pkgs/by-name/ap/apple-sdk/common/plists.nix @@ -2,15 +2,28 @@ lib, stdenvNoCC, xcodePlatform, + sdkVersion, }: let inherit (lib.generators) toPlist; - Info = { - CFBundleIdentifier = "com.apple.platform.${lib.toLower xcodePlatform}"; - Type = "Platform"; + Info = rec { + CFBundleIdentifier = "com.apple.platform.${Name}"; + DefaultProperties = { + COMPRESS_PNG_FILES = "NO"; + DEPLOYMENT_TARGET_SETTING_NAME = stdenvNoCC.hostPlatform.darwinMinVersionVariable; + STRIP_PNG_TEXT = "NO"; + }; + Description = if stdenvNoCC.hostPlatform.isMacOS then "macOS" else "iOS"; + FamilyDisplayName = Description; + FamilyIdentifier = lib.toLower xcodePlatform; + FamilyName = Description; + Identifier = CFBundleIdentifier; + MinimumSDKVersion = stdenvNoCC.hostPlatform.darwinMinVersion; Name = lib.toLower xcodePlatform; + Type = "Platform"; + Version = sdkVersion; }; # These files are all based off of Xcode spec files found in diff --git a/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix b/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix index 3a07fe78d803..ff0094df60e0 100644 --- a/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix +++ b/pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix @@ -3,11 +3,12 @@ pkgsBuildHost, stdenv, stdenvNoCC, + sdkVersion, }: let plists = import ./plists.nix { - inherit lib stdenvNoCC; + inherit lib stdenvNoCC sdkVersion; xcodePlatform = if stdenvNoCC.hostPlatform.isMacOS then "MacOSX" else "iPhoneOS"; }; inherit (pkgsBuildHost) darwin cctools xcbuild; diff --git a/pkgs/by-name/ap/apple-sdk/package.nix b/pkgs/by-name/ap/apple-sdk/package.nix index 1633010d4f3d..f05b4c13d343 100644 --- a/pkgs/by-name/ap/apple-sdk/package.nix +++ b/pkgs/by-name/ap/apple-sdk/package.nix @@ -41,7 +41,7 @@ let # Avoid infinite recursions by not propagating certain packages, so they can themselves build with the SDK. ++ lib.optionals (!enableBootstrap) [ (callPackage ./common/propagate-inputs.nix { }) - (callPackage ./common/propagate-xcrun.nix { }) + (callPackage ./common/propagate-xcrun.nix { inherit sdkVersion; }) ] # This has to happen last. ++ [ From c93f6d5545b3c5615129173ab61a81982d64c725 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 21 Apr 2025 18:51:52 -0400 Subject: [PATCH 4/4] apple-sdk: reduce spurious warnings when using SwiftPM SwiftPM adds several SDK paths to the search path by default. Creating empty paths in the SDK silences those warnings and reduces log spam. --- pkgs/by-name/ap/apple-sdk/package.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/by-name/ap/apple-sdk/package.nix b/pkgs/by-name/ap/apple-sdk/package.nix index f05b4c13d343..2a0dabd97ae0 100644 --- a/pkgs/by-name/ap/apple-sdk/package.nix +++ b/pkgs/by-name/ap/apple-sdk/package.nix @@ -90,6 +90,11 @@ stdenvNoCC.mkDerivation ( ln -s "${sdkName}" "$sdkpath/MacOSX${sdkMajor}.sdk" ln -s "${sdkName}" "$sdkpath/MacOSX.sdk" + # Swift adds these locations to its search paths. Avoid spurious warnings by making sure they exist. + mkdir -p "$platformPath/Developer/Library/Frameworks" + mkdir -p "$platformPath/Developer/Library/PrivateFrameworks" + mkdir -p "$platformPath/Developer/usr/lib" + runHook postInstall '';