Skip to content

Commit 2ac68d2

Browse files
Use shorter attr style in some places
1 parent 9af43b7 commit 2ac68d2

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

examples/microvms-host.nix

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ nixpkgs.lib.nixosSystem {
123123
networkConfig.Bridge = "virbr0";
124124
};
125125
};
126-
# Allow DHCP server
127-
networking.firewall.allowedUDPPorts = [ 67 ];
128-
# Allow Internet access
129-
networking.nat = {
130-
enable = true;
131-
enableIPv6 = true;
132-
internalInterfaces = [ "virbr0" ];
126+
networking = {
127+
extraHosts = lib.concatMapStrings (hypervisor: ''
128+
${hypervisorIPv4Addrs.${hypervisor}} ${hypervisor}
129+
'') hypervisors;
130+
# Allow DHCP server
131+
firewall.allowedUDPPorts = [ 67 ];
132+
# Allow Internet access
133+
nat = {
134+
enable = true;
135+
enableIPv6 = true;
136+
internalInterfaces = [ "virbr0" ];
137+
};
133138
};
134-
135-
networking.extraHosts = lib.concatMapStrings (hypervisor: ''
136-
${hypervisorIPv4Addrs.${hypervisor}} ${hypervisor}
137-
'') hypervisors;
138139
})
139140
];
140141
}

flake.nix

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,29 @@
167167
services.getty.autologinUser = "root";
168168

169169
nixpkgs.overlays = [ self.overlay ];
170-
microvm.hypervisor = hypervisor;
171-
# share the host's /nix/store if the hypervisor can do 9p
172-
microvm.shares = lib.optional (builtins.elem hypervisor hypervisorsWith9p) {
173-
tag = "ro-store";
174-
source = "/nix/store";
175-
mountPoint = "/nix/.ro-store";
176-
};
177-
# microvm.writableStoreOverlay = "/nix/.rw-store";
178-
# microvm.volumes = [ {
179-
# image = "nix-store-overlay.img";
180-
# mountPoint = config.microvm.writableStoreOverlay;
181-
# size = 2048;
182-
# } ];
183-
microvm.interfaces = lib.optional (builtins.elem hypervisor hypervisorsWithUserNet) {
184-
type = "user";
185-
id = "qemu";
186-
mac = "02:00:00:01:01:01";
187-
};
188-
microvm.forwardPorts = lib.optional (hypervisor == "qemu") {
189-
host.port = 2222;
190-
guest.port = 22;
170+
microvm = {
171+
inherit hypervisor;
172+
# share the host's /nix/store if the hypervisor can do 9p
173+
shares = lib.optional (builtins.elem hypervisor hypervisorsWith9p) {
174+
tag = "ro-store";
175+
source = "/nix/store";
176+
mountPoint = "/nix/.ro-store";
177+
};
178+
# writableStoreOverlay = "/nix/.rw-store";
179+
# volumes = [ {
180+
# image = "nix-store-overlay.img";
181+
# mountPoint = config.microvm.writableStoreOverlay;
182+
# size = 2048;
183+
# } ];
184+
interfaces = lib.optional (builtins.elem hypervisor hypervisorsWithUserNet) {
185+
type = "user";
186+
id = "qemu";
187+
mac = "02:00:00:01:01:01";
188+
};
189+
forwardPorts = lib.optional (hypervisor == "qemu") {
190+
host.port = 2222;
191+
guest.port = 22;
192+
};
191193
};
192194
networking.firewall.allowedTCPPorts = lib.optional (hypervisor == "qemu") 22;
193195
services.openssh = lib.optionalAttrs (hypervisor == "qemu") {
@@ -215,8 +217,10 @@
215217
id = "vm-${builtins.substring 0 4 hypervisor}";
216218
mac = "02:00:00:01:01:0${toString n}";
217219
} ];
218-
networking.interfaces.eth0.useDHCP = true;
219-
networking.firewall.allowedTCPPorts = [ 22 ];
220+
networking = {
221+
interfaces.eth0.useDHCP = true;
222+
firewall.allowedTCPPorts = [ 22 ];
223+
};
220224
services.openssh = {
221225
enable = true;
222226
settings.PermitRootLogin = "yes";

0 commit comments

Comments
 (0)