Skip to content

Commit 145c5d0

Browse files
committed
virtualisation.vmware.guest: allow the user to override the open-vm-tools package
1 parent cf3b78e commit 145c5d0

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,78 @@
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

1212
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;
1616
default = !config.services.xserver.enable;
17-
defaultText = "!config.services.xserver.enable";
17+
defaultText = literalExpression "!config.services.xserver.enable";
1818
description = "Whether to disable X11-related features.";
1919
};
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+
};
2028
};
2129

22-
config = lib.mkIf cfg.enable {
30+
config = mkIf cfg.enable {
2331
assertions = [ {
2432
assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64;
2533
message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
2634
} ];
2735

2836
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" ];
3038

31-
environment.systemPackages = [ open-vm-tools ];
39+
environment.systemPackages = [ cfg.package ];
3240

3341
systemd.services.vmware =
3442
{ description = "VMWare Guest Service";
3543
wantedBy = [ "multi-user.target" ];
3644
after = [ "display-manager.service" ];
3745
unitConfig.ConditionVirtualization = "vmware";
38-
serviceConfig.ExecStart = "${open-vm-tools}/bin/vmtoolsd";
46+
serviceConfig.ExecStart = getExe' cfg.package "vmtoolsd";
3947
};
4048

4149
# Mount the vmblock for drag-and-drop and copy-and-paste.
42-
systemd.mounts = lib.mkIf (!cfg.headless) [
50+
systemd.mounts = mkIf (!cfg.headless) [
4351
{
4452
description = "VMware vmblock fuse mount";
4553
documentation = [ "https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt" ];
4654
unitConfig.ConditionVirtualization = "vmware";
47-
what = "${open-vm-tools}/bin/vmware-vmblock-fuse";
55+
what = getExe' cfg.package "vmware-vmblock-fuse";
4856
where = "/run/vmblock-fuse";
4957
type = "fuse";
5058
options = "subtype=vmware-vmblock,default_permissions,allow_other";
5159
wantedBy = [ "multi-user.target" ];
5260
}
5361
];
5462

55-
security.wrappers.vmware-user-suid-wrapper = lib.mkIf (!cfg.headless) {
63+
security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) {
5664
setuid = true;
5765
owner = "root";
5866
group = "root";
59-
source = "${open-vm-tools}/bin/vmware-user-suid-wrapper";
67+
source = getExe' cfg.package "vmware-user-suid-wrapper";
6068
};
6169

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

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

67-
config = lib.optionalString (pkgs.stdenv.hostPlatform.isx86) ''
75+
config = optionalString (pkgs.stdenv.hostPlatform.isx86) ''
6876
Section "InputClass"
6977
Identifier "VMMouse"
7078
MatchDevicePath "/dev/input/event*"
@@ -74,10 +82,10 @@ in
7482
'';
7583

7684
displayManager.sessionCommands = ''
77-
${open-vm-tools}/bin/vmware-user-suid-wrapper
85+
${getExe' cfg.package "vmware-user-suid-wrapper"}
7886
'';
7987
};
8088

81-
services.udev.packages = [ open-vm-tools ];
89+
services.udev.packages = [ cfg.package ];
8290
};
8391
}

0 commit comments

Comments
 (0)