Sway does not start

I’m trying to use sway on an x86 NixOS machine and configuring it using Home Manager. I am not using a display manager (just using the sway command from tty). When I try to launch, it fails with the following debug log:

00:00:00.000 [INFO] [sway/main.c:343] Sway version 1.7
00:00:00.000 [INFO] [sway/main.c:344] wlroots version 0.15.1
00:00:00.010 [INFO] [sway/main.c:120] Linux orpheus 5.15.71 #1-NixOS SMP Wed Sep 28 09:11:58 UTC 2022 x86_64 GNU/Linux
00:00:00.011 [INFO] [sway/main.c:136] Contents of /etc/lsb-release:
00:00:00.011 [INFO] [sway/main.c:120] DISTRIB_CODENAME=raccoon
00:00:00.011 [INFO] [sway/main.c:120] DISTRIB_DESCRIPTION="NixOS 22.11 (Raccoon)"
00:00:00.011 [INFO] [sway/main.c:120] DISTRIB_ID=nixos
00:00:00.011 [INFO] [sway/main.c:120] DISTRIB_RELEASE="22.11"
00:00:00.011 [INFO] [sway/main.c:120] LSB_VERSION="22.11 (Raccoon)"
00:00:00.011 [INFO] [sway/main.c:136] Contents of /etc/os-release:
00:00:00.011 [INFO] [sway/main.c:120] BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
00:00:00.011 [INFO] [sway/main.c:120] BUILD_ID="22.11.20221005.37bd398"
00:00:00.011 [INFO] [sway/main.c:120] DOCUMENTATION_URL="https://nixos.org/learn.html"
00:00:00.011 [INFO] [sway/main.c:120] HOME_URL="https://nixos.org/"
00:00:00.011 [INFO] [sway/main.c:120] ID=nixos
00:00:00.011 [INFO] [sway/main.c:120] LOGO="nix-snowflake"
00:00:00.011 [INFO] [sway/main.c:120] NAME=NixOS
00:00:00.011 [INFO] [sway/main.c:120] PRETTY_NAME="NixOS 22.11 (Raccoon)"
00:00:00.011 [INFO] [sway/main.c:120] SUPPORT_URL="https://nixos.org/community.html"
00:00:00.011 [INFO] [sway/main.c:120] VERSION="22.11 (Raccoon)"
00:00:00.011 [INFO] [sway/main.c:120] VERSION_CODENAME=raccoon
00:00:00.011 [INFO] [sway/main.c:120] VERSION_ID="22.11"
00:00:00.011 [INFO] [sway/main.c:108] LD_LIBRARY_PATH=
00:00:00.011 [INFO] [sway/main.c:108] LD_PRELOAD=
00:00:00.011 [INFO] [sway/main.c:108] PATH=/run/wrappers/bin:/home/logan/.nix-profile/bin:/etc/profiles/per-user/logan/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin
00:00:00.011 [INFO] [sway/main.c:108] SWAYSOCK=
00:00:00.012 [DEBUG] [sway/server.c:50] Preparing Wayland server initialization
00:00:00.013 [INFO] [wlr] [libseat] [libseat/backend/seatd.c:64] Could not connect to socket /run/seatd.sock: No such file or directory
00:00:00.013 [INFO] [wlr] [libseat] [libseat/libseat.c:76] Backend 'seatd' failed to open seat, skipping
00:00:00.013 [INFO] [wlr] [libseat] [libseat/libseat.c:76] Backend 'logind' failed to open seat, skipping
00:00:00.014 [INFO] [wlr] [libseat] [seatd/seat.c:39] Created VT-bound seat seat0
00:00:00.015 [INFO] [wlr] [libseat] [seatd/server.c:145] New client connected (pid: 1028, uid: 1000, gid: 100)
00:00:00.015 [INFO] [wlr] [libseat] [libseat/backend/seatd.c:633] Started embedded seatd
00:00:00.015 [ERROR] [wlr] [libseat] [common/terminal.c:162] Could not open target tty: Permission denied
00:00:00.015 [ERROR] [wlr] [libseat] [seatd/seat.c:61] Could not open tty0 to update VT: Permission denied
00:00:00.015 [INFO] [wlr] [libseat] [seatd/seat.c:170] Added client 0 to seat0
00:00:00.015 [ERROR] [wlr] [libseat] [common/terminal.c:162] Could not open target tty: Permission denied
00:00:00.015 [ERROR] [wlr] [libseat] [seatd/seat.c:72] Could not open terminal for VT 0: Permission denied
00:00:00.015 [ERROR] [wlr] [libseat] [seatd/seat.c:461] Could not open VT for client
00:00:00.015 [ERROR] [wlr] [libseat] [common/terminal.c:162] Could not open target tty: Permission denied
00:00:00.015 [ERROR] [wlr] [libseat] [seatd/seat.c:86] Could not open terminal to clean up VT 0: Permission denied
00:00:00.015 [INFO] [wlr] [libseat] [libseat/libseat.c:73] Seat opened with backend 'builtin'
00:00:00.015 [INFO] [wlr] [backend/session/session.c:110] Successfully loaded libseat session
00:00:00.016 [INFO] [wlr] [backend/backend.c:91] Waiting for a session to become active
00:00:10.026 [ERROR] [wlr] [backend/backend.c:114] Timeout waiting session to become active
00:00:10.026 [ERROR] [wlr] [backend/backend.c:352] Failed to start a DRM session
00:00:10.026 [ERROR] [sway/server.c:56] Unable to create backend
00:00:10.029 [INFO] [wlr] [libseat] [seatd/client.c:471] Client disconnected
00:00:10.029 [ERROR] [wlr] [libseat] [common/terminal.c:162] Could not open target tty: Permission denied
00:00:10.029 [ERROR] [wlr] [libseat] [seatd/seat.c:86] Could not open terminal to clean up VT 0: Permission denied
00:00:10.029 [INFO] [wlr] [libseat] [seatd/seat.c:524] Closed client 0 on seat0
00:00:10.029 [INFO] [wlr] [libseat] [seatd/seat.c:192] Removed client 0 from seat0
00:00:10.029 [INFO] [wlr] [libseat] [libseat/backend/seatd.c:645] Stopped embedded seatd

