Skip to content
Open
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
17 changes: 17 additions & 0 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ let
windows = "Windows";
cygwin = "CYGWIN_NT";
darwin = "Darwin";
ios = "Darwin";
netbsd = "NetBSD";
freebsd = "FreeBSD";
openbsd = "OpenBSD";
Expand Down Expand Up @@ -354,10 +355,24 @@ let
darwinPlatform =
if final.isMacOS then
"macos"
else if final.isiOSSimulator then
"ios-simulator"
else if final.isiOS then
"ios"
else
null;

xcodePlatform =
args.xcodePlatform or (
if final.isMacOS then
"MacOSX"
else if final.isiOSSimulator then
"iPhoneSimulator"
else if final.isiOS then
"iPhoneOS"
else
null
);
# The canonical name for this attribute is darwinSdkVersion, but some
# platforms define the old name "sdkVer".
darwinSdkVersion = final.sdkVer or "14.4";
Expand Down Expand Up @@ -507,6 +522,8 @@ let
# TODO: Somehow ensure that Rust actually *uses* the correct ABI, and not just a libc-based default.
if (lib.strings.hasPrefix "powerpc" cpu.name) && (lib.strings.hasPrefix "gnuabielfv" abi.name) then
"gnu"
else if abi.name == "simulator" then
"sim"
else
abi.name;

Expand Down
12 changes: 4 additions & 8 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,17 @@ rec {

iphone64 = {
config = "arm64-apple-ios";
# config = "aarch64-apple-darwin14";
darwinSdkVersion = "14.3";
darwinMinVersion = "14";
xcodeVer = "12.3";
xcodePlatform = "iPhoneOS";
useiOSPrebuilt = true;
# useiOSPrebuilt = true;
};

iphone64-simulator = {
config = "x86_64-apple-ios";
# config = "x86_64-apple-darwin14";
config = "aarch64-apple-ios-simulator";
darwinSdkVersion = "14.3";
xcodeVer = "12.3";
xcodePlatform = "iPhoneSimulator";
darwinPlatform = "ios-simulator";
useiOSPrebuilt = true;
# useiOSPrebuilt = true;
};

aarch64-darwin = {
Expand Down
4 changes: 4 additions & 0 deletions lib/systems/inspect.nix
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ rec {
isiOS = {
kernel = kernels.ios;
};
isiOSSimulator = {
kernel = kernels.ios;
abi = abis.simulator;
};
isLinux = {
kernel = kernels.linux;
};
Expand Down
2 changes: 2 additions & 0 deletions lib/systems/parse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ rec {
};
uclibc = { };

simulator = { };

unknown = { };
};

Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ stdenvNoCC.mkDerivation {
darwinMinVersion
darwinMinVersionVariable
;
xcodePlatform = targetPlatform.xcodePlatform or "MacOSX";
}
// lib.optionalAttrs (stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null) {
# Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`.
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ stdenvNoCC.mkDerivation {
// lib.mapAttrs (_: lib.optionalString targetPlatform.isDarwin) {
# These will become empty strings when not targeting Darwin.
inherit (targetPlatform) darwinMinVersion darwinMinVersionVariable;
xcodePlatform = targetPlatform.xcodePlatform or "MacOSX";
}
// lib.optionalAttrs (stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null) {
# Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`.
Expand Down
7 changes: 7 additions & 0 deletions pkgs/build-support/cc-wrapper/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,12 @@ export CXX${role_post}=@named_cxx@
: ${NIX_HARDENING_ENABLE="@default_hardening_flags_str@"}
export NIX_HARDENING_ENABLE

# Export Darwin deployment target (e.g. IPHONEOS_DEPLOYMENT_TARGET) so tools
# like cc-rs that invoke the compiler directly can see the correct minimum
# version without going through the wrapper.
if [[ -n "@darwinMinVersionVariable@" ]]; then
export @darwinMinVersionVariable@=${@darwinMinVersionVariable@:-@darwinMinVersion@}
fi

# No local scope in sourced file
unset -v role_post
21 changes: 17 additions & 4 deletions pkgs/build-support/wrapper-common/darwin-sdk-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ accumulateRoles
# which is a signal that we're targetting darwin.
if [[ "@darwinMinVersion@" ]]; then
# `DEVELOPER_DIR` is used to dynamically locate libSystem (and the SDK frameworks) based on the SDK at that path.
mangleVarSingle DEVELOPER_DIR ${role_suffixes[@]+"${role_suffixes[@]}"}

# Allow wrapped compilers to do something useful when no `DEVELOPER_DIR` is set, which can happen when
# the compiler is run outside of a stdenv or intentionally in an environment with no environment variables set.
export DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@:-@fallback_sdk@}
export DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@:-${DEVELOPER_DIR:-@fallback_sdk@}}

