about summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix
blob: 7bd3cae118eb215884b11a1c3087558851f2b120 (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
161
{
  lib,
  stdenv,
  stdenvNoCC,
  appleDerivation,
  fetchFromGitHub,
  runCommand,
  gawk,
  meson,
  ninja,
  pkg-config,
  libdispatch,
  libmalloc,
  libplatform,
  Librpcsvc,
  libutil,
  ncurses,
  openbsm,
  pam,
  xnu,
  CoreFoundation,
  CoreSymbolication,
  DirectoryService,
  IOKit,
  Kernel,
  Libc,
  OpenDirectory,
  WebKit,
}:

let
  OpenDirectoryPrivate = stdenvNoCC.mkDerivation (finalAttrs: {
    name = "apple-private-framework-OpenDirectory";
    version = "146";

    src = fetchFromGitHub {
      owner = "apple-oss-distributions";
      repo = "OpenDirectory";
      rev = "OpenDirectory-${finalAttrs.version}";
      hash = "sha256-6fSl8PasCZSBfe0ftaePcBuSEO3syb6kK+mfDI6iR7A=";
    };

    dontConfigure = true;
    dontBuild = true;

    installPhase = ''
      runHook preInstall

      mkdir -p "$out/include/CFOpenDirectory" "$out/include/OpenDirectory"
      install -t "$out/include/CFOpenDirectory" \
        Core/CFOpenDirectoryPriv.h \
        Core/CFODTrigger.h
      touch "$out/include/CFOpenDirectory/CFOpenDirectoryConstantsPriv.h"
      install -t "$out/include/OpenDirectory" \
        Framework/OpenDirectoryPriv.h \
        Framework/NSOpenDirectoryPriv.h

      runHook postInstall
    '';
  });

  libmallocPrivate = stdenvNoCC.mkDerivation {
    pname = "libmalloc-private";
    version = lib.getVersion libmalloc;

    inherit (libmalloc) src;

    dontConfigure = true;
    dontBuild = true;

    installPhase = ''
      runHook preInstall

      mkdir -p "$out/include"
      cp -r private/*.h "$out/include"

      runHook postInstall
    '';
  };

  # Private xnu headers that are part of the source tree but not in the xnu derivation.
  xnuPrivate = stdenvNoCC.mkDerivation {
    pname = "xnu-private";
    version = lib.getVersion xnu;

    inherit (xnu) src;

    dontConfigure = true;
    dontBuild = true;

    installPhase = ''
      runHook preInstall

      mkdir -p "$out/include"
      cp libsyscall/wrappers/spawn/spawn_private.h "$out/include"

      runHook postInstall
    '';
  };
in
appleDerivation (finalAttrs: {
  nativeBuildInputs = [
    gawk
    meson
    ninja
    pkg-config
  ];

  buildInputs = [
    libdispatch
    libplatform
    Librpcsvc
    libutil
    ncurses
    openbsm
    pam
    xnu
    CoreFoundation
    CoreSymbolication
    DirectoryService
    IOKit
    Kernel
    OpenDirectory
  ];

  postPatch = ''
    # Replace hard-coded, impure system paths with the output path in the store.
    sed -e "s|PATH=[^;]*|PATH='$out/bin'|" -i "pagesize/pagesize.sh"
  '';

  # A vendored meson.build is used instead of the upstream Xcode project.
  # This is done for a few reasons:
  # - The upstream project causes `xcbuild` to crash.
  #   See: https://github.com/facebookarchive/xcbuild/issues/188;
  # - Achieving the same flexibility regarding SDK version would require modifying the
  #   Xcode project, but modifying Xcode projects without using Xcode is painful; and
  # - Using Meson allows the derivation to leverage the robust Meson support in nixpkgs,
  #   and it allows it to use Meson features to simplify the build (e.g., generators).
  preConfigure = ''
    substitute '${./meson.build}' meson.build \
      --subst-var-by kernel '${Kernel}' \
      --subst-var-by libc_private '${Libc}' \
      --subst-var-by libmalloc_private '${libmallocPrivate}' \
      --subst-var-by opendirectory '${OpenDirectory}' \
      --subst-var-by opendirectory_private '${OpenDirectoryPrivate}' \
      --subst-var-by xnu '${xnu}' \
      --subst-var-by xnu_private '${xnuPrivate}' \
      --subst-var-by version '${finalAttrs.version}'
    cp '${./meson.options}' meson.options
  '';

  mesonFlags = [ (lib.mesonOption "sdk_version" stdenv.hostPlatform.darwinSdkVersion) ];

  meta = {
    platforms = lib.platforms.darwin;
    maintainers = with lib.maintainers; [
      shlevy
      matthewbauer
    ];
  };
})