2012-03-01 21:10:08 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
2012-03-10 15:34:40 +01:00
|
|
|
let virtualbox = config.boot.kernelPackages.virtualbox; in
|
|
|
|
|
2012-03-01 21:10:08 +01:00
|
|
|
{
|
|
|
|
boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ];
|
2012-03-10 15:34:40 +01:00
|
|
|
boot.extraModulePackages = [ virtualbox ];
|
|
|
|
environment.systemPackages = [ virtualbox ];
|
2012-03-01 21:10:08 +01:00
|
|
|
|
2012-03-20 17:30:43 +01:00
|
|
|
users.extraGroups = singleton { name = "vboxusers"; };
|
2012-08-20 22:19:57 +02:00
|
|
|
|
2012-03-20 17:30:43 +01:00
|
|
|
services.udev.extraRules =
|
|
|
|
''
|
2012-08-20 22:19:57 +02:00
|
|
|
KERNEL=="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd"
|
|
|
|
KERNEL=="vboxnetctl", OWNER="root", GROUP="root", MODE="0600", TAG+="systemd"
|
2012-03-20 17:30:43 +01:00
|
|
|
'';
|
2012-03-21 13:28:14 +01:00
|
|
|
|
|
|
|
# Since we lack the right setuid binaries, set up a host-only network by default.
|
2012-08-20 22:19:57 +02:00
|
|
|
|
|
|
|
jobs."vboxnet0" =
|
|
|
|
{ description = "VirtualBox vboxnet0 Interface";
|
|
|
|
requires = [ "dev-vboxnetctl.device" ];
|
|
|
|
after = [ "dev-vboxnetctl.device" ];
|
|
|
|
before = [ "network-interfaces.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2012-03-21 13:28:14 +01:00
|
|
|
path = [ virtualbox ];
|
2012-08-20 22:19:57 +02:00
|
|
|
preStart =
|
2012-03-21 13:28:14 +01:00
|
|
|
''
|
|
|
|
if ! [ -e /sys/class/net/vboxnet0 ]; then
|
|
|
|
VBoxManage hostonlyif create
|
|
|
|
fi
|
|
|
|
'';
|
2012-08-20 22:19:57 +02:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
VBoxManage hostonlyif remove vboxnet0
|
|
|
|
'';
|
2012-03-21 13:28:14 +01:00
|
|
|
};
|
|
|
|
|
2012-03-21 13:38:11 +01:00
|
|
|
networking.interfaces = [ { name = "vboxnet0"; ipAddress = "192.168.56.1"; subnetMask = "255.255.255.0"; } ];
|
2012-03-01 21:10:08 +01:00
|
|
|
}
|