Skip to content

Commit a04d33c

Browse files
vmware-guest: allow the user to override the open-vm-tools package (#347939)
2 parents 75c9076 + c756281 commit a04d33c

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed
Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,82 @@
11
{ config, lib, pkgs, ... }:
22
let
3+
inherit (lib) getExe' literalExpression mkEnableOption mkIf mkOption mkRenamedOptionModule optionals optionalString types;
34
cfg = config.virtualisation.vmware.guest;
4-
open-vm-tools = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;
55
xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse;
66
in
77
{
88
imports = [
9-
(lib.mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ])
9+
(mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ])
1010
];
1111

12+
meta = {
13+
maintainers = [ lib.maintainers.kjeremy ];
14+
};
15+
1216
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;
1620
default = !config.services.xserver.enable;
17-
defaultText = "!config.services.xserver.enable";
21+
defaultText = literalExpression "!config.services.xserver.enable";
1822
description = "Whether to disable X11-related features.";
1923
};
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+
};
2032
};
2133

22-
config = lib.mkIf cfg.enable {
34+
config = mkIf cfg.enable {
2335
assertions = [ {
2436
assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64;
2537
message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
2638
} ];
2739

2840
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" ];
3042

31-
environment.systemPackages = [ open-vm-tools ];
43+
environment.systemPackages = [ cfg.package ];
3244

3345
systemd.services.vmware =
3446
{ description = "VMWare Guest Service";
3547
wantedBy = [ "multi-user.target" ];
3648
after = [ "display-manager.service" ];
3749
unitConfig.ConditionVirtualization = "vmware";
38-
serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd";
50+
serviceConfig.ExecStart = getExe' cfg.package "vmtoolsd";
3951
};
4052

4153
# Mount the vmblock for drag-and-drop and copy-and-paste.
42-
systemd.mounts = lib.mkIf (!cfg.headless) [
54+
systemd.mounts = mkIf (!cfg.headless) [
4355
{
4456
description = "VMware vmblock fuse mount";
4557
documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ];
4658
unitConfig.ConditionVirtualization = "vmware";
47-
what = "${open-vm-tools}/bin/vmware-vmblock-fuse";
59+
what = getExe' cfg.package "vmware-vmblock-fuse";
4860
where = "/run/vmblock-fuse";
4961
type = "fuse";
5062
options = "subtype=vmware-vmblock,default_permissions,allow_other";
5163
wantedBy = [ "multi-user.target" ];
5264
}
5365
];
5466

55-
security.wrappers.vmware-user-suid-wrapper = lib.mkIf (!cfg.headless) {
67+
security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) {
5668
setuid = true;
5769
owner = "root";
5870
group = "root";
59-
source = "${open-vm-tools}/bin/vmware-user-suid-wrapper";
71+
source = getExe' cfg.package "vmware-user-suid-wrapper";
6072
};
6173

62-
environment.etc.vmware-tools.source = "${open-vm-tools}/etc/vmware-tools/*";
74+
environment.etc.vmware-tools.source = "${cfg.package}/etc/vmware-tools/*";
6375

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 ];
6678

67-
config = lib.optionalString (pkgs.stdenv.hostPlatform.isx86) ''
79+
config = optionalString (pkgs.stdenv.hostPlatform.isx86) ''
6880
Section "InputClass"
6981
Identifier "VMMouse"
7082
MatchDevicePath "/dev/input/event*"
@@ -74,10 +86,10 @@ in
7486
'';
7587

7688
displayManager.sessionCommands = ''
77-
${open-vm-tools}/bin/vmware-user-suid-wrapper
89+
${getExe' cfg.package "vmware-user-suid-wrapper"}
7890
'';
7991
};
8092

81-
services.udev.packages = [ open-vm-tools ];
93+
services.udev.packages = [ cfg.package ];
8294
};
8395
}

0 commit comments

Comments
 (0)