I did some reading, and it looks like the seatd warning about not finding a socket is fine. So the first error is [wlr] [libseat] [common/terminal.c:162] Could not open target tty: Permission denied. I found this thread which seems to have a similar issue, but I’m not sure how to apply the information there to a NixOS setup.

These are the sway-relevant bits of my config:

# home.nix
  ...
  # Enable Sway
  wayland.windowManager.sway = {
    enable = true;
    wrapperFeatures.gtk = true;
    config = {
      startup = [
        # https://github.com/NixOS/nixpkgs/issues/119445
        {command = "dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK";}
      ];
      terminal = "kitty";
      menu = "wofi --show run";
      # Display device configuration
      output = {
        eDP-1 = {
          # Set HIDP scale (pixel integer scaling)
          scale = "2";
        };
      };
    };
  };
  ...
# configuration.nix
  ...
  hardware.opengl = {
    enable = true;
    driSupport = true;
  };
  users.users = {
    logan = {
      isNormalUser = true;
      extraGroups = [
        "wheel"
        "video"
        "audio"
      ];
    };
  };
  xdg.portal = {
    enable = true;
    wlr.enable = true;
  };
  ...

Thank you!

Exact same problem as this thread from last week, probably: Sway: where's the actual WM? - #10 by NobbZ

1 Like

Thank you! I didn’t find that post in my initial searches. That does solve the problem!

In case anyone ends up here in the future, the tl;dr is that enabling sway in home manager alone doesnt set up everything correctly for sway to work. You also need to enable sway via NixOS by adding the following to your configuration.nix:

