Skip to content

Commit 043e59e

Browse files
committed
nixos-modules/host: split up
1 parent 8cbd267 commit 043e59e

File tree

2 files changed

+142
-137
lines changed

2 files changed

+142
-137
lines changed

nixos-modules/host/default.nix

Lines changed: 1 addition & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -8,143 +8,7 @@ let
88
group = "kvm";
99
in
1010
{
11-
options.microvm = with lib; {
12-
host.enable = mkOption {
13-
type = types.bool;
14-
default = true;
15-
description = ''
16-
Whether to enable the microvm.nix host module.
17-
'';
18-
};
19-
20-
host.useNotifySockets = mkOption {
21-
type = types.bool;
22-
default = false;
23-
description = ''
24-
Enable if all your MicroVMs run with a Hypervisor that sends readiness notification over a VSOCK.
25-
26-
If one of your MicroVMs doesn't do this, its systemd service
27-
will not start up successfully.
28-
'';
29-
};
30-
31-
vms = mkOption {
32-
type = with types; attrsOf (submodule ({ config, name, ... }: {
33-
options = {
34-
config = mkOption {
35-
description = lib.mdDoc ''
36-
A specification of the desired configuration of this MicroVM,
37-
as a NixOS module, for building **without** a flake.
38-
'';
39-
default = null;
40-
type = nullOr (lib.mkOptionType {
41-
name = "Toplevel NixOS config";
42-
merge = loc: defs: (import "${config.nixpkgs}/nixos/lib/eval-config.nix" {
43-
modules =
44-
let
45-
extraConfig = ({ lib, ... }: {
46-
_file = "module at ${__curPos.file}:${toString __curPos.line}";
47-
config = {
48-
networking.hostName = lib.mkDefault name;
49-
};
50-
});
51-
in [
52-
extraConfig
53-
../microvm
54-
] ++ (map (x: x.value) defs);
55-
prefix = [ "microvm" "vms" name "config" ];
56-
inherit (config) specialArgs pkgs;
57-
system = if config.pkgs != null then config.pkgs.system else pkgs.system;
58-
});
59-
});
60-
};
61-
62-
nixpkgs = mkOption {
63-
type = types.path;
64-
default = if config.pkgs != null then config.pkgs.path else pkgs.path;
65-
defaultText = literalExpression "pkgs.path";
66-
description = lib.mdDoc ''
67-
This option is only respected when `config` is specified.
68-
The nixpkgs path to use for the MicroVM. Defaults to the host's nixpkgs.
69-
'';
70-
};
71-
72-
pkgs = mkOption {
73-
type = types.nullOr types.unspecified;
74-
default = pkgs;
75-
defaultText = literalExpression "pkgs";
76-
description = lib.mdDoc ''
77-
This option is only respected when `config` is specified.
78-
The package set to use for the MicroVM. Must be a nixpkgs package set with the microvm overlay. Determines the system of the MicroVM.
79-
If set to null, a new package set will be instantiated.
80-
'';
81-
};
82-
83-
specialArgs = mkOption {
84-
type = types.attrsOf types.unspecified;
85-
default = {};
86-
description = lib.mdDoc ''
87-
This option is only respected when `config` is specified.
88-
A set of special arguments to be passed to NixOS modules.
89-
This will be merged into the `specialArgs` used to evaluate
90-
the NixOS configurations.
91-
'';
92-
};
93-
94-
flake = mkOption {
95-
description = "Source flake for declarative build";
96-
type = nullOr path;
97-
default = null;
98-
};
99-
100-
updateFlake = mkOption {
101-
description = "Source flake to store for later imperative update";
102-
type = nullOr str;
103-
default = null;
104-
};
105-
106-
autostart = mkOption {
107-
description = "Add this MicroVM to config.microvm.autostart?";
108-
type = bool;
109-
default = true;
110-
};
111-
112-
restartIfChanged = mkOption {
113-
type = types.bool;
114-
default = config.config != null;
115-
description = ''
116-
Restart this MicroVM's services if the systemd units are changed,
117-
i.e. if it has been updated by rebuilding the host.
118-
119-
Defaults to true for fully-declarative MicroVMs.
120-
'';
121-
};
122-
};
123-
}));
124-
default = {};
125-
description = ''
126-
The MicroVMs that shall be built declaratively with the host NixOS.
127-
'';
128-
};
129-
130-
stateDir = mkOption {
131-
type = types.path;
132-
default = "/var/lib/microvms";
133-
description = ''
134-
Directory that contains the MicroVMs
135-
'';
136-
};
137-
138-
autostart = mkOption {
139-
type = with types; listOf str;
140-
default = [];
141-
description = ''
142-
MicroVMs to start by default.
143-
144-
This includes declarative `config.microvm.vms` as well as MicroVMs that are managed through the `microvm` command.
145-
'';
146-
};
147-
};
11+
imports = [ ./options.nix ];
14812

14913
config = lib.mkIf config.microvm.host.enable {
15014
assertions = lib.concatMap (vmName: [

nixos-modules/host/options.nix

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{ pkgs, lib, ... }:
2+
3+
{
4+
options.microvm = with lib; {
5+
host.enable = mkOption {
6+
type = types.bool;
7+
default = true;
8+
description = ''
9+
Whether to enable the microvm.nix host module.
10+
'';
11+
};
12+
13+
host.useNotifySockets = mkOption {
14+
type = types.bool;
15+
default = false;
16+
description = ''
17+
Enable if all your MicroVMs run with a Hypervisor that sends readiness notification over a VSOCK.
18+
19+
If one of your MicroVMs doesn't do this, its systemd service
20+
will not start up successfully.
21+
'';
22+
};
23+
24+
vms = mkOption {
25+
type = with types; attrsOf (submodule ({ config, name, ... }: {
26+
options = {
27+
config = mkOption {
28+
description = lib.mdDoc ''
29+
A specification of the desired configuration of this MicroVM,
30+
as a NixOS module, for building **without** a flake.
31+
'';
32+
default = null;
33+
type = nullOr (lib.mkOptionType {
34+
name = "Toplevel NixOS config";
35+
merge = loc: defs: (import "${config.nixpkgs}/nixos/lib/eval-config.nix" {
36+
modules =
37+
let
38+
extraConfig = ({ lib, ... }: {
39+
_file = "module at ${__curPos.file}:${toString __curPos.line}";
40+
config = {
41+
networking.hostName = lib.mkDefault name;
42+
};
43+
});
44+
in [
45+
extraConfig
46+
../microvm
47+
] ++ (map (x: x.value) defs);
48+
prefix = [ "microvm" "vms" name "config" ];
49+
inherit (config) specialArgs pkgs;
50+
system = if config.pkgs != null then config.pkgs.system else pkgs.system;
51+
});
52+
});
53+
};
54+
55+
nixpkgs = mkOption {
56+
type = types.path;
57+
default = if config.pkgs != null then config.pkgs.path else pkgs.path;
58+
defaultText = literalExpression "pkgs.path";
59+
description = lib.mdDoc ''
60+
This option is only respected when `config` is specified.
61+
The nixpkgs path to use for the MicroVM. Defaults to the host's nixpkgs.
62+
'';
63+
};
64+
65+
pkgs = mkOption {
66+
type = types.nullOr types.unspecified;
67+
default = pkgs;
68+
defaultText = literalExpression "pkgs";
69+
description = lib.mdDoc ''
70+
This option is only respected when `config` is specified.
71+
The package set to use for the MicroVM. Must be a nixpkgs package set with the microvm overlay. Determines the system of the MicroVM.
72+
If set to null, a new package set will be instantiated.
73+
'';
74+
};
75+
76+
specialArgs = mkOption {
77+
type = types.attrsOf types.unspecified;
78+
default = {};
79+
description = lib.mdDoc ''
80+
This option is only respected when `config` is specified.
81+
A set of special arguments to be passed to NixOS modules.
82+
This will be merged into the `specialArgs` used to evaluate
83+
the NixOS configurations.
84+
'';
85+
};
86+
87+
flake = mkOption {
88+
description = "Source flake for declarative build";
89+
type = nullOr path;
90+
default = null;
91+
};
92+
93+
updateFlake = mkOption {
94+
description = "Source flake to store for later imperative update";
95+
type = nullOr str;
96+
default = null;
97+
};
98+
99+
autostart = mkOption {
100+
description = "Add this MicroVM to config.microvm.autostart?";
101+
type = bool;
102+
default = true;
103+
};
104+
105+
restartIfChanged = mkOption {
106+
type = types.bool;
107+
default = config.config != null;
108+
description = ''
109+
Restart this MicroVM's services if the systemd units are changed,
110+
i.e. if it has been updated by rebuilding the host.
111+
112+
Defaults to true for fully-declarative MicroVMs.
113+
'';
114+
};
115+
};
116+
}));
117+
default = {};
118+
description = ''
119+
The MicroVMs that shall be built declaratively with the host NixOS.
120+
'';
121+
};
122+
123+
stateDir = mkOption {
124+
type = types.path;
125+
default = "/var/lib/microvms";
126+
description = ''
127+
Directory that contains the MicroVMs
128+
'';
129+
};
130+
131+
autostart = mkOption {
132+
type = with types; listOf str;
133+
default = [];
134+
description = ''
135+
MicroVMs to start by default.
136+
137+
This includes declarative `config.microvm.vms` as well as MicroVMs that are managed through the `microvm` command.
138+
'';
139+
};
140+
};
141+
}

0 commit comments

Comments
 (0)