nixpkgs/pkgs/os-specific/darwin/apple-sdk/default.nix

242 lines
7.5 KiB
Nix
Raw Normal View History

2020-01-13 09:10:23 +00:00
{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib }:
2015-06-20 22:29:42 +00:00
let version = "10.12"; in
# Ensure appleSdkVersion is up to date.
assert stdenv.isDarwin -> stdenv.appleSdkVersion == version;
2015-06-20 22:29:42 +00:00
let
2015-06-22 03:29:33 +00:00
# sadly needs to be exported because security_tool needs it
2015-06-20 22:29:42 +00:00
sdk = stdenv.mkDerivation rec {
pname = "MacOS_SDK";
inherit version;
2015-06-20 22:29:42 +00:00
# This URL comes from https://swscan.apple.com/content/catalogs/others/index-10.12.merged-1.sucatalog, which we found by:
# 1. Google: site:swscan.apple.com and look for a name that seems appropriate for your version
# 2. In the resulting file, search for a file called DevSDK ending in .pkg
# 3. ???
# 4. Profit
2015-06-20 22:29:42 +00:00
src = fetchurl {
2019-11-27 19:17:43 +00:00
url = "http://swcdn.apple.com/content/downloads/33/36/041-90419-A_7JJ4H9ZHO2/xs88ob5wjz6riz7g6764twblnvksusg4ps/DevSDK_OSX1012.pkg";
sha256 = "13xq34sb7383b37hwy076gnhf96prpk1b4087p87xnwswxbrisih";
2015-06-20 22:29:42 +00:00
};
2020-01-13 09:10:23 +00:00
nativeBuildInputs = [ xar cpio python3 pbzx ];
2015-06-20 22:29:42 +00:00
2018-06-09 03:57:36 +00:00
outputs = [ "out" "dev" "man" ];
2015-06-20 22:29:42 +00:00
unpackPhase = ''
xar -x -f $src
'';
installPhase = ''
start="$(pwd)"
mkdir -p $out
cd $out
pbzx -n $start/Payload | cpio -idm
2015-06-20 22:29:42 +00:00
mv usr/* .
rmdir usr
mv System/* .
rmdir System
pushd lib
ln -s -L /usr/lib/libcups*.dylib .
popd
2015-06-20 22:29:42 +00:00
'';
meta = with stdenv.lib; {
description = "Apple SDK ${version}";
maintainers = with maintainers; [ copumpkin ];
platforms = platforms.darwin;
};
};
framework = name: deps: stdenv.mkDerivation {
name = "apple-framework-${name}";
dontUnpack = true;
2015-06-20 22:29:42 +00:00
# because we copy files from the system
preferLocalBuild = true;
disallowedRequisites = [ sdk ];
2015-06-20 22:29:42 +00:00
installPhase = ''
linkFramework() {
local path="$1"
local nested_path="$1"
2015-06-20 22:29:42 +00:00
local dest="$out/Library/Frameworks/$path"
if [ "$path" == "JavaNativeFoundation.framework" ]; then
local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
fi
if [ "$path" == "JavaRuntimeSupport.framework" ]; then
local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaRuntimeSupport.framework"
fi
2015-06-20 22:29:42 +00:00
local name="$(basename "$path" .framework)"
local current="$(readlink "/System/Library/Frameworks/$nested_path/Versions/Current")"
if [ -z "$current" ]; then
current=A
fi
2015-06-20 22:29:42 +00:00
mkdir -p "$dest"
pushd "$dest" >/dev/null
# Keep track of if this is a child or a child rescue as with
# ApplicationServices in the 10.9 SDK
local isChild=0
if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
isChild=1
cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
2018-06-09 03:57:36 +00:00
cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
fi
ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/$name"
ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
2015-06-20 22:29:42 +00:00
if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
ln -s "/System/Library/Frameworks/$nested_path/module.map"
2015-06-20 22:29:42 +00:00
fi
pushd "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current" >/dev/null
2015-06-20 22:29:42 +00:00
local children=$(echo Frameworks/*.framework)
popd >/dev/null
for child in $children; do
childpath="$path/Versions/$current/$child"
linkFramework "$childpath"
done
if [ -d "$dest/Versions/$current" ]; then
mv $dest/Versions/$current/* .
fi
popd >/dev/null
}
linkFramework "${name}.framework"
'';
propagatedBuildInputs = deps;
2017-03-07 21:10:07 +00:00
# don't use pure CF for dylibs that depend on frameworks
setupHook = ./framework-setup-hook.sh;
2017-03-07 21:10:07 +00:00
2017-10-31 11:58:08 +00:00
# Not going to be more specific than this for now
__propagatedImpureHostDeps = stdenv.lib.optionals (name != "Kernel") [
# The setup-hook ensures that everyone uses the impure CoreFoundation who uses these SDK frameworks, so let's expose it
"/System/Library/Frameworks/CoreFoundation.framework"
"/System/Library/Frameworks/${name}.framework"
"/System/Library/Frameworks/${name}.framework/${name}"
];
2015-06-20 22:29:42 +00:00
meta = with stdenv.lib; {
description = "Apple SDK framework ${name}";
maintainers = with maintainers; [ copumpkin ];
platforms = platforms.darwin;
};
};
in rec {
libs = {
xpc = stdenv.mkDerivation {
name = "apple-lib-xpc";
dontUnpack = true;
2015-06-20 22:29:42 +00:00
installPhase = ''
mkdir -p $out/include
pushd $out/include >/dev/null
cp -r "${lib.getDev sdk}/include/xpc" $out/include/xpc
cp "${lib.getDev sdk}/include/launch.h" $out/include/launch.h
2015-06-20 22:29:42 +00:00
popd >/dev/null
'';
};
Xplugin = stdenv.mkDerivation {
name = "apple-lib-Xplugin";
dontUnpack = true;
2015-06-20 22:29:42 +00:00
# Not enough
__propagatedImpureHostDeps = [ "/usr/lib/libXplugin.1.dylib" ];
propagatedBuildInputs = with frameworks; [
OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText
2015-06-20 22:29:42 +00:00
];
installPhase = ''
mkdir -p $out/include $out/lib
2018-06-09 03:57:36 +00:00
ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
2015-06-20 22:29:42 +00:00
ln -s "/usr/lib/libXplugin.1.dylib" $out/lib/libXplugin.dylib
'';
};
utmp = stdenv.mkDerivation {
name = "apple-lib-utmp";
dontUnpack = true;
2015-06-20 22:29:42 +00:00
installPhase = ''
mkdir -p $out/include
pushd $out/include >/dev/null
2018-06-09 03:57:36 +00:00
ln -s "${lib.getDev sdk}/include/utmp.h"
ln -s "${lib.getDev sdk}/include/utmpx.h"
2015-06-20 22:29:42 +00:00
popd >/dev/null
'';
};
};
2015-10-01 00:13:56 +00:00
overrides = super: {
AppKit = stdenv.lib.overrideDerivation super.AppKit (drv: {
__propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
"/System/Library/PrivateFrameworks/"
];
2015-10-01 00:13:56 +00:00
});
CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: {
setupHook = ./cf-setup-hook.sh;
});
CoreMedia = stdenv.lib.overrideDerivation super.CoreMedia (drv: {
__propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
"/System/Library/Frameworks/CoreImage.framework"
];
2015-11-13 02:59:17 +00:00
});
CoreMIDI = stdenv.lib.overrideDerivation super.CoreMIDI (drv: {
__propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
"/System/Library/PrivateFrameworks/"
];
setupHook = ./private-frameworks-setup-hook.sh;
});
Security = stdenv.lib.overrideDerivation super.Security (drv: {
setupHook = ./security-setup-hook.sh;
});
QuartzCore = stdenv.lib.overrideDerivation super.QuartzCore (drv: {
installPhase = drv.installPhase + ''
f="$out/Library/Frameworks/QuartzCore.framework/Headers/CoreImage.h"
substituteInPlace "$f" \
--replace "QuartzCore/../Frameworks/CoreImage.framework/Headers" "CoreImage"
'';
});
2019-06-23 22:28:36 +00:00
MetalKit = stdenv.lib.overrideDerivation super.MetalKit (drv: {
installPhase = drv.installPhase + ''
mkdir -p $out/include/simd
cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
'';
});
2015-10-01 00:13:56 +00:00
};
bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix {
inherit frameworks libs;
inherit (pkgs.darwin) libobjc;
});
2015-10-01 00:13:56 +00:00
frameworks = bareFrameworks // overrides bareFrameworks;
inherit sdk;
2015-06-20 22:29:42 +00:00
}