Skip to content

Commit f033f4b

Browse files
committed
nixos-modules/host: add microvm.host.tapScript
Closes Github issue #251
1 parent e187191 commit f033f4b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

nixos-modules/host/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ in
160160
fi
161161
162162
${pkgs.iproute2}/bin/ip tuntap add name $id mode tap user ${user} $TAP_FLAGS
163-
${pkgs.iproute2}/bin/ip link set $id up
163+
${config.microvm.host.tapScript}
164164
done
165165
'';
166166
};
@@ -342,6 +342,10 @@ in
342342
wants = map (name: "microvm@${name}.service") config.microvm.autostart;
343343
};
344344

345+
microvm.host.tapScript = lib.mkDefault ''
346+
${pkgs.iproute2}/bin/ip link set $id up
347+
'';
348+
345349
# This helper creates tap interfaces and attaches them to a bridge
346350
# for qemu regardless if it is run as root or not.
347351
security.wrappers.qemu-bridge-helper = lib.mkIf (!config.virtualisation.libvirtd.enable) {

nixos-modules/host/options.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121
'';
2222
};
2323

24+
host.tapScript = mkOption {
25+
description = ''
26+
Commands to run after creating a tap interface
27+
28+
Defaults to bring the interface up.
29+
30+
If you do not want the interface to be automatically created
31+
at all, just set
32+
`systemd.services."microvm-tap-interfaces@%i.service".enable = false`
33+
'';
34+
example = ''
35+
# Attach tap interface to bridge br0, and set it up
36+
''${pkgs.iproute2}/bin/ip link set $id master br0 up
37+
'';
38+
type = types.lines;
39+
};
40+
2441
vms = mkOption {
2542
type = with types; attrsOf (submodule ({ config, name, ... }: {
2643
options = {

0 commit comments

Comments
 (0)