PR to support network resources for VirtualBox backend in NixOps

Hello, I created a PR for nixops-vbox plugin to extend its network capabilities. With this PR, user can define virtual networks and specify network adaptors explicitly for machines. It solves several itchy-spots when user wants to use virtualbox backend in some serious scenario. Though I think I’ve finished the initial development of my original idea, I’m still open to suggestions, advices and new requirements.

Here is the link to the PR:
https://github.com/nix-community/nixops-vbox/pull/2

And an example of what a deployment will look like with the newly supported network resources.

{
    resources.virtualboxNetworks.host-net = {
        type = "hostonly";
        cidrBlock = "192.168.101.0/24";
        staticIPs = {
            "192.168.101.10" = "my-node";  # works in VirtualBox v6.1
        };
    };

    my-node = { resources, lib, pkgs, ... }: {
        deployment.targetEnv = "virtualbox";
        deployment.virtualbox.headless = true;
        deployment.virtualbox.networks = [
            { "type" = "nat"; }
            resources.virtualboxNetworks.host-net
        ];
    };
}

Appreciate for any feedback as well as code review.

2 Likes

As a followup, I’ve also created a PR for libvirtd backend providing similar functionalities but in a libvirt way.

https://github.com/nix-community/nixops-libvirtd/pull/9

I tried to keep the nix module options the same with the virtualbox backend so that user can have consistent experience with the two backends though there are differences due to the capabilities originated from the hypervisor.

Here is a similar example but for libvirt backend.

{
    resources.libvirtdNetworks.host-net = {
        type = "nat"; # NAT virtual network in libvirt is like a mix of Host-only and Natnetwork in virtualbox
        cidrBlock = "192.168.101.0/24";
        staticIPs = {
            "192.168.101.10" = "my-node";  # should work in all supported libvirt version
        };
    };

    my-node = { resources, lib, pkgs, ... }: {
        deployment.targetEnv = "libvirtd";
        deployment.libvirtd.networks = [
            resources.libvirtdNetworks.host-net
        ];
    };
}
1 Like