21 Libc = apple-sdk.sourceRelease "Libc";
22 Libinfo = apple-sdk.sourceRelease "Libinfo";
24 # The 10.12 SDK doesn’t have the files needed in the same places or possibly at all.
25 # Just use the 11.0 SDK to make things easier.
26 CommonCrypto = apple-sdk_11.sourceRelease "CommonCrypto";
27 libplatform = apple-sdk_11.sourceRelease "libplatform";
28 xnu = apple-sdk_11.sourceRelease "xnu";
30 privateHeaders = stdenvNoCC.mkDerivation {
31 name = "file_cmds-deps-private-headers";
34 install -D -t "$out/include" \
35 '${Libinfo}/membership.subproj/membershipPriv.h' \
36 '${libplatform}/private/_simple.h'
37 install -D -t "$out/include/os" \
38 '${Libc}/os/assumes.h' \
39 '${xnu}/libkern/os/base_private.h'
40 install -D -t "$out/include/sys" \
41 '${xnu}/bsd/sys/ipcs.h' \
42 '${xnu}/bsd/sys/sem_internal.h' \
43 '${xnu}/bsd/sys/shm_internal.h'
44 install -D -t "$out/include/CommonCrypto" \
45 '${CommonCrypto}/include/Private/CommonDigestSPI.h'
46 install -D -t "$out/include/System/sys" \
47 '${xnu}/bsd/sys/fsctl.h'
49 # Needed by older private headers.
50 touch "$out/include/CrashReporterClient.h"
52 mkdir -p "$out/include/apfs"
53 # APFS group is 'J' per https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/vfs/vfs_fsevents.c#L1054
54 cat <<EOF > "$out/include/apfs/apfs_fsctl.h"
57 #include <sys/ioccom.h>
58 struct xdstream_obj_id {
60 uint64_t xdi_xdtream_obj_id;
62 #define APFS_CLEAR_PURGEABLE 0
63 #define APFSIOC_MARK_PURGEABLE _IOWR('J', 68, uint64_t)
64 #define APFSIOC_XDSTREAM_OBJ_ID _IOWR('J', 53, struct xdstream_obj_id)
67 # Prevent an error when using the old availability headers from the 10.12 SDK.
68 substituteInPlace "$out/include/CommonCrypto/CommonDigestSPI.h" \
69 --replace-fail 'API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.13), ios(5.0, 11.0))' "" \
70 --replace-fail 'API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(5.0, 13.0))' ""
72 cat <<EOF > "$out/include/sys/types.h"
75 #if defined(__arm64__)
76 /* https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/arm/types.h#L120-L133 */
77 typedef int32_t user32_addr_t;
78 typedef int32_t user32_time_t;
79 typedef int64_t user64_addr_t;
80 typedef int64_t user64_time_t;
81 #elif defined(__x86_64__)
82 /* https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/i386/types.h#L128-L142 */
83 typedef int32_t user32_addr_t;
84 typedef int32_t user32_time_t;
85 typedef int64_t user64_addr_t __attribute__((aligned(8)));
86 typedef int64_t user64_time_t __attribute__((aligned(8)));
88 #error "Tried to build file_cmds for an unsupported architecture"
90 #include_next <sys/types.h>
96 releaseName = "file_cmds";
104 xcodeHash = "sha256-u23AoLa7J0eFtf4dXKkVO59eYL2I3kRsHcWPfT03MCU=";
108 ./patches/0001-Add-missing-extern-unix2003_compat-to-ls.patch
109 # Add missing conditional to avoid using private APFS APIs that we lack headers for using.
110 ./patches/0002-Add-missing-ifdef-for-private-APFS-APIs.patch
111 # Add implementations of missing functions for older SDKs
112 ./patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch
115 nativeBuildInputs = [ pkg-config ];
117 env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
129 # ls needs strtonum, which requires the 11.0 SDK.
130 ++ lib.optionals (lib.versionOlder (lib.getVersion apple-sdk) "11.0") [ libbsd ];
133 HOST_PATH='${lib.getBin shell_cmds}/bin' patchShebangs --host "$out/bin"
135 substituteInPlace "$out/bin/zmore" \
136 --replace-fail 'PAGER-less' '${lib.getBin less}/bin/less' \
137 --replace-fail 'PAGER-more' '${lib.getBin less}/bin/more'
139 # Work around Meson limitations.
140 mv "$out/bin/install-bin" "$out/bin/install"
142 # Make xattr available in its own output, so darwin.xattr can be an alias to it.
143 moveToOutput bin/xattr "$xattr"
144 ln -s "$xattr/bin/xattr" "$out/bin/xattr"
148 description = "File commands for Darwin";
149 license = with lib.licenses; [