-
Notifications
You must be signed in to change notification settings - Fork 7
/
vm-options.nix
127 lines (113 loc) · 3.1 KB
/
vm-options.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This is just the VM specific config and options being built
{ lib, system }:
{ config, options, name, ... }:
with lib;
{
options = {
config = mkOption {
description = ''
A specification of the desired configuration of this
virtual machine, as a NixOS module.
'';
type = lib.mkOptionType {
name = "Toplevel NixOS config";
merge = loc: defs: (import <nixpkgs/nixos/lib/eval-config.nix> {
inherit system;
modules = [{
networking.hostName = mkDefault name;
imports = [ # Import the vm profile for all guests
./vm-profile.nix
];
}] ++ (map (x: x.value) defs);
prefix = [ "virtualMachines" name ];
}).config;
};
};
rootImagePath = mkOption {
type = types.str;
default = "/var/lib/vms/${name}.${config.rootImageFormat}";
description = ''
Path to store the root image.
'';
};
rootImageSize = mkOption {
type = types.int;
default = 10 * 1024;
description = ''
The size of the root image in MiB.
'';
};
rootImageFormat = mkOption {
type = types.enum ["qcow2" "raw"];
default = "qcow2";
description = ''
The format of the root image.
'';
};
baseImageSize = mkOption {
type = types.int;
default = 10 * 1024;
description = ''
The size of the base image in MiB.
'';
};
baseImageFormat = mkOption {
type = types.enum ["qcow2" "raw"];
default = "qcow2";
description = ''
The format of the base image.
'';
};
memory = mkOption {
type = types.int;
default = 512;
description = ''
Size in MiB of memory to assign this virtual machine
'';
};
qemuSwitches = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Switches given to QEMU cli when starting this virtual machine.
All switches will have - prepended automatically.
'';
};
autoStart = mkOption {
type = types.bool;
default = false;
description = ''
Whether the virtual machine is automatically started at boot-time.
'';
};
cpu = mkOption {
type = types.str;
default = "host";
description = ''
The CPU model to emulate.
'';
};
cores = mkOption {
type = types.int;
default = 1;
description = ''
The number of CPU cores this virtual machine has access to.
'';
};
kvm = mkEnableOption "Kernal Virtual Machine acceleration";
virtioRNG = mkEnableOption "Virtio accelerated Random Number Generator";
memoryBalloon = mkEnableOption "Virtio memory ballooning";
};
config = mkIf options.config.isDefined {
qemuSwitches = with config; [
"nographic"
"vga none"
"m ${toString memory}"
"cpu ${cpu}"
"smp ${toString cores}"
]
++ optional kvm "enable-kvm"
++ optional memoryBalloon "device virtio-balloon,automatic=true"
++ optional virtioRNG "device virtio-rng-pci";
};
}