Files
apple-internals/flake.nix
Michael Roitzsch 6c884c3052 flake: add snapUtil
creates APFS snapshots
2020-09-17 17:29:17 +02:00

53 lines
1.6 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
description = "tools to understand the internals of Apples operating systems";
inputs = {
snapshot-header = {
url = "https://opensource.apple.com/tarballs/xnu/xnu-6153.141.1.tar.gz";
flake = false;
};
snap-util = {
url = github:ahl/apfs;
flake = false;
};
};
outputs = { self, nixpkgs, snapshot-header, snap-util }: {
snap-util =
with import nixpkgs { system = "x86_64-darwin"; };
stdenv.mkDerivation {
name = "snap-util-${lib.substring 0 8 self.inputs.snap-util.lastModifiedDate}";
src = snap-util;
preBuild = "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 $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
'';
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/>
</dict>
</plist>
EOF
/usr/bin/codesign -s - --entitlement snapUtil.entitlements $out/bin/.snapUtil-wrapped
'';
};
};
}