diff --git a/pkgs/default.nix b/pkgs/default.nix index 216318b..e9b536d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -38,14 +38,6 @@ let inherit revstring diskName; }; - disk-script-fn = - { moduleIds ? null - , - }: - pkgs.callPackage ./disk-script { - bundle = bundle-fn { inherit moduleIds; }; - }; - in rec { default = moduleit; @@ -66,11 +58,15 @@ rec { # For prod use: builds the Nixmodules disk image bundle-image-tarball = pkgs.callPackage ./bundle-image-tarball { inherit bundle-image revstring; }; - disk-script-dev = disk-script-fn { - moduleIds = dev-module-ids; + disk-script = pkgs.callPackage ./disk-script { + bundle = bundle-fn { }; }; - disk-script = disk-script-fn { }; + disk-script-dev = pkgs.callPackage ./disk-script-dev { + bundle = bundle-fn { + moduleIds = dev-module-ids; + }; + }; # For dev use: builds the shared Nixmodules disk bundle-squashfs = bundle-squashfs-fn { diff --git a/pkgs/disk-script-dev/default.nix b/pkgs/disk-script-dev/default.nix new file mode 100644 index 0000000..11507ba --- /dev/null +++ b/pkgs/disk-script-dev/default.nix @@ -0,0 +1,47 @@ +{ writeShellApplication +, bundle +, squashfsTools +, coreutils +, findutils +, closureInfo +, +}: + +let + diskClosureInfo = closureInfo { rootPaths = [ bundle ]; }; +in +writeShellApplication { + name = "disk-script"; + runtimeInputs = [ + coreutils + findutils + squashfsTools + ]; + text = '' + set -x + TMP_DIR=$(mktemp -d) + + cd "$TMP_DIR" + + root="$TMP_DIR/root" + diskImage="$TMP_DIR/disk.sqsh" + + ( + 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 + + ) 1>&2 + + echo "$diskImage" + ''; +} diff --git a/pkgs/disk-script/default.nix b/pkgs/disk-script/default.nix index 61f9969..1c7ec1d 100644 --- a/pkgs/disk-script/default.nix +++ b/pkgs/disk-script/default.nix @@ -30,7 +30,8 @@ writeShellApplication { cd "$TMP_DIR" root="$TMP_DIR/root" - diskImage="$TMP_DIR/disk.sqsh" + # gcp requires that disks end in "disk.raw" + diskImage="$TMP_DIR/disk.raw" tarball="$TMP_DIR/disk.sqsh.tar.gz" ( @@ -48,7 +49,7 @@ writeShellApplication { echo "mksquashfs took $SECONDS seconds" >&2 SECONDS=0 - tar --use-compress-program="pigz --best --recursive | pv" -Scf "$tarball" disk.sqsh + tar --use-compress-program="pigz --best --recursive | pv" -Scf "$tarball" "$diskImage" echo "tar took $SECONDS seconds" >&2 echo Tarball created at "$tarball" >&2