-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdefault.nix
More file actions
59 lines (49 loc) · 1.24 KB
/
default.nix
File metadata and controls
59 lines (49 loc) · 1.24 KB
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
{ writeShellApplication
, bundle
, squashfsTools
, gnutar
, pigz
, coreutils
, findutils
, closureInfo
, pv
,
}:
let
diskClosureInfo = closureInfo { rootPaths = [ bundle ]; };
in
writeShellApplication {
name = "disk-script";
runtimeInputs = [
coreutils
findutils
gnutar
squashfsTools
pigz
pv
];
text = ''
set -x
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
root="$TMP_DIR/root"
diskImage="$TMP_DIR/disk.sqsh"
tarball="$TMP_DIR/disk.sqsh.tar.gz"
(
mkdir -p "$root/nix/store" "$root/etc/nixmodules"
cp --archive --reflink=auto "${bundle}/etc/nixmodules/"* "$root/etc/nixmodules"
SECONDS=0
xargs -P "$(nproc)" cp -a --reflink=auto -t "$root/nix/store/" < "${diskClosureInfo}/store-paths"
echo "xargs copy took $SECONDS seconds" >&2
echo "making squashfs..."
SECONDS=0
mksquashfs "$root" "$diskImage" -force-uid 11000 -force-gid 11000 -comp lz4 -b 1M
echo "mksquashfs took $SECONDS seconds" >&2
SECONDS=0
tar --use-compress-program="pigz --best --recursive | pv" -Scf "$tarball" disk.sqsh
echo "tar took $SECONDS seconds" >&2
echo Tarball created at "$tarball" >&2
) 1>&2
echo "$tarball"
'';
}