2015-05-13 08:31:32 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2024-10-11 10:40:48 -04:00
|
|
|
inherit (lib)
|
|
|
|
getExe'
|
|
|
|
literalExpression
|
2024-12-12 10:35:08 -05:00
|
|
|
maintainers
|
2024-10-11 10:40:48 -04:00
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
mkRenamedOptionModule
|
|
|
|
optionals
|
|
|
|
optionalString
|
|
|
|
types
|
|
|
|
;
|
2018-05-28 15:24:29 +08:00
|
|
|
cfg = config.virtualisation.vmware.guest;
|
2016-11-16 23:43:42 +01:00
|
|
|
xf86inputvmmouse = pkgs.xorg.xf86inputvmmouse;
|
2015-05-13 08:31:32 +00:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
2024-10-11 10:40:48 -04:00
|
|
|
(mkRenamedOptionModule [ "services" "vmwareGuest" ] [ "virtualisation" "vmware" "guest" ])
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2024-10-23 11:13:05 -04:00
|
|
|
meta = {
|
2024-12-12 10:35:08 -05:00
|
|
|
maintainers = [ maintainers.kjeremy ];
|
2024-10-23 11:13:05 -04:00
|
|
|
};
|
|
|
|
|
2018-05-28 15:24:29 +08:00
|
|
|
options.virtualisation.vmware.guest = {
|
2024-10-11 10:40:48 -04:00
|
|
|
enable = mkEnableOption "VMWare Guest Support";
|
|
|
|
headless = mkOption {
|
|
|
|
type = types.bool;
|
2022-11-01 16:57:30 +01:00
|
|
|
default = !config.services.xserver.enable;
|
2024-10-11 10:40:48 -04:00
|
|
|
defaultText = literalExpression "!config.services.xserver.enable";
|
2018-05-28 15:24:29 +08:00
|
|
|
description = "Whether to disable X11-related features.";
|
2016-12-01 16:59:53 +02:00
|
|
|
};
|
2024-10-11 10:40:48 -04:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = if cfg.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;
|
|
|
|
defaultText = literalExpression "if config.virtualisation.vmware.headless then pkgs.open-vm-tools-headless else pkgs.open-vm-tools;";
|
|
|
|
example = literalExpression "pkgs.open-vm-tools";
|
|
|
|
description = "Package providing open-vm-tools.";
|
|
|
|
};
|
2015-05-13 08:31:32 +00:00
|
|
|
};
|
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
config = mkIf cfg.enable {
|
2015-05-13 08:31:32 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
2023-07-07 15:40:29 -04:00
|
|
|
assertion = pkgs.stdenv.hostPlatform.isx86 || pkgs.stdenv.hostPlatform.isAarch64;
|
2018-08-20 15:11:29 -04:00
|
|
|
message = "VMWare guest is not currently supported on ${pkgs.stdenv.hostPlatform.system}";
|
2015-05-13 08:31:32 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-01-10 17:05:58 +01:00
|
|
|
boot.initrd.availableKernelModules = [ "mptspi" ];
|
2024-10-11 10:40:48 -04:00
|
|
|
boot.initrd.kernelModules = optionals pkgs.stdenv.hostPlatform.isx86 [ "vmw_pvscsi" ];
|
2018-05-28 15:24:29 +08:00
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2015-05-13 08:31:32 +00:00
|
|
|
|
|
|
|
systemd.services.vmware = {
|
|
|
|
description = "VMWare Guest Service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-11-25 04:29:18 +02:00
|
|
|
after = [ "display-manager.service" ];
|
|
|
|
unitConfig.ConditionVirtualization = "vmware";
|
2024-10-11 10:40:48 -04:00
|
|
|
serviceConfig.ExecStart = getExe' cfg.package "vmtoolsd";
|
2015-05-13 08:31:32 +00:00
|
|
|
};
|
|
|
|
|
2021-09-19 11:15:41 -04:00
|
|
|
# Mount the vmblock for drag-and-drop and copy-and-paste.
|
2024-10-11 10:40:48 -04:00
|
|
|
systemd.mounts = mkIf (!cfg.headless) [
|
2021-09-19 11:15:41 -04:00
|
|
|
{
|
|
|
|
description = "VMware vmblock fuse mount";
|
|
|
|
documentation = [
|
|
|
|
"https://github.com/vmware/open-vm-tools/blob/master/open-vm-tools/vmblock-fuse/design.txt"
|
|
|
|
];
|
2021-11-25 04:29:18 +02:00
|
|
|
unitConfig.ConditionVirtualization = "vmware";
|
2024-10-11 10:40:48 -04:00
|
|
|
what = getExe' cfg.package "vmware-vmblock-fuse";
|
2021-09-19 11:15:41 -04:00
|
|
|
where = "/run/vmblock-fuse";
|
|
|
|
type = "fuse";
|
|
|
|
options = "subtype=vmware-vmblock,default_permissions,allow_other";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) {
|
2021-10-20 16:12:07 +02:00
|
|
|
setuid = true;
|
2021-09-20 23:45:24 +02:00
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2024-10-11 10:40:48 -04:00
|
|
|
source = getExe' cfg.package "vmware-user-suid-wrapper";
|
2021-09-20 23:45:24 +02:00
|
|
|
};
|
2021-09-19 11:15:41 -04:00
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
environment.etc.vmware-tools.source = "${cfg.package}/etc/vmware-tools/*";
|
2016-04-23 01:08:06 +00:00
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
services.xserver = mkIf (!cfg.headless) {
|
|
|
|
modules = optionals pkgs.stdenv.hostPlatform.isx86 [ xf86inputvmmouse ];
|
2015-05-13 08:31:32 +00:00
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
config = optionalString (pkgs.stdenv.hostPlatform.isx86) ''
|
2016-11-16 23:43:42 +01:00
|
|
|
Section "InputClass"
|
2015-05-13 08:31:32 +00:00
|
|
|
Identifier "VMMouse"
|
2016-11-16 23:43:42 +01:00
|
|
|
MatchDevicePath "/dev/input/event*"
|
|
|
|
MatchProduct "ImPS/2 Generic Wheel Mouse"
|
2015-05-13 08:31:32 +00:00
|
|
|
Driver "vmmouse"
|
|
|
|
EndSection
|
|
|
|
'';
|
|
|
|
|
|
|
|
displayManager.sessionCommands = ''
|
2024-10-11 10:40:48 -04:00
|
|
|
${getExe' cfg.package "vmware-user-suid-wrapper"}
|
2015-05-13 08:31:32 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-07-13 21:26:58 -04:00
|
|
|
|
2024-10-11 10:40:48 -04:00
|
|
|
services.udev.packages = [ cfg.package ];
|
2015-05-13 08:31:32 +00:00
|
|
|
};
|
|
|
|
}
|