Skip to content

Commit 3394c37

Browse files
committed
nixos-modules/microvm/options: move all user-input options here
so they end up in the doc
1 parent 70db31a commit 3394c37

File tree

3 files changed

+94
-93
lines changed

3 files changed

+94
-93
lines changed

nixos-modules/microvm/optimization.nix

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,35 @@ let
1313
) config.microvm.shares;
1414

1515
in
16-
{
17-
options.microvm.optimize = {
18-
enable = lib.mkOption {
19-
description = ''
20-
Enables some optimizations by default to closure size and startup time:
21-
- defaults documentation to off
22-
- defaults to using systemd in initrd
23-
- use systemd-networkd
24-
- disables systemd-network-wait-online
25-
- disables NixOS system switching if the host store is not mounted
26-
27-
This takes a few hundred MB off the closure size, including qemu,
28-
allowing for putting MicroVMs inside Docker containers.
29-
'';
30-
31-
type = lib.types.bool;
32-
default = true;
33-
};
34-
};
35-
36-
config = lib.mkIf (cfg.guest.enable && cfg.optimize.enable) {
37-
# The docs are pretty chonky
38-
documentation.enable = lib.mkDefault false;
39-
40-
# Use systemd initrd for startup speed.
41-
# TODO: error mounting /nix/store on crosvm, kvmtool
42-
boot.initrd.systemd.enable = lib.mkDefault (
43-
builtins.elem cfg.hypervisor [
44-
"qemu"
45-
"cloud-hypervisor"
46-
"firecracker"
47-
"stratovirt"
48-
]);
49-
50-
nixpkgs.overlays = [
51-
(final: prev: {
52-
stratovirt = prev.stratovirt.override { gtk3 = null; };
53-
})
54-
];
55-
56-
# networkd is used due to some strange startup time issues with nixos's
57-
# homegrown dhcp implementation
58-
networking.useNetworkd = lib.mkDefault true;
59-
# Due to a bug in systemd-networkd: https://github.com/systemd/systemd/issues/29388
60-
# we cannot use systemd-networkd-wait-online.
61-
systemd.network.wait-online.enable = lib.mkDefault false;
62-
63-
# Exclude switch-to-configuration.pl from toplevel.
64-
system = lib.optionalAttrs (options.system ? switch && !canSwitchViaSsh) {
65-
switch.enable = lib.mkDefault false;
66-
};
16+
lib.mkIf (cfg.guest.enable && cfg.optimize.enable) {
17+
# The docs are pretty chonky
18+
documentation.enable = lib.mkDefault false;
19+
20+
# Use systemd initrd for startup speed.
21+
# TODO: error mounting /nix/store on crosvm, kvmtool
22+
boot.initrd.systemd.enable = lib.mkDefault (
23+
builtins.elem cfg.hypervisor [
24+
"qemu"
25+
"cloud-hypervisor"
26+
"firecracker"
27+
"stratovirt"
28+
]);
29+
30+
nixpkgs.overlays = [
31+
(final: prev: {
32+
stratovirt = prev.stratovirt.override { gtk3 = null; };
33+
})
34+
];
35+
36+
# networkd is used due to some strange startup time issues with nixos's
37+
# homegrown dhcp implementation
38+
networking.useNetworkd = lib.mkDefault true;
39+
# Due to a bug in systemd-networkd: https://github.com/systemd/systemd/issues/29388
40+
# we cannot use systemd-networkd-wait-online.
41+
systemd.network.wait-online.enable = lib.mkDefault false;
42+
43+
# Exclude switch-to-configuration.pl from toplevel.
44+
system = lib.optionalAttrs (options.system ? switch && !canSwitchViaSsh) {
45+
switch.enable = lib.mkDefault false;
6746
};
6847
}

nixos-modules/microvm/options.nix

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ in
1717
'';
1818
};
1919

20+
optimize.enable = lib.mkOption {
21+
description = ''
22+
Enables some optimizations by default to closure size and startup time:
23+
- defaults documentation to off
24+
- defaults to using systemd in initrd
25+
- use systemd-networkd
26+
- disables systemd-network-wait-online
27+
- disables NixOS system switching if the host store is not mounted
28+
29+
This takes a few hundred MB off the closure size, including qemu,
30+
allowing for putting MicroVMs inside Docker containers.
31+
'';
32+
33+
type = lib.types.bool;
34+
default = true;
35+
};
36+
2037
cpu = mkOption {
2138
type = with types; nullOr str;
2239
default = null;
@@ -519,14 +536,55 @@ in
519536
defaultText = literalExpression ''"config.microvm.runner.''${config.microvm.hypervisor}"'';
520537
};
521538

522-
# TODO: microvm-* as well?
523539
binScripts = mkOption {
524540
description = ''
525541
Script snippets that end up in the runner package's bin/ directory
526542
'';
527543
default = {};
528544
type = with types; attrsOf lines;
529545
};
546+
547+
storeDiskType = mkOption {
548+
type = types.enum [ "squashfs" "erofs" ];
549+
description = ''
550+
Boot disk file system type: squashfs is smaller, erofs is supposed to be faster.
551+
552+
Defaults to erofs, unless the NixOS hardened profile is detected.
553+
'';
554+
};
555+
556+
storeDiskErofsFlags = mkOption {
557+
type = with types; listOf str;
558+
description = ''
559+
Flags to pass to mkfs.erofs
560+
561+
Omit `"-Efragments"` and `"-Ededupe"` to enable multi-threading.
562+
'';
563+
default =
564+
[ "-zlz4hc" ]
565+
++
566+
lib.optional (kernelAtLeast "5.16") "-Eztailpacking"
567+
++
568+
lib.optionals (kernelAtLeast "6.1") [
569+
# not implemented with multi-threading
570+
"-Efragments"
571+
"-Ededupe"
572+
];
573+
defaultText = lib.literalExpression ''
574+
[ "-zlz4hc" ]
575+
++ lib.optional (kernelAtLeast "5.16") "-Eztailpacking"
576+
++ lib.optionals (kernelAtLeast "6.1") [
577+
"-Efragments"
578+
"-Ededupe"
579+
]
580+
'';
581+
};
582+
583+
storeDiskSquashfsFlags = mkOption {
584+
type = with types; listOf str;
585+
description = "Flags to pass to gensquashfs";
586+
default = [ "-c" "zstd" "-j" "$NIX_BUILD_CORES" ];
587+
};
530588
};
531589

