2012-02-26 00:10:53 +04:00
|
|
|
# Module for VirtualBox guests.
|
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-09-07 17:28:17 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2010-09-07 17:28:17 +04:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2015-08-13 13:17:32 +03:00
|
|
|
cfg = config.virtualisation.virtualbox.guest;
|
2011-09-19 17:20:09 +04:00
|
|
|
kernel = config.boot.kernelPackages;
|
2010-09-07 17:28:17 +04:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2015-08-13 13:17:32 +03:00
|
|
|
options.virtualisation.virtualbox.guest.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the VirtualBox service and other guest additions.";
|
2010-09-07 17:28:17 +04:00
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2010-09-07 17:28:17 +04:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2014-05-05 22:58:51 +04:00
|
|
|
assertions = [ {
|
|
|
|
assertion = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64;
|
|
|
|
message = "Virtualbox not currently supported on ${pkgs.stdenv.system}";
|
|
|
|
} ];
|
2010-09-07 17:28:17 +04:00
|
|
|
|
2012-02-26 00:10:53 +04:00
|
|
|
environment.systemPackages = [ kernel.virtualboxGuestAdditions ];
|
2011-08-09 23:53:01 +04:00
|
|
|
|
2011-09-19 17:20:09 +04:00
|
|
|
boot.extraModulePackages = [ kernel.virtualboxGuestAdditions ];
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2015-08-20 01:29:20 +03:00
|
|
|
boot.supportedFilesystems = [ "vboxsf" ];
|
|
|
|
boot.initrd.supportedFilesystems = [ "vboxsf" ];
|
2014-02-05 21:38:03 +04:00
|
|
|
|
2013-08-23 13:33:24 +04:00
|
|
|
users.extraGroups.vboxsf.gid = config.ids.gids.vboxsf;
|
2013-01-01 01:00:02 +04:00
|
|
|
|
2013-10-09 15:30:57 +04:00
|
|
|
systemd.services.virtualbox =
|
2012-08-23 18:25:27 +04:00
|
|
|
{ description = "VirtualBox Guest Services";
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2012-08-06 22:59:58 +04:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "dev-vboxguest.device" ];
|
|
|
|
after = [ "dev-vboxguest.device" ];
|
2010-09-07 17:28:17 +04:00
|
|
|
|
2013-10-09 15:30:57 +04:00
|
|
|
unitConfig.ConditionVirtualization = "oracle";
|
|
|
|
|
2015-08-04 04:03:24 +03:00
|
|
|
serviceConfig.ExecStart = "@${kernel.virtualboxGuestAdditions}/bin/VBoxService VBoxService --foreground";
|
2010-09-07 17:28:17 +04:00
|
|
|
};
|
|
|
|
|
2016-07-19 14:55:44 +03:00
|
|
|
services.xserver.videoDrivers = mkOverride 50 [ "virtualbox" "modesetting" ];
|
2012-03-16 05:03:09 +04:00
|
|
|
|
|
|
|
services.xserver.config =
|
|
|
|
''
|
|
|
|
Section "InputDevice"
|
|
|
|
Identifier "VBoxMouse"
|
|
|
|
Driver "vboxmouse"
|
|
|
|
EndSection
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.xserver.serverLayoutSection =
|
|
|
|
''
|
|
|
|
InputDevice "VBoxMouse"
|
|
|
|
'';
|
2012-08-06 22:59:58 +04:00
|
|
|
|
2012-03-16 05:29:51 +04:00
|
|
|
services.xserver.displayManager.sessionCommands =
|
|
|
|
''
|
2016-04-13 15:53:51 +03:00
|
|
|
PATH=${makeBinPath [ pkgs.gnugrep pkgs.which pkgs.xorg.xorgserver.out ]}:$PATH \
|
2012-03-16 05:29:51 +04:00
|
|
|
${kernel.virtualboxGuestAdditions}/bin/VBoxClient-all
|
|
|
|
'';
|
2012-03-23 15:52:06 +04:00
|
|
|
|
|
|
|
services.udev.extraRules =
|
|
|
|
''
|
|
|
|
# /dev/vboxuser is necessary for VBoxClient to work. Maybe we
|
|
|
|
# should restrict this to logged-in users.
|
|
|
|
KERNEL=="vboxuser", OWNER="root", GROUP="root", MODE="0666"
|
2012-08-06 22:59:58 +04:00
|
|
|
|
|
|
|
# Allow systemd dependencies on vboxguest.
|
2016-06-03 01:30:02 +03:00
|
|
|
SUBSYSTEM=="misc", KERNEL=="vboxguest", TAG+="systemd"
|
2012-03-23 15:52:06 +04:00
|
|
|
'';
|
2010-09-07 17:28:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|