Installing Sway Window Manager on Fresh Install

I am new to Linux and I currently have KDE Plasma installed on and it has been fine, but I am wanting to learn and install Sway. However, I have no experience or understanding of I3 or window managers as a whole, or how the config file is supposed to be installed and formatted. Are there any resources or tips for where to learn for Nix specifically?

I would start with the NixOS wiki page on Sway to get oriented.

If you prefer to use home-manager for conf files, it does a pretty good job of nixifying the config. Entrypoint here, manual here. Much easier than Plasma to manage reliably with nix module settings once you get acclimated.

If not, you can ref the Sway docs and drop in your config file like any other distro.

3 Likes

If you like to learn by example, my NixOS config for sway:

{
  programs = {
    uwsm = {
      enable = true;
      waylandCompositors = {
        sway = {
          binPath = "/run/current-system/sw/bin/sway";
          prettyName = "Sway";
        };
      };
    };
  };

  security = {
    pam = {
      services.swaylock = { };
    };
  };
}

and my home-manager config:

{
  config,
  pkgs,
  lib,
  ...
}:

{
  programs = {
    bemenu.enable = true;
    swayimg = {
      enable = true;
    };
    swaylock = {
      enable = true;
      settings = {
        color = "Fc000000";
      };
    };
  };

  services = {
    swayidle = {
      enable = true;
      extraArgs = [ ];
      timeouts = [
        {
          command = "${pkgs.sway}/bin/swaynag -m 'about to lock screen' -e bottom -y background";
          timeout = 270;
        }
        {
          command = "${pkgs.sway}/bin/swaynag -m 'about to lock screen'";
          resumeCommand = "${pkgs.killall}/bin/killall swaynag";
          timeout = 270;
        }
        {
          command = "${pkgs.swaylock}/bin/swaylock -fFc000000";
          timeout = 300;
        }
        {
          command = "${pkgs.sway}/bin/swaymsg 'output * power off'";
          resumeCommand = "${pkgs.sway}/bin/swaymsg 'output * power on'";
          timeout = 330;
        }
      ];
    };
  };

  wayland = {
    systemd.target = "sway-session.target";
    windowManager = {
      sway = {
        enable = true;
        config = {
          keybindings =
            let
              modifier = config.wayland.windowManager.sway.config.modifier;
            in
            lib.mkOptionDefault {
              "${modifier}+q" = "exec ${pkgs.swaylock}/bin/swaylock -fFc000000";
              "${modifier}+Shift+e" = "exec ${pkgs.sway}/bin/swaymsg exit";
            };
          menu = "bemenu-run";
          modifier = "Mod4";
          terminal = "bemenu-run";
        };
        systemd = {
          xdgAutostart = true;
        };
        xwayland = false;
      };
    };
  };

  xdg = {
    autostart = {
      enable = true;
      readOnly = true;
    };
    enable = true;
    portal = {
      enable = true;
      config = {
        common = {
          default = [ "wlr" ];
        };
      };
      extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
    };
    userDirs = {
      enable = true;
      createDirectories = true;
    };
    mimeApps = {
      enable = true;
      defaultApplications = {
        "default-web-browser" = [ "firefox.desktop" ];
        "text/html" = [ "firefox.desktop" ];
        "application/pdf" = [ "org.pwmt.zathura.desktop" ];
        "x-scheme-handler/about" = [ "firefox.desktop" ];
        "x-scheme-handler/http" = [ "firefox.desktop" ];
        "x-scheme-handler/https" = [ "firefox.desktop" ];
        "x-scheme-handler/org-protocol" = [ "emacsclient.desktop" ];
        "x-scheme-handler/unknown" = [ "firefox.desktop" ];
      };
    };
  };
}

With the above one can start sway at the console with uwsm start sway

Btw you can run sway with no config, the default config is already quite usable (if a bit of an eyesore).

3 Likes

Thank you so much. Ive got a standard default config going. I just have to figure out how to customize everything now. I really appreciate the help.

1 Like

Thank you for this! If i ever decide to use Home Manager I will use this as my reference point.

You say you’re new to Linux so I’d just point out that the man pages are also pretty good.

So in a terminal you’d run:

  • man sway to display the program options (plus a little on how to configure it),
  • man sway.5 explains the config format.

To start with (if you haven’t already) I’d copy the “stock” config across to your home folder:

mkdir ~/.config/sway
cp /etc/sway/config ~/.config/sway/config

Then open it up in an editor with the sway.5 man page in an adjacent tile (so you can see them both side-by-side), and change stuff a bit how you’d like. After making a change save the config and then press $mod + Shift + c to reload sway to see the result.

Also because sway is “i3 compatible” the i3 user guide is also quite useful at times.

2 Likes