@@ -11,47 +11,46 @@ nixpkgs.lib.nixosSystem {
11
11
self . nixosModules . microvm
12
12
13
13
( { config , lib , pkgs , ... } :
14
- let
15
- hypervisors-with-mac = builtins . listToAttrs (
16
- map ( hypervisor :
17
- let
18
- hash = builtins . hashString "sha256" hypervisor ;
19
- c = off : builtins . substring off 2 hash ;
20
- mac = "${ builtins . substring 0 1 hash } 2:${ c 2 } :${ c 4 } :${ c 6 } :${ c 8 } :${ c 10 } " ;
21
- in
22
- { name = hypervisor ; value = mac ; } )
23
- self . lib . hypervisors ) ;
24
- in
25
- {
26
- networking . hostName = "microvms-host" ;
27
- system . stateVersion = config . system . nixos . version ;
28
- users . users . root . password = "" ;
29
- users . motd = ''
30
- Once nested MicroVMs have booted you can look up DHCP leases:
31
- networkctl status virbr0
14
+ let
15
+ hypervisorMacAddrs = builtins . listToAttrs (
16
+ map ( hypervisor :
17
+ let
18
+ hash = builtins . hashString "sha256" hypervisor ;
19
+ c = off : builtins . substring off 2 hash ;
20
+ mac = "${ builtins . substring 0 1 hash } 2:${ c 2 } :${ c 4 } :${ c 6 } :${ c 8 } :${ c 10 } " ;
21
+ in {
22
+ name = hypervisor ;
23
+ value = mac ;
24
+ } ) self . lib . hypervisors ) ;
25
+ in {
26
+ networking . hostName = "microvms-host" ;
27
+ system . stateVersion = config . system . nixos . version ;
28
+ users . users . root . password = "" ;
29
+ users . motd = ''
30
+ Once nested MicroVMs have booted you can look up DHCP leases:
31
+ networkctl status virbr0
32
32
33
- They are configured to allow SSH login with an empty root
34
- password.
35
- '' ;
36
- services . getty . autologinUser = "root" ;
33
+ They are configured to allow SSH login with an empty root
34
+ password.
35
+ '' ;
36
+ services . getty . autologinUser = "root" ;
37
37
38
- # MicroVM settings
39
- microvm = {
40
- mem = 8192 ;
41
- vcpu = 4 ;
42
- # Use QEMU because nested virtualization and user networking
43
- # are required.
44
- hypervisor = "qemu" ;
45
- interfaces = [ {
46
- type = "user" ;
47
- id = "qemu" ;
48
- mac = "02:00:00:01:01:01" ;
49
- } ] ;
50
- } ;
38
+ # MicroVM settings
39
+ microvm = {
40
+ mem = 8192 ;
41
+ vcpu = 4 ;
42
+ # Use QEMU because nested virtualization and user networking
43
+ # are required.
44
+ hypervisor = "qemu" ;
45
+ interfaces = [ {
46
+ type = "user" ;
47
+ id = "qemu" ;
48
+ mac = "02:00:00:01:01:01" ;
49
+ } ] ;
50
+ } ;
51
51
52
- # Nested MicroVMs (a *host* option)
53
- microvm . vms = builtins . mapAttrs ( hypervisor : mac :
54
- {
52
+ # Nested MicroVMs (a *host* option)
53
+ microvm . vms = builtins . mapAttrs ( hypervisor : mac : {
55
54
config = {
56
55
system . stateVersion = config . system . nixos . version ;
57
56
networking . hostName = "${ hypervisor } -microvm" ;
@@ -61,7 +60,7 @@ nixpkgs.lib.nixosSystem {
61
60
interfaces = [ {
62
61
type = "tap" ;
63
62
id = "vm-${ builtins . substring 0 12 hypervisor } " ;
64
- inherit mac ;
63
+ inherit mac ;
65
64
} ] ;
66
65
} ;
67
66
# Just use 99-ethernet-default-dhcp.network
@@ -73,54 +72,51 @@ nixpkgs.lib.nixosSystem {
73
72
settings . PermitRootLogin = "yes" ;
74
73
} ;
75
74
} ;
76
- } ) hypervisors-with-mac ;
75
+ } ) hypervisorMacAddrs ;
77
76
78
- systemd . network = {
79
- enable = true ;
80
- netdevs . virbr0 . netdevConfig = {
81
- Kind = "bridge" ;
82
- Name = "virbr0" ;
83
- } ;
84
- networks . virbr0 = {
85
- matchConfig . Name = "virbr0" ;
86
- # Hand out IP addresses to MicroVMs.
87
- # Use `networkctl status virbr0` to see leases.
88
- networkConfig = {
89
- DHCPServer = true ;
90
- IPv6SendRA = true ;
77
+ systemd . network = {
78
+ enable = true ;
79
+ netdevs . virbr0 . netdevConfig = {
80
+ Kind = "bridge" ;
81
+ Name = "virbr0" ;
82
+ } ;
83
+ networks . virbr0 = {
84
+ matchConfig . Name = "virbr0" ;
85
+ # Hand out IP addresses to MicroVMs.
86
+ # Use `networkctl status virbr0` to see leases.
87
+ networkConfig = {
88
+ DHCPServer = true ;
89
+ IPv6SendRA = true ;
90
+ } ;
91
+ dhcpServerStaticLeases = [ {
92
+ # Let DHCP assign a statically known address to the qemu vm
93
+ dhcpServerStaticLeaseConfig = {
94
+ MACAddress = hypervisors-with-mac . qemu ;
95
+ Address = "10.0.13.37" ;
96
+ } ;
97
+ } ] ;
98
+ addresses = [ {
99
+ addressConfig . Address = "10.0.0.1/24" ;
100
+ } {
101
+ addressConfig . Address = "fd12:3456:789a::1/64" ;
102
+ } ] ;
103
+ ipv6Prefixes = [ {
104
+ ipv6PrefixConfig . Prefix = "fd12:3456:789a::/64" ;
105
+ } ] ;
106
+ } ;
107
+ networks . microvm-eth0 = {
108
+ matchConfig . Name = "vm-*" ;
109
+ networkConfig . Bridge = "virbr0" ;
91
110
} ;
92
- dhcpServerStaticLeases =
93
- [
94
- # Let DHCP assign a statically known address to the qemu vm
95
- {
96
- dhcpServerStaticLeaseConfig = {
97
- MACAddress = hypervisors-with-mac . qemu ;
98
- Address = "10.0.13.37" ;
99
- } ;
100
- }
101
- ] ;
102
- addresses = [ {
103
- addressConfig . Address = "10.0.0.1/24" ;
104
- } {
105
- addressConfig . Address = "fd12:3456:789a::1/64" ;
106
- } ] ;
107
- ipv6Prefixes = [ {
108
- ipv6PrefixConfig . Prefix = "fd12:3456:789a::/64" ;
109
- } ] ;
110
111
} ;
111
- networks . microvm-eth0 = {
112
- matchConfig . Name = "vm-*" ;
113
- networkConfig . Bridge = "virbr0" ;
112
+ # Allow DHCP server
113
+ networking . firewall . allowedUDPPorts = [ 67 ] ;
114
+ # Allow Internet access
115
+ networking . nat = {
116
+ enable = true ;
117
+ enableIPv6 = true ;
118
+ internalInterfaces = [ "virbr0" ] ;
114
119
} ;
115
- } ;
116
- # Allow DHCP server
117
- networking . firewall . allowedUDPPorts = [ 67 ] ;
118
- # Allow Internet access
119
- networking . nat = {
120
- enable = true ;
121
- enableIPv6 = true ;
122
- internalInterfaces = [ "virbr0" ] ;
123
- } ;
124
- } )
120
+ } )
125
121
] ;
126
122
}
0 commit comments