about summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix
blob: c64f011c0534d43c6ae6b4a4236a9124a34ba3aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{ stdenvNoCC, fetchurl, newScope, lib, pkgs
, stdenv, overrideCC
, xar, cpio, python3, pbzx }:

let
  mkSusDerivation = args: stdenvNoCC.mkDerivation (args // {
    dontBuild = true;
    darwinDontCodeSign = true;

    nativeBuildInputs = [ cpio pbzx ];

    outputs = [ "out" ];

    unpackPhase = ''
      pbzx $src | cpio -idm
    '';

    passthru = {
      inherit (args) version;
    };
  });

  MacOSX-SDK = mkSusDerivation {
    pname = "MacOSX-SDK";
    version = "11.0.0";

    # https://swscan.apple.com/content/catalogs/others/index-11-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
    src = fetchurl {
      url = "http://swcdn.apple.com/content/downloads/46/21/001-89745-A_56FM390IW5/v1um2qppgfdnam2e9cdqcqu2r6k8aa3lis/CLTools_macOSNMOS_SDK.pkg";
      sha256 = "0n425smj4q1vxbza8fzwnk323fyzbbq866q32w288c44hl5yhwsf";
    };

    installPhase = ''
      mv Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk $out
    '';
  };

  CLTools_Executables = mkSusDerivation {
    pname = "CLTools_Executables";
    version = "11.0.0";

    # https://swscan.apple.com/content/catalogs/others/index-11-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
    src = fetchurl {
      url = "http://swcdn.apple.com/content/downloads/46/21/001-89745-A_56FM390IW5/v1um2qppgfdnam2e9cdqcqu2r6k8aa3lis/CLTools_Executables.pkg";
      sha256 = "0nvb1qx7l81l2wcl8wvgbpsg5rcn51ylhivqmlfr2hrrv3zrrpl0";
    };

    installPhase = ''
      mv Library/Developer/CommandLineTools $out
    '';
  };

  mkCc = cc:
    if lib.versionAtLeast stdenv.hostPlatform.darwinSdkVersion "11" then cc
    else
      cc.override {
        bintools = stdenv.cc.bintools.override { libc = packages.Libsystem; };
        libc = packages.Libsystem;
      };

  mkStdenv = stdenv:
    if lib.versionAtLeast stdenv.hostPlatform.darwinSdkVersion "11" then stdenv
    else
      let
        darwinMinVersion = "10.12";
        darwinSdkVersion = "11.0";
      in
      (overrideCC stdenv (mkCc stdenv.cc)).override {
        extraBuildInputs = [ pkgs.darwin.apple_sdk_11_0.frameworks.CoreFoundation ];
        buildPlatform = stdenv.buildPlatform // { inherit darwinMinVersion darwinSdkVersion; };
        hostPlatform = stdenv.hostPlatform // { inherit darwinMinVersion darwinSdkVersion; };
        targetPlatform = stdenv.targetPlatform // { inherit darwinMinVersion darwinSdkVersion; };
      };

  stdenvs = {
    stdenv = mkStdenv stdenv;
  } // builtins.listToAttrs (map
    (v: {
      name = "llvmPackages_${v}";
      value = pkgs."llvmPackages_${v}" // {
        stdenv = mkStdenv pkgs."llvmPackages_${v}".stdenv;
        clang = mkCc pkgs."llvmPackages_${v}".clang;
      };
    })
    [ "12" "13" "14" "15" "16" ]
  );

  callPackage = newScope (packages // pkgs.darwin // { inherit MacOSX-SDK; });

  packages = stdenvs // {
    inherit (callPackage ./apple_sdk.nix { }) frameworks libs;

    # TODO: this is nice to be private. is it worth the callPackage above?
    # Probably, I don't think that callPackage costs much at all.
    inherit MacOSX-SDK CLTools_Executables;

    Libsystem = callPackage ./libSystem.nix { };
    LibsystemCross = pkgs.darwin.Libsystem;
    libcharset = callPackage ./libcharset.nix { };
    libcompression = callPackage ./libcompression.nix { };
    libunwind = callPackage ./libunwind.nix { };
    libnetwork = callPackage ./libnetwork.nix { };
    libpm = callPackage ./libpm.nix { };
    # Avoid introducing a new objc4 if stdenv already has one, to prevent
    # conflicting LLVM modules.
    objc4 = stdenv.objc4 or (callPackage ./libobjc.nix { });

    sdkRoot = pkgs.callPackage ../apple-sdk/sdkRoot.nix { sdkVersion = "11.0"; };

    # questionable aliases
    configd = pkgs.darwin.apple_sdk.frameworks.SystemConfiguration;
    inherit (pkgs.darwin.apple_sdk.frameworks) IOKit;

    xcodebuild = pkgs.xcbuild.override {
      inherit (pkgs.darwin.apple_sdk_11_0) stdenv;
      inherit (pkgs.darwin.apple_sdk_11_0.frameworks) CoreServices CoreGraphics ImageIO;
    };

    rustPlatform = pkgs.makeRustPlatform {
      inherit (pkgs.darwin.apple_sdk_11_0) stdenv;
      inherit (pkgs) rustc cargo;
    } // {
      inherit (pkgs.callPackage ../../../build-support/rust/hooks {
        inherit (pkgs.darwin.apple_sdk_11_0) stdenv;
        inherit (pkgs) cargo rustc;
        clang = mkCc pkgs.clang;
      }) bindgenHook;
    };

    callPackage = newScope (lib.optionalAttrs stdenv.hostPlatform.isDarwin (stdenvs // rec {
      inherit (pkgs.darwin.apple_sdk_11_0) xcodebuild rustPlatform;
      darwin = pkgs.darwin.overrideScope (_: prev: {
        inherit (prev.darwin.apple_sdk_11_0)
          IOKit
          Libsystem
          LibsystemCross
          Security
          configd
          libcharset
          libunwind
          objc4
          ;
        apple_sdk = prev.darwin.apple_sdk_11_0;
        CF = prev.darwin.apple_sdk_11_0.CoreFoundation;
      });
      xcbuild = xcodebuild;
    }));

    darwin-stubs = stdenvNoCC.mkDerivation {
      pname = "darwin-stubs";
      inherit (MacOSX-SDK) version;

      buildCommand = ''
        mkdir -p "$out"
        ln -s ${MacOSX-SDK}/System "$out/System"
        ln -s ${MacOSX-SDK}/usr "$out/usr"
      '';
    };
  };
in packages