@@ -10,7 +10,19 @@ nixpkgs.lib.nixosSystem {
10
10
# this runs as a MicroVM that nests MicroVMs
11
11
self . nixosModules . microvm
12
12
13
- ( { config , lib , pkgs , ... } : {
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
+ {
14
26
networking . hostName = "microvms-host" ;
15
27
system . stateVersion = config . system . nixos . version ;
16
28
users . users . root . password = "" ;
@@ -38,38 +50,30 @@ nixpkgs.lib.nixosSystem {
38
50
} ;
39
51
40
52
# Nested MicroVMs (a *host* option)
41
- microvm . vms = builtins . listToAttrs (
42
- map ( hypervisor : {
43
- name = hypervisor ;
44
- value = {
45
- config = {
46
- system . stateVersion = config . system . nixos . version ;
47
- networking . hostName = "${ hypervisor } -microvm" ;
53
+ microvm . vms = builtins . mapAttrs ( hypervisor : mac :
54
+ {
55
+ config = {
56
+ system . stateVersion = config . system . nixos . version ;
57
+ networking . hostName = "${ hypervisor } -microvm" ;
48
58
49
- microvm = {
50
- inherit hypervisor ;
51
- interfaces = [ {
52
- type = "tap" ;
53
- id = "vm-${ builtins . substring 0 12 hypervisor } " ;
54
- mac =
55
- let
56
- hash = builtins . hashString "sha256" hypervisor ;
57
- c = off : builtins . substring off 2 hash ;
58
- in
59
- "${ builtins . substring 0 1 hash } 2:${ c 2 } :${ c 4 } :${ c 6 } :${ c 8 } :${ c 10 } " ;
60
- } ] ;
61
- } ;
62
- # Just use 99-ethernet-default-dhcp.network
63
- systemd . network . enable = true ;
59
+ microvm = {
60
+ inherit hypervisor ;
61
+ interfaces = [ {
62
+ type = "tap" ;
63
+ id = "vm-${ builtins . substring 0 12 hypervisor } " ;
64
+ inherit mac ;
65
+ } ] ;
66
+ } ;
67
+ # Just use 99-ethernet-default-dhcp.network
68
+ systemd . network . enable = true ;
64
69
65
- users . users . root . password = "" ;
66
- services . openssh = {
67
- enable = true ;
68
- settings . PermitRootLogin = "yes" ;
69
- } ;
70
+ users . users . root . password = "" ;
71
+ services . openssh = {
72
+ enable = true ;
73
+ settings . PermitRootLogin = "yes" ;
70
74
} ;
71
75
} ;
72
- } ) self . lib . hypervisors ) ;
76
+ } ) hypervisors-with-mac ;
73
77
74
78
systemd . network = {
75
79
enable = true ;
@@ -85,6 +89,16 @@ nixpkgs.lib.nixosSystem {
85
89
DHCPServer = true ;
86
90
IPv6SendRA = true ;
87
91
} ;
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
+ ] ;
88
102
addresses = [ {
89
103
addressConfig . Address = "10.0.0.1/24" ;
90
104
} {
0 commit comments