1 { config, lib, pkgs, ... }:
3 cfg = config.virtualisation.vmware.guest;
4 open-vm-tools = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;
5 xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse;
9 (lib.mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ])
12 options.virtualisation.vmware.guest = {
13 enable = lib.mkEnableOption "VMWare Guest Support";
14 headless = lib.mkOption {
15 type = lib.types.bool;
16 default = !config.services.xserver.enable;
17 defaultText = "!config.services.xserver.enable";
18 description = "Whether to disable X11-related features.";
22 config = lib.mkIf cfg.enable {
24 assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64;
25 message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
28 boot.initrd.availableKernelModules = [ "mptspi" ];
29 boot.initrd.kernelModules = lib.optionals pkgs.stdenv.hostPlatform.isx86 [ "vmw_pvscsi" ];
31 environment.systemPackages = [ open-vm-tools ];
33 systemd.services.vmware =
34 { description = "VMWare Guest Service";
35 wantedBy = [ "multi-user.target" ];
36 after = [ "display-manager.service" ];
37 unitConfig.ConditionVirtualization = "vmware";
38 serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd";
41 # Mount the vmblock for drag-and-drop and copy-and-paste.
42 systemd.mounts = lib.mkIf (!cfg.headless) [
44 description = "VMware vmblock fuse mount";
45 documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ];
46 unitConfig.ConditionVirtualization = "vmware";
47 what = "${open-vm-tools}/bin/vmware-vmblock-fuse";
48 where = "/run/vmblock-fuse";
50 options = "subtype=vmware-vmblock,default_permissions,allow_other";
51 wantedBy = [ "multi-user.target" ];
55 security.wrappers.vmware-user-suid-wrapper = lib.mkIf (!cfg.headless) {
59 source = "${open-vm-tools}/bin/vmware-user-suid-wrapper";
62 environment.etc.vmware-tools.source = "${open-vm-tools}/etc/vmware-tools/*";
64 services.xserver = lib.mkIf (!cfg.headless) {
65 modules = lib.optionals pkgs.stdenv.hostPlatform.isx86 [ xf86inputvmmouse ];
67 config = lib.optionalString (pkgs.stdenv.hostPlatform.isx86) ''
70 MatchDevicePath "/dev/input/event*"
71 MatchProduct "ImPS/2 Generic Wheel Mouse"
76 displayManager.sessionCommands = ''
77 ${open-vm-tools}/bin/vmware-user-suid-wrapper
81 services.udev.packages = [ open-vm-tools ];