programs.sway.enable = true;

@LoganWalls would you be willing to share your full configuration.nix file? :pray: I’d really like to study it to see how is it different to mine (which still doesn’t work)

So, my earlier post spoke too soon. Enabling sway via NixOS does make sway launch correctly, but it won’t use your home manager configuration (I think it just uses some default settings defined by the module). After some fiddling I finally got sway working with home manager:

{
  inputs,
  lib,
  config,
  pkgs,
  ...
}: {
  imports = [
    inputs.hardware.nixosModules.common-cpu-intel
    inputs.hardware.nixosModules.common-gpu-intel
    inputs.hardware.nixosModules.common-pc-ssd
    ./hardware-configuration.nix
  ];
  hardware.opengl = {
    enable = true;
    driSupport = true;
  };
  nix = {
    # This will add each flake input as a registry
    # To make nix3 commands consistent with your flake
    registry = lib.mapAttrs (_: value: {flake = value;}) inputs;

    # This will additionally add your inputs to the system's legacy channels
    # Making legacy nix commands consistent as well, awesome!
    nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry;

    settings = {
      experimental-features = "nix-command flakes";
      auto-optimise-store = true;
    };
  };

  boot.loader = {
    systemd-boot.enable = true;
    efi = {
      canTouchEfiVariables = true;
      efiSysMountPoint = "/boot/efi";
    };
  };

  services.getty.autologinUser = "logan";
  users.users = {
    logan = {
      isNormalUser = true;
      extraGroups = [
        "wheel"
        "video"
        "audio"
      ];
    };
  };

  # Enable services to make sway happy
  security.rtkit.enable = true;
  services.dbus.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };

  # Enable XDG portal for Wayland
  xdg.portal = {
    enable = true;
    wlr.enable = true;
    extraPortals = with pkgs; [
      xdg-desktop-portal-wlr
    ];
  };
  # Start sway automatically
  environment.loginShellInit = ''
    [[ "$(tty)" == /dev/tty1 ]] && sway
  '';

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "22.05"; # Did you read the comment?
}

As you can see, you don’t actually need to use programs.sway.enable = true;

I’m not sure exactly which change made it work, but I think it was one of:

  1. Enabling dbus and rtkit
  2. Enabling pipewire
  3. Adding the xdg-desktop-portal-wlr extra portal to xdg.portal

If any of those three work for you please let us know here so I can mark the answer for future readers. :slight_smile:

2 Likes

Pipewire shouldn’t be needed to launch sway.
And you do not need to explicitely add xdg-desktop-portal-wlr to extraPortals, it is already done by wlr.enable.

1 Like

Thank you! That’s good to know. Sounds like enabling dbus and rtkit is probably the key then.

rtkit should be unnecessary as well, I don’t think wayland makes use of realtime scheduling. rtkit does howevever also enable polkit, which sway explicitly requires (and uses to get permissions for starting your graphical interface).

That is probably the missing link, would be cool to confirm and maybe document on the NixOS wiki.

I think it’s actually quite hard to get a NixOS system that doesn’t have dbus enabled, after all systemd enables it, so you probably already had that before the explicit setting. If you search for it in the options search you won’t even find an enable option :wink:

1 Like

Thanks for the info! I gave it a try only enabling polkit and it worked.

For future readers, you can fix the probelm by adding the following to configuration.nix:

security.polkit.enable = true;

I updated the wiki with a home manager installation section to document this. :slight_smile:

4 Likes

rtkit is useful for pipewire.

1 Like

And pipewire apparently does not enable it by default, unlike the pulseaudio module! https://github.com/NixOS/nixpkgs/blob/1935dd8fdab8e022a9d958419663162fd840014c/nixos/modules/services/desktops/pipewire/pipewire.nix#L251

Let me go fix that on my config, may well explain some audio issues I’ve experienced…

The wiki does drop a line on it, but it could maybe be best to enable by default? Is there any case where rtkit is not wanted?