2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-01 20:10:08 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2012-03-01 20:10:08 +00:00
|
|
|
|
2012-03-10 14:34:40 +00:00
|
|
|
let virtualbox = config.boot.kernelPackages.virtualbox; in
|
|
|
|
|
2012-03-01 20:10:08 +00:00
|
|
|
{
|
|
|
|
boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ];
|
2012-03-10 14:34:40 +00:00
|
|
|
boot.extraModulePackages = [ virtualbox ];
|
|
|
|
environment.systemPackages = [ virtualbox ];
|
2012-03-01 20:10:08 +00:00
|
|
|
|
2013-08-23 09:33:24 +00:00
|
|
|
users.extraGroups.vboxusers.gid = config.ids.gids.vboxusers;
|
2012-08-20 20:19:57 +00:00
|
|
|
|
2012-03-20 16:30:43 +00:00
|
|
|
services.udev.extraRules =
|
|
|
|
''
|
2012-08-20 20:19:57 +00:00
|
|
|
KERNEL=="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd"
|
|
|
|
KERNEL=="vboxnetctl", OWNER="root", GROUP="root", MODE="0600", TAG+="systemd"
|
2013-05-04 09:15:24 +00:00
|
|
|
SUBSYSTEM=="usb_device", ACTION=="add", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
|
|
|
SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
|
|
|
SUBSYSTEM=="usb_device", ACTION=="remove", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor"
|
|
|
|
SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor"
|
2012-03-20 16:30:43 +00:00
|
|
|
'';
|
2012-03-21 12:28:14 +00:00
|
|
|
|
|
|
|
# Since we lack the right setuid binaries, set up a host-only network by default.
|
2012-08-20 20:19:57 +00:00
|
|
|
|
2013-10-09 17:33:12 +00:00
|
|
|
systemd.services."vboxnet0" =
|
2012-08-20 20:19:57 +00:00
|
|
|
{ description = "VirtualBox vboxnet0 Interface";
|
|
|
|
requires = [ "dev-vboxnetctl.device" ];
|
|
|
|
after = [ "dev-vboxnetctl.device" ];
|
2012-10-11 02:47:50 +00:00
|
|
|
wantedBy = [ "network.target" "sys-subsystem-net-devices-vboxnet0.device" ];
|
2012-03-21 12:28:14 +00:00
|
|
|
path = [ virtualbox ];
|
2013-10-09 17:33:12 +00:00
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script =
|
2012-03-21 12:28:14 +00:00
|
|
|
''
|
|
|
|
if ! [ -e /sys/class/net/vboxnet0 ]; then
|
|
|
|
VBoxManage hostonlyif create
|
|
|
|
fi
|
|
|
|
'';
|
2012-08-20 20:19:57 +00:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
VBoxManage hostonlyif remove vboxnet0
|
|
|
|
'';
|
2012-03-21 12:28:14 +00:00
|
|
|
};
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
networking.interfaces.vboxnet0 = { ipAddress = "192.168.56.1"; prefixLength = 24; };
|
2012-03-01 20:10:08 +00:00
|
|
|
}
|