at 22.05-pre 2.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.virtualisation.vmware.guest; 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 imports = [ 12 (mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ]) 13 ]; 14 15 options.virtualisation.vmware.guest = { 16 enable = mkEnableOption "VMWare Guest Support"; 17 headless = mkOption { 18 type = types.bool; 19 default = false; 20 description = "Whether to disable X11-related features."; 21 }; 22 }; 23 24 config = mkIf cfg.enable { 25 assertions = [ { 26 assertion = pkgs.stdenv.hostPlatform.isx86; 27 message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}"; 28 } ]; 29 30 boot.initrd.kernelModules = [ "vmw_pvscsi" ]; 31 32 environment.systemPackages = [ open-vm-tools ]; 33 34 systemd.services.vmware = 35 { description = "VMWare Guest Service"; 36 wantedBy = [ "multi-user.target" ]; 37 serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd"; 38 }; 39 40 # Mount the vmblock for drag-and-drop and copy-and-paste. 41 systemd.mounts = mkIf (!cfg.headless) [ 42 { 43 description = "VMware vmblock fuse mount"; 44 documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ]; 45 before = [ "vmware.service" ]; 46 wants = [ "vmware.service" ]; 47 what = "${open-vm-tools}/bin/vmware-vmblock-fuse"; 48 where = "/run/vmblock-fuse"; 49 type = "fuse"; 50 options = "subtype=vmware-vmblock,default_permissions,allow_other"; 51 wantedBy = [ "multi-user.target" ]; 52 } 53 ]; 54 55 security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) { 56 setuid = true; 57 owner = "root"; 58 group = "root"; 59 source = "${open-vm-tools}/bin/vmware-user-suid-wrapper"; 60 }; 61 62 environment.etc.vmware-tools.source = "${open-vm-tools}/etc/vmware-tools/*"; 63 64 services.xserver = mkIf (!cfg.headless) { 65 videoDrivers = mkOverride 50 [ "vmware" ]; 66 modules = [ xf86inputvmmouse ]; 67 68 config = '' 69 Section "InputClass" 70 Identifier "VMMouse" 71 MatchDevicePath "/dev/input/event*" 72 MatchProduct "ImPS/2 Generic Wheel Mouse" 73 Driver "vmmouse" 74 EndSection 75 ''; 76 77 displayManager.sessionCommands = '' 78 ${open-vm-tools}/bin/vmware-user-suid-wrapper 79 ''; 80 }; 81 82 services.udev.packages = [ open-vm-tools ]; 83 }; 84}