Skip to content

Commit 570399a

Browse files
authored
[disk script] tweaks (#471)
2 parents e2da755 + 4d53456 commit 570399a

3 files changed

Lines changed: 57 additions & 13 deletions

File tree

pkgs/default.nix

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ let
3838
inherit revstring diskName;
3939
};
4040

41-
disk-script-fn =
42-
{ moduleIds ? null
43-
,
44-
}:
45-
pkgs.callPackage ./disk-script {
46-
bundle = bundle-fn { inherit moduleIds; };
47-
};
48-
4941
in
5042
rec {
5143
default = moduleit;
@@ -66,11 +58,15 @@ rec {
6658
# For prod use: builds the Nixmodules disk image
6759
bundle-image-tarball = pkgs.callPackage ./bundle-image-tarball { inherit bundle-image revstring; };
6860

69-
disk-script-dev = disk-script-fn {
70-
moduleIds = dev-module-ids;
61+
disk-script = pkgs.callPackage ./disk-script {
62+
bundle = bundle-fn { };
7163
};
7264

73-
disk-script = disk-script-fn { };
65+
disk-script-dev = pkgs.callPackage ./disk-script-dev {
66+
bundle = bundle-fn {
67+
moduleIds = dev-module-ids;
68+
};
69+
};
7470

7571
# For dev use: builds the shared Nixmodules disk
7672
bundle-squashfs = bundle-squashfs-fn {

pkgs/disk-script-dev/default.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{ writeShellApplication
2+
, bundle
3+
, squashfsTools
4+
, coreutils
5+
, findutils
6+
, closureInfo
7+
,
8+
}:
9+
10+
let
11+
diskClosureInfo = closureInfo { rootPaths = [ bundle ]; };
12+
in
13+
writeShellApplication {
14+
name = "disk-script";
15+
runtimeInputs = [
16+
coreutils
17+
findutils
18+
squashfsTools
19+
];
20+
text = ''
21+
set -x
22+
TMP_DIR=$(mktemp -d)
23+
24+
cd "$TMP_DIR"
25+
26+
root="$TMP_DIR/root"
27+
diskImage="$TMP_DIR/disk.sqsh"
28+
29+
(
30+
mkdir -p "$root/nix/store" "$root/etc/nixmodules"
31+
32+
cp --archive --reflink=auto "${bundle}/etc/nixmodules/"* "$root/etc/nixmodules"
33+
34+
SECONDS=0
35+
xargs -P "$(nproc)" cp -a --reflink=auto -t "$root/nix/store/" < "${diskClosureInfo}/store-paths"
36+
echo "xargs copy took $SECONDS seconds" >&2
37+
38+
echo "making squashfs..."
39+
SECONDS=0
40+
mksquashfs "$root" "$diskImage" -force-uid 11000 -force-gid 11000 -comp lz4 -b 1M
41+
echo "mksquashfs took $SECONDS seconds" >&2
42+
43+
) 1>&2
44+
45+
echo "$diskImage"
46+
'';
47+
}

pkgs/disk-script/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ writeShellApplication {
3030
cd "$TMP_DIR"
3131
3232
root="$TMP_DIR/root"
33-
diskImage="$TMP_DIR/disk.sqsh"
33+
# gcp requires that disks end in "disk.raw"
34+
diskImage="$TMP_DIR/disk.raw"
3435
tarball="$TMP_DIR/disk.sqsh.tar.gz"
3536
3637
(
@@ -48,7 +49,7 @@ writeShellApplication {
4849
echo "mksquashfs took $SECONDS seconds" >&2
4950
5051
SECONDS=0
51-
tar --use-compress-program="pigz --best --recursive | pv" -Scf "$tarball" disk.sqsh
52+
tar --use-compress-program="pigz --best --recursive | pv" -Scf "$tarball" "$diskImage"
5253
echo "tar took $SECONDS seconds" >&2
5354
5455
echo Tarball created at "$tarball" >&2

0 commit comments

Comments
 (0)