summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix')
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix29
1 files changed, 22 insertions, 7 deletions
diff --git a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
index 90f572d3940..8b0d2054d58 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
@@ -4,12 +4,15 @@
 , headersOnly ? true
 }:
 
-appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ({
+appleDerivation' (if headersOnly then stdenvNoCC else stdenv) (
+  let arch = if stdenv.isx86_64 then "x86_64" else "arm64";
+  in
+  {
   depsBuildBuild = [ buildPackages.stdenv.cc ];
 
   nativeBuildInputs = [ bootstrap_cmds bison flex gnum4 unifdef perl python3 ];
 
-  patches = [ ./python3.patch ];
+  patches = lib.optional stdenv.isx86_64 [ ./python3.patch ];
 
   postPatch = ''
     substituteInPlace Makefile \
@@ -41,9 +44,16 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ({
       --replace " -o 0" "" \
       --replace '$SRC/$mig' '-I$DSTROOT/include $SRC/$mig' \
       --replace '$SRC/servers/netname.defs' '-I$DSTROOT/include $SRC/servers/netname.defs' \
-      --replace '$BUILT_PRODUCTS_DIR/mig_hdr' '$BUILT_PRODUCTS_DIR'
+      --replace '$BUILT_PRODUCTS_DIR/mig_hdr' '$BUILT_PRODUCTS_DIR' \
+      --replace 'MACHINE_ARCH=armv7' 'MACHINE_ARCH=arm64' # this might break the comments saying 32-bit is required
 
     patchShebangs .
+  '' + lib.optionalString stdenv.isAarch64 ''
+    # iig is closed-sourced, we don't have it
+    # create an empty file to the header instead
+    # this line becomes: echo "" > $@; echo --header ...
+    substituteInPlace iokit/DriverKit/Makefile \
+      --replace '--def $<' '> $@; echo'
   '';
 
   PLATFORM = "MacOSX";
@@ -62,18 +72,22 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ({
   HOST_BISON = "bison";
   HOST_GM4 = "m4";
   MIGCC = "cc";
-  ARCHS = "x86_64";
+  ARCHS = arch;
+  ARCH_CONFIGS = arch;
 
   NIX_CFLAGS_COMPILE = "-Wno-error";
 
-  preBuild = ''
+  preBuild = let macosVersion =
+    "10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11" +
+    lib.optionalString stdenv.isAarch64 " 10.12 10.13 10.14 10.15 11.0";
+   in ''
     # This is a bit of a hack...
     mkdir -p sdk/usr/local/libexec
 
     cat > sdk/usr/local/libexec/availability.pl <<EOF
       #!$SHELL
       if [ "\$1" == "--macosx" ]; then
-        echo 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11
+        echo ${macosVersion}
       elif [ "\$1" == "--ios" ]; then
         echo 2.0 2.1 2.2 3.0 3.1 3.2 4.0 4.1 4.2 4.3 5.0 5.1 6.0 6.1 7.0 8.0 9.0
       fi
@@ -132,7 +146,7 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ({
     mv $out/Library/Frameworks/IOKit.framework $out/Library/PrivateFrameworks
   '';
 
-  appleHeaders = builtins.readFile ./headers.txt;
+  appleHeaders = builtins.readFile (./. + "/headers-${arch}.txt");
 } // lib.optionalAttrs headersOnly {
   HOST_CODESIGN = "echo";
   HOST_CODESIGN_ALLOCATE = "echo";
@@ -142,4 +156,5 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ({
   CTFMERGE = "echo";
   CTFINSERT = "echo";
   NMEDIT = "echo";
+  IIG = "echo";
 })