2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-01 21:10:08 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2012-03-01 21:10:08 +01:00
|
|
|
|
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
|
|
|
|
2013-08-23 11:33:24 +02:00
|
|
|
users.extraGroups.vboxusers.gid = config.ids.gids.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"
|
2014-06-25 15:52:05 +02:00
|
|
|
KERNEL=="vboxdrvu", OWNER="root", GROUP="root", MODE="0666", TAG+="systemd"
|
2012-08-20 22:19:57 +02:00
|
|
|
KERNEL=="vboxnetctl", OWNER="root", GROUP="root", MODE="0600", TAG+="systemd"
|
2013-05-04 11:15:24 +02: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 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
|
|
|
|
2013-10-09 19:33:12 +02:00
|
|
|
systemd.services."vboxnet0" =
|
2012-08-20 22:19:57 +02:00
|
|
|
{ description = "VirtualBox vboxnet0 Interface";
|
|
|
|
requires = [ "dev-vboxnetctl.device" ];
|
|
|
|
after = [ "dev-vboxnetctl.device" ];
|
2012-10-11 04:47:50 +02:00
|
|
|
wantedBy = [ "network.target" "sys-subsystem-net-devices-vboxnet0.device" ];
|
2012-03-21 13:28:14 +01:00
|
|
|
path = [ virtualbox ];
|
2013-10-09 19:33:12 +02:00
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script =
|
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
|
|
|
};
|
|
|
|
|
2014-08-31 18:46:16 +02:00
|
|
|
networking.interfaces.vboxnet0.ip4 = [ { address = "192.168.56.1"; prefixLength = 24; } ];
|
2012-03-01 21:10:08 +01:00
|
|
|
}
|