# When cross-compiling (e.g. macOS → iOS), the environment may have DEVELOPER_DIR set to a
# different platform's SDK (e.g. iPhoneOS). If the expected platform directory doesn't exist
# in DEVELOPER_DIR, fall back to the hardcoded SDK for this wrapper.
if [[ ! -d "$DEVELOPER_DIR/Platforms/@xcodePlatform@.platform" ]]; then
export DEVELOPER_DIR=@fallback_sdk@
fi

# Only mangle DEVELOPER_DIR after resolving the correct value, so that
# mangleVarSingle stores the final (platform-correct) SDK path, not a
# polluted value from a cross-compilation peer SDK's setup hook.
mangleVarSingle DEVELOPER_DIR ${role_suffixes[@]+"${role_suffixes[@]}"}

# xcbuild needs `SDKROOT` to be the name of the SDK, which it sets in its own wrapper,
# but compilers expect it to point to the absolute path.
export SDKROOT="$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
export SDKROOT="$DEVELOPER_DIR/Platforms/@xcodePlatform@.platform/Developer/SDKs/@xcodePlatform@.sdk"

# Export the deployment target (e.g. IPHONEOS_DEPLOYMENT_TARGET, MACOSX_DEPLOYMENT_TARGET)
export @darwinMinVersionVariable@=${@darwinMinVersionVariable@:-@darwinMinVersion@}
fi
10 changes: 7 additions & 3 deletions pkgs/by-name/ap/apple-sdk/common/derivation-options.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{ lib, config }:
{
lib,
config,
sdkPlatform,
}:

self: super: {
preBuild = super.preBuild or "" + ''
platformPath=$out/Platforms/MacOSX.platform
platformPath=$out/Platforms/${sdkPlatform}.platform
sdkpath=$platformPath/Developer/SDKs
'';

preInstall = super.preInstall or "" + ''
platformPath=$out/Platforms/MacOSX.platform
platformPath=$out/Platforms/${sdkPlatform}.platform
sdkpath=$platformPath/Developer/SDKs
'';
}
41 changes: 41 additions & 0 deletions pkgs/by-name/ap/apple-sdk/common/fetch-ios-sdk.nix
Comment thread
insipx marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
lib,
stdenvNoCC,
buildPackages,
}:

{
sdkPlatform,
version,
}:

stdenvNoCC.mkDerivation {
pname = "${sdkPlatform}-SDK";
inherit version;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we add __contentAddressed = true; to allow recreating this derivations from a globally installed version of Xcode? On many CI platforms Xcode is already available globally in the builder images (on GitHub Actions every Xcode version is located on a different path so reproducibility won't be a problem). Adding Xcode to Nix store manually takes too long and building this derivation outside the store will be very quick. With a content addressable derivation I can imagine copy pasting the install phase from here in a custom script which depends on global Xcode and just adds the result to the store.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for your review! I'll have to look into content addressable derivations, frankly I didn't know that was possible when making this PR. I'm happy to do that if it speeds things up though, since I do have a CI workflow with xcode that takes 2min to the CI run purely from importing xcode to the nix store


src = buildPackages.darwin.xcode;

This comment was marked as resolved.

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.

The Xcode package already has its license set to unfree, which should cover that.

The license on apple-sdk could be set conditionally based on iOS using xcode.meta.license, but it’s deliberate (based on historical practice in Nixpkgs for SDK frameworks) that it’s absent on macOS. On macOS, the SDK is not sourced from Xcode (or else we’d have access to several tools that we’re missing). #477742 has some discussion the last time adding the license was to the package was tried.


dontConfigure = true;
dontBuild = true;

installPhase = ''
runHook preInstall

sdkPath="Contents/Developer/Platforms/${sdkPlatform}.platform/Developer/SDKs/${sdkPlatform}.sdk"

# Extract the iOS SDK from the nested Xcode.app such that it
# matches the fetched macOS SDKs
if [ ! -d "$sdkPath" ]; then
echo "Error: iOS SDK not found at $sdkPath in Xcode.app"
echo "Available platforms:"
ls -la Contents/Developer/Platforms/ || true
exit 1
fi

mkdir -p "$out"
cp -rd "$sdkPath"/* "$out/"
rm -rf "$out/usr/bin" "$out/usr/share" 2>/dev/null || true

runHook postInstall
'';
}
8 changes: 5 additions & 3 deletions pkgs/by-name/ap/apple-sdk/common/propagate-inputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
lib,
cups,
darwin,
db,
libiconv,
ncurses,
stdenv,
stdenvNoCC,
xcbuild,
}:

let
Expand All @@ -28,7 +26,11 @@ let
buildInputs = [ darwin.libresolv ]; # The `configure` script requires libresolv headers.

# CUPS’s configure script fails to find `ar` when cross-compiling.
configureFlags = [ "ac_cv_path_AR=${stdenv.cc.targetPrefix}ar" ];
configureFlags = [
"ac_cv_path_AR=${stdenv.cc.targetPrefix}ar"
]
# headers-only install, ios cross-compile cannot find tls libraries.
++ lib.optional stdenv.hostPlatform.isiOS "--with-tls=no";

installTargets = [ "install-headers" ];

Expand Down
3 changes: 2 additions & 1 deletion pkgs/by-name/ap/apple-sdk/common/propagate-xcrun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
stdenv,
stdenvNoCC,
sdkVersion,
sdkPlatform,
}:

let
plists = import ./plists.nix {
inherit lib stdenvNoCC sdkVersion;
xcodePlatform = if stdenvNoCC.hostPlatform.isMacOS then "MacOSX" else "iPhoneOS";
xcodePlatform = sdkPlatform;
};
inherit (pkgsBuildHost) darwin cctools xcbuild;
in
Expand Down
33 changes: 25 additions & 8 deletions pkgs/by-name/ap/apple-sdk/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in

# Required by various phases
callPackage,
buildPackages,
jq,
llvm,
}:
Expand All @@ -28,11 +29,15 @@ let
sdkVersion = sdkInfo.version;

fetchSDK = callPackage ./common/fetch-sdk.nix { };
sdkPlatform =
if stdenv.hostPlatform.xcodePlatform != null then stdenv.hostPlatform.xcodePlatform else "MacOSX";

phases = lib.composeManyExtensions (
[
lib.optionals stdenv.hostPlatform.isMacOS [
(callPackage ./common/add-core-symbolication.nix { })
(callPackage ./common/derivation-options.nix { })
]
++ [
(callPackage ./common/derivation-options.nix { inherit sdkPlatform; })
(callPackage ./common/passthru-private-frameworks.nix { inherit sdkVersion; })
(callPackage ./common/passthru-source-release-files.nix { })
(callPackage ./common/remove-disallowed-packages.nix { })
Expand All @@ -41,7 +46,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 { inherit sdkVersion; })
(callPackage ./common/propagate-xcrun.nix { inherit sdkVersion sdkPlatform; })
]
# This has to happen last.
++ [
Expand All @@ -54,7 +59,14 @@ stdenvNoCC.mkDerivation (
pname = "apple-sdk";
inherit (sdkInfo) version;

src = fetchSDK sdkInfo;
src =
if stdenv.hostPlatform.isiOS then
(callPackage ./common/fetch-ios-sdk.nix { }) {
inherit sdkPlatform;
version = sdkVersion;
}
else
fetchSDK sdkInfo;

dontConfigure = true;

Expand All @@ -72,13 +84,17 @@ stdenvNoCC.mkDerivation (
"--subst-var-by"
"sdkVersion"
(lib.escapeShellArgs (lib.splitVersion sdkVersion))
"--subst-var-by"
"sdkPlatform"
(lib.escapeShellArgs (lib.splitVersion sdkPlatform))

];
})
];

installPhase =
let
sdkName = "MacOSX${lib.versions.majorMinor sdkVersion}.sdk";
sdkName = "${sdkPlatform}${lib.versions.majorMinor sdkVersion}.sdk";
sdkMajor = lib.versions.major sdkVersion;
in
''
Expand All @@ -87,8 +103,8 @@ stdenvNoCC.mkDerivation (
mkdir -p "$sdkpath"

cp -rd . "$sdkpath/${sdkName}"
ln -s "${sdkName}" "$sdkpath/MacOSX${sdkMajor}.sdk"
ln -s "${sdkName}" "$sdkpath/MacOSX.sdk"
ln -s "${sdkName}" "$sdkpath/${sdkPlatform}${sdkMajor}.sdk"
ln -s "${sdkName}" "$sdkpath/${sdkPlatform}.sdk"

# Swift adds these locations to its search paths. Avoid spurious warnings by making sure they exist.
mkdir -p "$platformPath/Developer/Library/Frameworks"
Expand All @@ -99,7 +115,8 @@ stdenvNoCC.mkDerivation (
'';

passthru = {
sdkroot = finalAttrs.finalPackage + "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk";
sdkroot =
finalAttrs.finalPackage + "/Platforms/${sdkPlatform}.platform/Developer/SDKs/${sdkPlatform}.sdk";
};

__structuredAttrs = true;
Expand Down
3 changes: 2 additions & 1 deletion pkgs/by-name/ap/apple-sdk/setup-hooks/sdk-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ getHostRole
local sdkVersionVar=NIX_APPLE_SDK_VERSION${role_post}
local developerDirVar=DEVELOPER_DIR${role_post}

local platformVar=(@sdkPlatform@)
local sdkVersionArr=(@sdkVersion@)
local sdkVersion
sdkVersion=$(printf "%02d%02d%02d" "${sdkVersionArr[0]-0}" "${sdkVersionArr[1]-0}" "${sdkVersionArr[2]-0}")

if [ "$sdkVersion" -gt "${!sdkVersionVar-000000}" ]; then
export "$developerDirVar"='@out@'
export "$sdkVersionVar"="$sdkVersion"
export "SDKROOT${role_post}"="${!developerDirVar}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
export "SDKROOT${role_post}"="${!developerDirVar}/Platforms/${platformVar}.platform/Developer/SDKs/${platformVar}.sdk"
fi

unset -v role_post developerDirVar sdkVersion sdkVersionArr sdkVersionVar
8 changes: 4 additions & 4 deletions pkgs/by-name/gn/gnu-config/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
# files.

let
rev = "948ae97ca5703224bd3eada06b7a69f40dd15a02";
rev = "a2287c3041a3f2a204eb942e09c015eab00dc7dd";

# Don't use fetchgit as this is needed during Aarch64 bootstrapping
configGuess = fetchurl {
name = "config.guess-${builtins.substring 0 7 rev}";
url = "https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=${rev}";
hash = "sha256-ZByuPAx0xJNU0+3gCfP+vYD+vhUBp3wdn6yNQsxFtss=";
hash = "sha256-UCBc8+xcdhWxf5N6Cle6v07FzQqt49ezzMvl8b+Rp+8=";
};
configSub = fetchurl {
name = "config.sub-${builtins.substring 0 7 rev}";
url = "https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=${rev}";
hash = "sha256-/jovMvuv9XhIcyVJ9I2YP9ZSYCTsLw9ancdcL0NZo6Y=";
hash = "sha256-JrhS91pjdEg2CpVpMUOffoGL9jFQ6q25uFSENHYo0f0=";
};
in
stdenv.mkDerivation {
pname = "gnu-config";
version = "2024-01-01";
version = "2025-07-09";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this version of gnu-config contains updates that include ios-simulator triples, making life easier in nixpkgs for that target


unpackPhase = ''
runHook preUnpack
Expand Down
Loading
Loading