diff --git a/modules/microvm.nix b/modules/microvm.nix index 3e0fa0c6..83d9c2a8 100644 --- a/modules/microvm.nix +++ b/modules/microvm.nix @@ -96,6 +96,13 @@ in ip tuntap add ${id} mode tap user microvm fi ''; + stopTuntap = { id, ... }: + pkgs.writeScript "tuntap-${hostName}-${id}" '' + #!${pkgs.runtimeShell} -e + if [ -d /sys/class/net/${id} ]; then + ip tuntap del ${id} mode tap + fi + ''; # change working directory before starting virtiofsd runVirtiofsd = { tag, socket, source, ... }: pkgs.writeScript "virtiofsd-${hostName}-${tag}" '' @@ -137,6 +144,16 @@ in command = "${runTuntap interface}" } } + task "interface-${id}-stop" { + lifecycle { + hook = "poststop" + } + driver = "raw_exec" + user = "root" + config { + command = "${stopTuntap interface}" + } + } '') config.microvm.interfaces} ${lib.concatMapStrings (share@{ tag, ... }: ''