Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions pkgs/disk-script-dev/default.nix
Original file line number Diff line number Diff line change
@@ -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"
'';
}
5 changes: 3 additions & 2 deletions pkgs/disk-script/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"

(
Expand All @@ -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
Expand Down