2012-02-25 20:10:53 +00:00
|
|
|
# Module for VirtualBox guests.
|
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.virtualbox;
|
2011-09-19 13:20:09 +00:00
|
|
|
kernel = config.boot.kernelPackages;
|
2010-09-07 13:28:17 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2012-10-10 20:49:47 +00:00
|
|
|
optionalAttrs (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) # ugly...
|
2010-09-07 13:28:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
services.virtualbox = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the VirtualBox service and other guest additions.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
2010-09-07 13:28:17 +00:00
|
|
|
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2012-02-25 20:10:53 +00:00
|
|
|
environment.systemPackages = [ kernel.virtualboxGuestAdditions ];
|
2011-08-09 19:53:01 +00:00
|
|
|
|
2011-09-19 13:20:09 +00:00
|
|
|
boot.extraModulePackages = [ kernel.virtualboxGuestAdditions ];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-07 13:28:17 +00:00
|
|
|
jobs.virtualbox =
|
2012-08-23 14:25:27 +00:00
|
|
|
{ description = "VirtualBox Guest Services";
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2012-08-06 18:59:58 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "dev-vboxguest.device" ];
|
|
|
|
after = [ "dev-vboxguest.device" ];
|
2010-09-07 13:28:17 +00:00
|
|
|
|
2012-02-25 20:10:53 +00:00
|
|
|
exec = "${kernel.virtualboxGuestAdditions}/sbin/VBoxService --foreground";
|
2010-09-07 13:28:17 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 01:03:09 +00:00
|
|
|
services.xserver.videoDrivers = mkOverride 50 [ "virtualbox" ];
|
|
|
|
|
|
|
|
services.xserver.config =
|
|
|
|
''
|
|
|
|
Section "InputDevice"
|
|
|
|
Identifier "VBoxMouse"
|
|
|
|
Driver "vboxmouse"
|
|
|
|
EndSection
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.xserver.serverLayoutSection =
|
|
|
|
''
|
|
|
|
InputDevice "VBoxMouse"
|
|
|
|
'';
|
2012-08-06 18:59:58 +00:00
|
|
|
|
2012-03-16 01:29:51 +00:00
|
|
|
services.xserver.displayManager.sessionCommands =
|
|
|
|
''
|
|
|
|
PATH=${makeSearchPath "bin" [ pkgs.gnugrep pkgs.which pkgs.xorg.xorgserver ]}:$PATH \
|
|
|
|
${kernel.virtualboxGuestAdditions}/bin/VBoxClient-all
|
|
|
|
'';
|
2012-03-23 11:52:06 +00: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 18:59:58 +00:00
|
|
|
|
|
|
|
# Allow systemd dependencies on vboxguest.
|
|
|
|
KERNEL=="vboxguest", TAG+="systemd"
|
2012-03-23 11:52:06 +00:00
|
|
|
'';
|
2012-06-11 22:37:55 +00:00
|
|
|
|
2012-08-06 18:59:58 +00:00
|
|
|
# Make the ACPI Shutdown command to do the right thing.
|
2012-06-11 22:37:55 +00:00
|
|
|
services.acpid.enable = true;
|
|
|
|
services.acpid.powerEventCommands = "poweroff";
|
2010-09-07 13:28:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|