mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-19 04:02:10 +00:00
29027fd1e1
Using pkgs.lib on the spine of module evaluation is problematic because the pkgs argument depends on the result of module evaluation. To prevent an infinite recursion, pkgs and some of the modules are evaluated twice, which is inefficient. Using ‘with lib’ prevents this problem.
90 lines
2 KiB
Nix
90 lines
2 KiB
Nix
# Module for VirtualBox guests.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.virtualbox;
|
|
kernel = config.boot.kernelPackages;
|
|
|
|
in
|
|
|
|
optionalAttrs (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) # ugly...
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.virtualbox = {
|
|
|
|
enable = mkOption {
|
|
default = false;
|
|
description = "Whether to enable the VirtualBox service and other guest additions.";
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ kernel.virtualboxGuestAdditions ];
|
|
|
|
boot.extraModulePackages = [ kernel.virtualboxGuestAdditions ];
|
|
|
|
boot.kernelModules = [ "vboxsf" ];
|
|
|
|
users.extraGroups.vboxsf.gid = config.ids.gids.vboxsf;
|
|
|
|
systemd.services.virtualbox =
|
|
{ description = "VirtualBox Guest Services";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
requires = [ "dev-vboxguest.device" ];
|
|
after = [ "dev-vboxguest.device" ];
|
|
|
|
unitConfig.ConditionVirtualization = "oracle";
|
|
|
|
serviceConfig.ExecStart = "@${kernel.virtualboxGuestAdditions}/sbin/VBoxService VBoxService --foreground";
|
|
};
|
|
|
|
hardware.opengl.videoDrivers = mkOverride 50 [ "virtualbox" ];
|
|
|
|
services.xserver.config =
|
|
''
|
|
Section "InputDevice"
|
|
Identifier "VBoxMouse"
|
|
Driver "vboxmouse"
|
|
EndSection
|
|
'';
|
|
|
|
services.xserver.serverLayoutSection =
|
|
''
|
|
InputDevice "VBoxMouse"
|
|
'';
|
|
|
|
services.xserver.displayManager.sessionCommands =
|
|
''
|
|
PATH=${makeSearchPath "bin" [ pkgs.gnugrep pkgs.which pkgs.xorg.xorgserver ]}:$PATH \
|
|
${kernel.virtualboxGuestAdditions}/bin/VBoxClient-all
|
|
'';
|
|
|
|
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"
|
|
|
|
# Allow systemd dependencies on vboxguest.
|
|
KERNEL=="vboxguest", TAG+="systemd"
|
|
'';
|
|
};
|
|
|
|
}
|