|
8 | 8 | group = "kvm";
|
9 | 9 | in
|
10 | 10 | {
|
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 ]; |
148 | 12 |
|
149 | 13 | config = lib.mkIf config.microvm.host.enable {
|
150 | 14 | assertions = lib.concatMap (vmName: [
|
|
0 commit comments