532590
config = lib.mkMerge [ {

nixos-modules/microvm/store-disk.nix

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,11 @@ let
3737

3838
in
3939
{
40-
options.microvm = with lib; {
41-
storeDiskType = mkOption {
42-
type = types.enum [ "squashfs" "erofs" ];
43-
description = ''
44-
Boot disk file system type: squashfs is smaller, erofs is supposed to be faster.
45-
'';
46-
};
47-
48-
storeDiskErofsFlags = mkOption {
49-
type = with types; listOf str;
50-
default =
51-
[ "-zlz4hc" ]
52-
++
53-
lib.optional (kernelAtLeast "5.16") "-Eztailpacking"
54-
++
55-
lib.optionals (kernelAtLeast "6.1") [
56-
# not implemented with multi-threading
57-
"-Efragments"
58-
"-Ededupe"
59-
];
60-
defaultText = lib.literalExpression ''
61-
[ "-zlz4hc" ]
62-
++ lib.optional (kernelAtLeast "5.16") "-Eztailpacking"
63-
++ lib.optionals (kernelAtLeast "6.1") [
64-
"-Efragments"
65-
"-Ededupe"
66-
]
67-
'';
68-
};
69-
70-
storeDiskSquashfsFlags = mkOption {
71-
type = with types; listOf str;
72-
default = [ "-c" "zstd" "-j" "$NIX_BUILD_CORES" ];
73-
};
74-
75-
storeDisk = mkOption {
76-
type = types.path;
77-
description = ''
78-
Generated
79-
'';
80-
};
40+
options.microvm.storeDisk = with lib; mkOption {
41+
type = types.path;
42+
description = ''
43+
Generated
44+
'';
8145
};
8246

8347
config = lib.mkMerge [

0 commit comments

Comments
 (0)