11 # The 10.12 SDK doesn’t have the files needed in the same places or possibly at all.
12 # Just use the 11.x SDK to make things easier.
13 xnu = apple-sdk_11.sourceRelease "xnu";
15 privateHeaders = stdenvNoCC.mkDerivation {
16 name = "copyfile-deps-private-headers";
19 install -D -t "$out/include/Kernel/sys" \
20 '${xnu}/bsd/sys/decmpfs.h'
22 install -D -t "$out/include/System/sys" \
23 '${xnu}/bsd/sys/content_protection.h' \
24 '${xnu}/bsd/sys/fsctl.h'
25 substituteInPlace "$out/include/System/sys/content_protection.h" \
26 --replace-fail '#ifdef PRIVATE' '#if 1'
28 mkdir -p "$out/include/xpc"
29 cat <<EOF > "$out/include/xpc/private.h"
31 extern int _xpc_runtime_is_app_sandboxed();
34 # https://github.com/apple-oss-distributions/copyfile/blob/ed3f0a8bf8b6bac6838c92c297afcc826fec75f4/copyfile.c#L64-L74
35 cat <<EOF > "$out/include/quarantine.h"
37 typedef void* qtn_file_t;
38 #define QTN_SERIALIZED_DATA_MAX 4096
39 #define qtn_file_alloc _qtn_file_alloc
40 #define qtn_file_init_with_fd _qtn_file_init_with_fd
41 #define qtn_file_init_with_path _qtn_file_init_with_path
42 #define qtn_file_init_with_data _qtn_file_init_with_data
43 #define qtn_file_free _qtn_file_free
44 #define qtn_file_apply_to_fd _qtn_file_apply_to_fd
45 #define qtn_error _qtn_error
46 #define qtn_file_to_data _qtn_file_to_data
47 #define qtn_file_clone _qtn_file_clone
48 #define qtn_file_get_flags _qtn_file_get_flags
49 #define qtn_file_set_flags _qtn_file_set_flags
50 extern void * qtn_file_alloc(void);
51 extern int qtn_file_init_with_fd(void *x, int y);
52 extern int qtn_file_init_with_path(void *x, const char *path);
53 extern int qtn_file_init_with_data(void *x, const void *data, size_t len);
54 extern void qtn_file_free(void *);
55 extern int qtn_file_apply_to_fd(void *x, int y);
56 extern char *qtn_error(int x);
57 extern int qtn_file_to_data(void *x, char *y, size_t *z);
58 extern void *qtn_file_clone(void *x);
59 extern uint32_t qtn_file_get_flags(void *x);
60 extern int qtn_file_set_flags(void *x, uint32_t flags);
61 #define qtn_xattr_name "com.apple.quarantine"
62 #define QTN_FLAG_DO_NOT_TRANSLOCATE 0x100
68 releaseName = "copyfile";
76 xcodeHash = "sha256-SYW6pBlCQkcbkBqCq+W/mDYZZ7/co2HlPZwXzgh/LnI=";
79 # Disable experimental bounds safety stuff that’s not available in LLVM 16.
80 for header in copyfile.h xattr_flags.h; do
81 substituteInPlace "$header" \
82 --replace-fail '__ptrcheck_abi_assume_single()' "" \
83 --replace-fail '__unsafe_indexable' ""
86 # clang 16 does not support C23 empty initializers. This can be removed once the bootstrap tools are updated.
87 substituteInPlace copyfile.c \
88 --replace-fail 'filesec_t fsec_tmp = {};' 'filesec_t fsec_tmp = {0};'
91 env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
93 buildInputs = lib.optionals (lib.versionOlder (lib.getVersion apple-sdk) "10.13") [
94 (apple-sdk_10_13.override { enableBootstrap = true; })
97 meta.description = "Darwin file copying library";