|
1 | 1 | { config, lib, pkgs, ... }: |
2 | 2 | let |
| 3 | + inherit (lib) getExe' literalExpression mkEnableOption mkIf mkOption mkRenamedOptionModule optionals optionalString types; |
3 | 4 | cfg = config.virtualisation.vmware.guest; |
4 | | - open-vm-tools = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools; |
5 | 5 | xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse; |
6 | 6 | in |
7 | 7 | { |
8 | 8 | imports = [ |
9 | | - (lib.mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ]) |
| 9 | + (mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ]) |
10 | 10 | ]; |
11 | 11 |
|
12 | 12 | options.virtualisation.vmware.guest = { |
13 | | - enable = lib.mkEnableOption "VMWare Guest Support"; |
14 | | - headless = lib.mkOption { |
15 | | - type = lib.types.bool; |
| 13 | + enable = mkEnableOption "VMWare Guest Support"; |
| 14 | + headless = mkOption { |
| 15 | + type = types.bool; |
16 | 16 | default = !config.services.xserver.enable; |
17 | | - defaultText = "!config.services.xserver.enable"; |
| 17 | + defaultText = literalExpression "!config.services.xserver.enable"; |
18 | 18 | description = "Whether to disable X11-related features."; |
19 | 19 | }; |
| 20 | + |
| 21 | + package = mkOption { |
| 22 | + type = types.package; |
| 23 | + default = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools; |
| 24 | + defaultText = literalExpression "if config.virtualisation.vmware.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;"; |
| 25 | + example = literalExpression "pkgs.open-vm-tools"; |
| 26 | + description = "Package providing open-vm-tools."; |
| 27 | + }; |
20 | 28 | }; |
21 | 29 |
|
22 | | - config = lib.mkIf cfg.enable { |
| 30 | + config = mkIf cfg.enable { |
23 | 31 | assertions = [ { |
24 | 32 | assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64; |
25 | 33 | message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}"; |
26 | 34 | } ]; |
27 | 35 |
|
28 | 36 | boot.initrd.availableKernelModules = [ "mptspi" ]; |
29 | | - boot.initrd.kernelModules = lib.optionals pkgs.stdenv.hostPlatform.isx86 [ "vmw_pvscsi" ]; |
| 37 | + boot.initrd.kernelModules = optionals pkgs.stdenv.hostPlatform.isx86 [ "vmw_pvscsi" ]; |
30 | 38 |
|
31 | | - environment.systemPackages = [ open-vm-tools ]; |
| 39 | + environment.systemPackages = [ cfg.package ]; |
32 | 40 |
|
33 | 41 | systemd.services.vmware = |
34 | 42 | { description = "VMWare Guest Service"; |
35 | 43 | wantedBy = [ "multi-user.target" ]; |
36 | 44 | after = [ "display-manager.service" ]; |
37 | 45 | unitConfig.ConditionVirtualization = "vmware"; |
38 | | - serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd"; |
| 46 | + serviceConfig.ExecStart = getExe' cfg.package "vmtoolsd"; |
39 | 47 | }; |
40 | 48 |
|
41 | 49 | # Mount the vmblock for drag-and-drop and copy-and-paste. |
42 | | - systemd.mounts = lib.mkIf (!cfg.headless) [ |
| 50 | + systemd.mounts = mkIf (!cfg.headless) [ |
43 | 51 | { |
44 | 52 | description = "VMware vmblock fuse mount"; |
45 | 53 | documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ]; |
46 | 54 | unitConfig.ConditionVirtualization = "vmware"; |
47 | | - what = "${open-vm-tools}/bin/vmware-vmblock-fuse"; |
| 55 | + what = getExe' cfg.package "vmware-vmblock-fuse"; |
48 | 56 | where = "/run/vmblock-fuse"; |
49 | 57 | type = "fuse"; |
50 | 58 | options = "subtype=vmware-vmblock,default_permissions,allow_other"; |
51 | 59 | wantedBy = [ "multi-user.target" ]; |
52 | 60 | } |
53 | 61 | ]; |
54 | 62 |
|
55 | | - security.wrappers.vmware-user-suid-wrapper = lib.mkIf (!cfg.headless) { |
| 63 | + security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) { |
56 | 64 | setuid = true; |
57 | 65 | owner = "root"; |
58 | 66 | group = "root"; |
59 | | - source = "${open-vm-tools}/bin/vmware-user-suid-wrapper"; |
| 67 | + source = getExe' cfg.package "vmware-user-suid-wrapper"; |
60 | 68 | }; |
61 | 69 |
|
62 | | - environment.etc.vmware-tools.source = "${open-vm-tools}/etc/vmware-tools/*"; |
| 70 | + environment.etc.vmware-tools.source = "${cfg.package}/etc/vmware-tools/*"; |
63 | 71 |
|
64 | | - services.xserver = lib.mkIf (!cfg.headless) { |
65 | | - modules = lib.optionals pkgs.stdenv.hostPlatform.isx86 [ xf86inputvmmouse ]; |
| 72 | + services.xserver = mkIf (!cfg.headless) { |
| 73 | + modules = optionals pkgs.stdenv.hostPlatform.isx86 [ xf86inputvmmouse ]; |
66 | 74 |
|
67 | | - config = lib.optionalString (pkgs.stdenv.hostPlatform.isx86) '' |
| 75 | + config = optionalString (pkgs.stdenv.hostPlatform.isx86) '' |
68 | 76 | Section "InputClass" |
69 | 77 | Identifier "VMMouse" |
70 | 78 | MatchDevicePath "/dev/input/event*" |
|
74 | 82 | ''; |
75 | 83 |
|
76 | 84 | displayManager.sessionCommands = '' |
77 | | - ${open-vm-tools}/bin/vmware-user-suid-wrapper |
| 85 | + ${getExe' cfg.package "vmware-user-suid-wrapper"} |
78 | 86 | ''; |
79 | 87 | }; |
80 | 88 |
|
81 | | - services.udev.packages = [ open-vm-tools ]; |
| 89 | + services.udev.packages = [ cfg.package ]; |
82 | 90 | }; |
83 | 91 | } |
0 commit comments