1 { config, lib, pkgs, ... }:
3 inherit (lib) getExe' literalExpression mkEnableOption mkIf mkOption mkRenamedOptionModule optionals optionalString types;
4 cfg = config.virtualisation.vmware.guest;
5 xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse;
9 (mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ])
13 maintainers = [ lib.maintainers.kjeremy ];
16 options.virtualisation.vmware.guest = {
17 enable = mkEnableOption "VMWare Guest Support";
20 default = !config.services.xserver.enable;
21 defaultText = literalExpression "!config.services.xserver.enable";
22 description = "Whether to disable X11-related features.";
27 default = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;
28 defaultText = literalExpression "if config.virtualisation.vmware.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;";
29 example = literalExpression "pkgs.open-vm-tools";
30 description = "Package providing open-vm-tools.";
34 config = mkIf cfg.enable {
36 assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64;
37 message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
40 boot.initrd.availableKernelModules = [ "mptspi" ];
41 boot.initrd.kernelModules = optionals pkgs.stdenv.hostPlatform.isx86 [ "vmw_pvscsi" ];
43 environment.systemPackages = [ cfg.package ];
45 systemd.services.vmware =
46 { description = "VMWare Guest Service";
47 wantedBy = [ "multi-user.target" ];
48 after = [ "display-manager.service" ];
49 unitConfig.ConditionVirtualization = "vmware";
50 serviceConfig.ExecStart = getExe' cfg.package "vmtoolsd";
53 # Mount the vmblock for drag-and-drop and copy-and-paste.
54 systemd.mounts = mkIf (!cfg.headless) [
56 description = "VMware vmblock fuse mount";
57 documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ];
58 unitConfig.ConditionVirtualization = "vmware";
59 what = getExe' cfg.package "vmware-vmblock-fuse";
60 where = "/run/vmblock-fuse";
62 options = "subtype=vmware-vmblock,default_permissions,allow_other";
63 wantedBy = [ "multi-user.target" ];
67 security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) {
71 source = getExe' cfg.package "vmware-user-suid-wrapper";
74 environment.etc.vmware-tools.source = "${cfg.package}/etc/vmware-tools/*";
76 services.xserver = mkIf (!cfg.headless) {
77 modules = optionals pkgs.stdenv.hostPlatform.isx86 [ xf86inputvmmouse ];
79 config = optionalString (pkgs.stdenv.hostPlatform.isx86) ''
82 MatchDevicePath "/dev/input/event*"
83 MatchProduct "ImPS/2 Generic Wheel Mouse"
88 displayManager.sessionCommands = ''
89 ${getExe' cfg.package "vmware-user-suid-wrapper"}
93 services.udev.packages = [ cfg.package ];