1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.vmwareGuest;
7 open-vm-tools = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;
8 xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse;
9in
10{
11 options = {
12 services.vmwareGuest = {
13 enable = mkEnableOption "VMWare Guest Support";
14 headless = mkOption {
15 type = types.bool;
16 default = false;
17 description = "Whether to disable X11-related features.";
18 };
19 };
20 };
21
22 config = mkIf cfg.enable {
23 assertions = [ {
24 assertion = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64;
25 message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
26 } ];
27
28 environment.systemPackages = [ open-vm-tools ];
29
30 systemd.services.vmware =
31 { description = "VMWare Guest Service";
32 wantedBy = [ "multi-user.target" ];
33 serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd";
34 };
35
36 environment.etc."vmware-tools".source = "${open-vm-tools}/etc/vmware-tools/*";
37
38 services.xserver = mkIf (!cfg.headless) {
39 videoDrivers = mkOverride 50 [ "vmware" ];
40 modules = [ xf86inputvmmouse ];
41
42 config = ''
43 Section "InputClass"
44 Identifier "VMMouse"
45 MatchDevicePath "/dev/input/event*"
46 MatchProduct "ImPS/2 Generic Wheel Mouse"
47 Driver "vmmouse"
48 EndSection
49 '';
50
51 displayManager.sessionCommands = ''
52 ${open-vm-tools}/bin/vmware-user-suid-wrapper
53 '';
54 };
55 };
56}