Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
81c21f3
Support network resource management
onixie Feb 6, 2020
de2f744
Update and check for virtualbox network resource
onixie Feb 14, 2020
a9ded3b
Fix unstable create and destroy in a parallel deployment
onixie Feb 14, 2020
d7ca549
Add examples for illustrating how to use the vbox-network resource
onixie Feb 14, 2020
3bd7409
Allow network CIDR contain host bits
onixie Feb 17, 2020
739d3d0
Improve state checks and update conditions
onixie Feb 17, 2020
4ec86c0
Avoid depending on unecessary parse_nic_spec method
onixie Feb 18, 2020
3924d98
Ensure stop even if the machine is unreachable
onixie Feb 18, 2020
02e191a
VBoxManage requires a full stop vm to be modified
onixie Feb 18, 2020
db117dd
Simplify the method to get nic info and flags
onixie Feb 18, 2020
786536c
Avoid using non-reachable link-local address for machine connection
onixie Feb 18, 2020
cccca98
Fix change of dhcp server config not reflected bug
onixie Feb 18, 2020
30e3006
Invoke poweroff from guest machine only if it's possible
onixie Feb 18, 2020
792c0d6
Use namedtuple to avoid ad-hoc unpacking
onixie Feb 18, 2020
c2ae0db
Reflect change of networks in redeployment
onixie Feb 18, 2020
46a1b42
Fix broken vbox-network example
onixie Feb 18, 2020
d13104e
Use regex to extract the index number of the nic
onixie Feb 19, 2020
80ce440
Factor out condition for modifyvm
onixie Feb 19, 2020
d66f7eb
Improve error handling for the update failure of private ip
onixie Feb 19, 2020
f0fb1c1
Fix missing return bug
onixie Feb 19, 2020
9d93bbb
Inform user to use --allow-reboot when updating networks is intended
onixie Feb 20, 2020
264b8db
Disable removed nics with a network typed as 'none'
onixie Feb 20, 2020
ba68a21
Avoid network change warning for the initial deployment
onixie Feb 21, 2020
980fd28
Type check on networks option to ensure hostonly exist in the list
onixie Feb 21, 2020
00f70b4
Rename the vbox-network resource to virtualbox-network
onixie Feb 28, 2020
bfa334d
Fix trivial logging error
onixie Feb 28, 2020
e0a504f
Execute proper shutdown command based on updated machine state
onixie Feb 28, 2020
ca76ede
An alternative form to allow compact staticIPs definition
onixie Feb 28, 2020
00cb135
Fix staticIPs overwrite issue
onixie Feb 28, 2020
f544eb7
Avoid update unchanged network resources
onixie Feb 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/vbox-network.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
resources.virtualboxNetworks.net1 = { resources, ... }: {
type = "natnetwork";
cidrBlock = "192.168.100.0/24";
staticIPs = {
"192.168.100.11" = resources.machines.node1;
"192.168.100.12" = "node2";
};
};

resources.virtualboxNetworks.net2 = { resources, ... }: {
type = "hostonly";
cidrBlock = "192.168.101.0/24";
staticIPs = [
{
machine = resources.machines.node1;
address = "192.168.101.10";
}
];
};

node1 = { resources, lib, pkgs, ... }: {
deployment.targetEnv = "virtualbox";
deployment.virtualbox.headless = true;
deployment.virtualbox.networks = [
{ "type" = "nat"; }
resources.virtualboxNetworks.net1
resources.virtualboxNetworks.net2
];
};

node2 = { resources, lib, pkgs, ... }: {
deployment.targetEnv = "virtualbox";
deployment.virtualbox.headless = true;
deployment.virtualbox.networks = [
resources.virtualboxNetworks.net2
resources.virtualboxNetworks.net1
];
};

node3 = { resources, lib, pkgs, ... }: {
deployment.targetEnv = "virtualbox";
deployment.virtualbox.headless = true;
};
}
4 changes: 3 additions & 1 deletion nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
options = [
./virtualbox.nix
];
resources = { ... }: {};
resources = { evalResources, zipAttrs, resourcesByType, ...}: {
virtualboxNetworks = evalResources ./virtualbox-network.nix (zipAttrs resourcesByType.virtualboxNetworks or []);
};
}
73 changes: 73 additions & 0 deletions nix/virtualbox-network.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{ config, lib, pkgs, uuid, name, ... }:

with lib;
with import <nixops/lib.nix> lib;

let
toMachineName = m: if builtins.isString m then m else m._name;
in
rec {
options = {
type = mkOption {
default = "hostonly";
description = ''
The type of the VirtualBox network.
Either NAT network or Host-only network can be specified. Defaults to Host-only Network.
'';
type = types.enum [ "natnetwork" "hostonly" ];
};

cidrBlock = mkOption {
example = "192.168.56.0/24";
description = ''
The IPv4 CIDR block for the VirtualBox network. The following IP addresses are reserved for the network:
Network - The first address in the IP range, e.g. 192.168.56.0 in 192.168.56.0/24
Gateway - The second address in the IP range, e.g. 192.168.56.1 in 192.168.56.0/24
DHCP Server - The third address in the IP range, e.g. 192.168.56.2 in 192.168.56.0/24
Broadcast - The last address in the IP range, e.g. 192.168.56.255 in 192.168.56.0/24
'';
type = types.str;
};

staticIPs = mkOption {
example = ''
# As an attrset
{
"192.168.56.10" = "node1";
"192.168.56.11" = "node2";
...
}
# Or as a list
[
{ address = "192.168.56.10"; machine = "node1"; }
{ address = "192.168.56.11"; machine = "node2"; }
...
]
'';
default = [];
description = "The list of machine to IPv4 address bindings for fixing IP address of the machine in the network";
apply = a: if builtins.isAttrs a then mapAttrs (k: toMachineName) a else a;
type = with types; either attrs (listOf (submodule {
options = {
address = mkOption {
example = "192.168.56.3";
type = str;
description = ''
The IPv4 address assigned to the machine as static IP.
The static IP must be a non-reserved IP address.
'';
};
machine = mkOption {
type = either str (resource "machine");
apply = toMachineName;
description = "The name of the machine in the network";
};
};
}));
};
};

config = {
_type = "virtualbox-network";
};
}
35 changes: 34 additions & 1 deletion nix/virtualbox.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ config, pkgs, lib, ... }:
{ config, pkgs, lib, resources, ... }:

with lib;
with import <nixops/lib.nix> lib;

let

Expand Down Expand Up @@ -91,6 +92,38 @@ in
});
};

deployment.virtualbox.networks = mkOption {
default = [ { type = "nat"; } { type = "hostonly"; name = "vboxnet0"; } ];
description = ''
The list of networks to which the instance is attached. The network can be either
a virtualbox-network resource or a network not managed by NixOps.

For the sake of backward compatibility, the default list contains the following networks:
- NAT
- Host-only network vboxnet0

Note: NixOps requires at least one Host-only network to access the instance for management purposes,
When multiple Host-only networks exist, the first one in the list will be used for machine connection.
'';
type = with types; addCheck (nonEmptyListOf
(either
(resource "virtualbox-network")
(submodule {
options = {
name = mkOption {
default = "";
description = "The name of the network not managed by NixOps";
type = str;
};
type = mkOption {
description = "The type of the network";
type = enum [ "none" "nat" "natnetwork" "bridged" "hostonly" "intnet" "generic" ];
};
};
})
)) (l: any (n: n.type == "hostonly") l);
};

deployment.virtualbox.sharedFolders = mkOption {
default = {};

Expand Down
Loading