2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-01 20:10:08 +00:00
|
|
|
|
2014-04-14 15:26:48 +01: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 10:33:24 +01:00
|
|
|
users.extraGroups.vboxusers.gid = config.ids.gids.vboxusers;
|
2012-08-20 21:19:57 +01:00
|
|
|
|
2012-03-20 16:30:43 +00:00
|
|
|
services.udev.extraRules =
|
|
|
|
''
|
2012-08-20 21:19:57 +01:00
|
|
|
KERNEL=="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd"
|
|
|
|
KERNEL=="vboxnetctl", OWNER="root", GROUP="root", MODE="0600", TAG+="systemd"
|
2013-05-04 10:15:24 +01: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 21:19:57 +01:00
|
|
|
|
2013-10-09 18:33:12 +01:00
|
|
|
systemd.services."vboxnet0" =
|
2012-08-20 21:19:57 +01:00
|
|
|
{ description = "VirtualBox vboxnet0 Interface";
|
|
|
|
requires = [ "dev-vboxnetctl.device" ];
|
|
|
|
after = [ "dev-vboxnetctl.device" ];
|
2012-10-11 03:47:50 +01:00
|
|
|
wantedBy = [ "network.target" "sys-subsystem-net-devices-vboxnet0.device" ];
|
2012-03-21 12:28:14 +00:00
|
|
|
path = [ virtualbox ];
|
2013-10-09 18:33:12 +01: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 21:19:57 +01: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
|
|
|
}
|