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