Help needed to make Sway and Wayland work

I run NixOS 22.05 with the stable channel in VMWare Fusion 11.5.3, both x86-64.

I’m able to make Sway work using this configuration:

{ config, pkgs, ... }:

{
  imports = [ ./hardware-configuration.nix ];
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  virtualisation.vmware.guest.enable = true;
  networking.useDHCP = false;
  networking.interfaces.ens33.useDHCP = true;

  programs.sway.enable = true;
  environment.loginShellInit = ''
    if [ "$(tty)" == /dev/tty1 ]; then
      export WLR_NO_HARDWARE_CURSORS=1
      sway
    fi
  '';

  users.mutableUsers = false;
  users.users.name = {
    isNormalUser = true;
    extraGroups = [ "wheel" ];
    hashedPassword = "<password>";
  };

  system.stateVersion = "22.05";
}

However, it has a two drawbacks:

  1. Upon booting, I’m presented with a terminal, and only when I log in as the user, Sway is started.
  2. When I resize the VM window, Sway doesn’t change resolution. The image is simply stretched. (The mouse however can travel seamlessly between the VM window and the host desktop. It seems the guest add-on is successfully loaded.)

I tried to solve #1 by installing a display manager:

services.xserver = {
  enable = true;
  videoDrivers = [ "vmware" ];
  displayManager.gdm.enable = true;
  displayManager.autoLogin.enable = true;
  displayManager.autoLogin.user = "name";
};

But upon booting, I’m presented with a black screen. I presume it’s because gdm brought up sway without setting the WLR_NO_HARDWARE_CURSORS env, and I’m not sure if I should even install gdm to begin with, since I only want to use Wayland and not X.

Does anyone have any ideas on how to solve the two issues? Thanks in advance.

You can maybe solve that part by using programs.sway.extraSessionCommands or (more heavy-handed) environment.variables instead of your current approach to set the environment variable.

gdm should default to using Wayland on NixOS (services.xserver.displayManager.gdm.wayland) but note that it’s neither unusual nor “bad” to use an X-based display manager to boot up a Wayland session (e.g. lightdm). Since in your case you’re just looking to autologin with very little else in the way, you might also want to consider greetd which is a minimalistic “display manager” (really more “session manager”).

Thank you for bringing greetd to my attention. After following the wiki page, I can now logged in automatically!

As for auto-updating the resolution, I found a potential solution from redhat. However, it involves generating a new file in the open-vm-tools package.

What would be a good way to generate this file for the open-vm-tools package in my configuration?

Never mind, there is an issue for it already: https://github.com/NixOS/nixpkgs/issues/45751

1 Like

I don’t think this needs modifying any file within the open-vm-tools package? You likely just need to have the right /etc configuration file created by your NixOS config. That would be done using environment.etc.

I think open-vm-tools installs to the store folder, so the tools.conf should be added to that folder instead.

(The issue is closed since a PR addressed it. However, it doesn’t work for me. I left a comment there.)