-
Notifications
You must be signed in to change notification settings - Fork 12
/
flake.nix
142 lines (133 loc) · 4.37 KB
/
flake.nix
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
{
description = "tools to understand the internals of Apple’s operating systems";
inputs = {
acextract = {
url = "github:bartoszj/acextract";
flake = false;
};
command-line = {
url = "github:iHTCboy/CommandLine";
flake = false;
};
dsc-extractor = {
url = "github:keith/dyld-shared-cache-extractor";
flake = false;
};
snap-util = {
url = "github:ahl/apfs";
flake = false;
};
};
outputs = { self, nixpkgs, acextract, command-line, dsc-extractor, snap-util }: {
packages.x86_64-darwin = let
xcode = nixpkgs.legacyPackages.x86_64-darwin.xcodeenv.composeXcodeWrapper {};
in {
acextract =
with nixpkgs.legacyPackages.x86_64-darwin;
let xcodeHook = makeSetupHook {
name = "xcode-hook";
propagatedBuildInputs = [ xcode ];
} "${xcbuildHook}/nix-support/setup-hook";
in stdenv.mkDerivation {
name = "acextract-${lib.substring 0 8 self.inputs.acextract.lastModifiedDate}";
src = acextract;
nativeBuildInputs = [ xcodeHook ];
__noChroot = true;
preBuild = "LD=$CC";
# FIXME: want to have submodule support for Nix flakes, workaround by explicit instantiation
postUnpack = "rmdir source/CommandLine ; ln -s ${command-line} source/CommandLine";
# FIXME: fix for Swift compiler crash
patchPhase = ''
patch -p0 <<- EOF
--- acextract/CoreUI.h
+++ acextract/CoreUI.h
@@ -24,6 +24,7 @@
// SOFTWARE.
@import Foundation;
+@import CoreGraphics;
// Hierarchy:
// - CUICatalog:
--- acextract/Operation.swift 2021-10-20 10:35:39.000000000 +0200
+++ acextract/Operation.swift 2021-10-20 10:35:46.000000000 +0200
@@ -24,6 +24,7 @@
// SOFTWARE.
import Foundation
+import ImageIO
// MARK: - Protocols
protocol Operation {
@@ -152,7 +153,7 @@
throw ExtractOperationError.cannotCreatePDFDocument
}
// Create the pdf context
- let cgPage = CGPDFDocument.page(cgPDFDocument) as! CGPDFPage // swiftlint:disable:this force_cast
+ let cgPage = cgPDFDocument.page(at: 0)!
var cgPageRect = cgPage.getBoxRect(.mediaBox)
let mutableData = NSMutableData()
EOF
'';
installPhase = ''
mkdir -p $out/bin
cp Products/Release/acextract $out/bin/
'';
dontStrip = true;
};
dsc-extractor =
with nixpkgs.legacyPackages.x86_64-darwin;
stdenv.mkDerivation {
name = "dsc-extractor-${lib.substring 0 8 self.inputs.dsc-extractor.lastModifiedDate}";
src = dsc-extractor;
nativeBuildInputs = [ cmake ];
};
snap-util =
with nixpkgs.legacyPackages.x86_64-darwin;
let snapshot-header = fetchFromGitHub {
owner = "apple";
repo = "darwin-xnu";
rev = "xnu-6153.141.1";
hash = "sha256-/2aR6n5CbUobwbxkrGqBOAhCZLwDdIsoIOcpALhAUF8=";
};
in stdenv.mkDerivation {
name = "snap-util-${lib.substring 0 8 self.inputs.snap-util.lastModifiedDate}";
src = snap-util;
nativeBuildInputs = [ xcode ];
preBuild = ''
unset DEVELOPER_DIR SDKROOT
NIX_CFLAGS_COMPILE='-idirafter ${snapshot-header}/bsd'
'';
installPhase = ''
mkdir -p $out/bin
cp snapUtil $out/bin/.snapUtil-wrapped
cat > $out/bin/snapUtil <<- EOF
#!/bin/sh
if csrutil status | grep -Fq disabled && sysctl kern.bootargs | grep -Fq amfi_get_out_of_my_way ; then
exec -a ./snapUtil $out/bin/.snapUtil-wrapped "\$@"
else
echo 'snapUtil requires SIP and AMFI to be disabled:'
echo '• boot recovery system'
echo '• run ‘csrutil disable’'
echo '• run ‘nvram boot-args=amfi_get_out_of_my_way=0x1’'
exit 1
fi
EOF
chmod a+x $out/bin/snapUtil
'';
__noChroot = true;
postFixup = ''
cat > snapUtil.entitlements <<- EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.vfs.snapshot</key>
<true/>
<key>com.apple.private.apfs.revert-to-snapshot</key>
<true/>
</dict>
</plist>
EOF
codesign -s - --entitlement snapUtil.entitlements $out/bin/.snapUtil-wrapped
'';
};
};
};
}