Skip to content

Commit 5067708

Browse files
committed
nixos-modules/microvm/store-disk: parallelize mkfs.erofs, specify gensquashfs jobs
1 parent 02c5b7a commit 5067708

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

nixos-modules/microvm/store-disk.nix

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ let
77

88
kernelAtLeast = lib.versionAtLeast config.boot.kernelPackages.kernel.version;
99

10+
erofs-utils =
11+
# Are any extended options specified?
12+
if lib.any (with lib; flip elem ["-Ededupe" "-Efragments"]) config.microvm.storeDiskErofsFlags
13+
then
14+
# If extended options are present,
15+
# stick to the single-threaded erofs-utils
16+
# to not scare anyone with warning messages.
17+
pkgs.buildPackages.erofs-utils
18+
else
19+
# If no extended options are configured,
20+
# rebuild mkfs.erofs with multi-threading.
21+
pkgs.buildPackages.erofs-utils.overrideAttrs (attrs: {
22+
configureFlags = attrs.configureFlags ++ [
23+
"--enable-multithreading"
24+
];
25+
});
26+
1027
erofsFlags = builtins.concatStringsSep " " config.microvm.storeDiskErofsFlags;
1128
squashfsFlags = builtins.concatStringsSep " " config.microvm.storeDiskSquashfsFlags;
1229

@@ -25,23 +42,20 @@ in
2542
storeDiskErofsFlags = mkOption {
2643
type = with types; listOf str;
2744
default =
28-
[
29-
"-zlz4hc"
30-
]
31-
# ++
32-
# lib.optional (kernelAtLeast "5.13") "-C1048576"
45+
[ "-zlz4hc" ]
3346
++
3447
lib.optional (kernelAtLeast "5.16") "-Eztailpacking"
3548
++
3649
lib.optionals (kernelAtLeast "6.1") [
50+
# not implemented with multi-threading
3751
"-Efragments"
38-
# "-Ededupe"
52+
"-Ededupe"
3953
];
4054
};
4155

4256
storeDiskSquashfsFlags = mkOption {
4357
type = with types; listOf str;
44-
default = [ "-c" "zstd" ];
58+
default = [ "-c" "zstd" "-j" "$NIX_BUILD_CORES" ];
4559
};
4660

4761
storeDisk = mkOption {
@@ -69,10 +83,12 @@ in
6983
];
7084

7185
microvm.storeDisk = pkgs.runCommandLocal "microvm-store-disk.${config.microvm.storeDiskType}" {
72-
nativeBuildInputs = with pkgs.buildPackages; [ {
73-
squashfs = [ squashfs-tools-ng ];
74-
erofs = [ erofs-utils ];
75-
}.${config.microvm.storeDiskType} ];
86+
nativeBuildInputs = [
87+
{
88+
squashfs = [ pkgs.buildPackages.squashfs-tools-ng ];
89+
erofs = [ erofs-utils ];
90+
}.${config.microvm.storeDiskType}
91+
];
7692
passthru = {
7793
inherit regInfo;
7894
};
@@ -92,8 +108,8 @@ in
92108
done
93109
94110
echo Creating a ${config.microvm.storeDiskType}
95-
${{
96-
squashfs = "gensquashfs -D store --all-root -q ${squashfsFlags} $out";
111+
time ${{
112+
squashfs = "gensquashfs ${squashfsFlags} -D store --all-root -q $out";
97113
erofs = "mkfs.erofs ${erofsFlags} -T 0 --all-root -L nix-store --mount-point=/nix/store $out store";
98114
}.${config.microvm.storeDiskType}}
99115
'';

0 commit comments

Comments
 (0)