Sway: Difference between revisions

imported>Onny
Alternatives to autostart Sway
Phobos (talk | contribs)
mNo edit summary
 
(97 intermediate revisions by 47 users not shown)
Line 1: Line 1:
Sway is a tiling [[Wayland]] compositor and a drop-in replacement for the i3 window manager for X11. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.  
[https://swaywm.org/ Sway] is a tiling [[Wayland]] compositor and a drop-in replacement for the [[i3]] window manager for X11. It can work with an existing i3 configuration and supports most of i3's features, plus a few extras. For users migrating from i3, see the [https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide].
[https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide]


== Installation ==
== Setup ==
You can install Sway by enabling it in NixOS directly, or by using [[Home Manager]], or both.


=== NixOS ===
=== Using NixOS ===
[https://search.nixos.org/options?query=sway NixOS options for sway]
Here is a minimal configuration:


<syntaxhighlight lang="nix">
{{File|3={ config, pkgs, lib, ... }:
programs.sway = {
{
   enable = true;
   environment.systemPackages = with pkgs; [
  wrapperFeatures.gtk = true; # so that gtk works properly
     wl-clipboard # Copy/Paste functionality.
  extraPackages = with pkgs; [
     mako # Notification utility.
    swaylock
    swayidle
     wl-clipboard
     mako # notification daemon
    alacritty # Alacritty is the default terminal in the config
    dmenu # Dmenu is the default in the config but i recommend wofi since its wayland native
   ];
   ];
};


</syntaxhighlight>
  # Enables Gnome Keyring to store secrets for applications.
  services.gnome.gnome-keyring.enable = true;
 
  # Enable Sway.
  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;
  };
}|name=/etc/nixos/configuration.nix|lang=nix}}
 
By default, the Sway module in NixOS comes with a set of extra packages, including [https://codeberg.org/dnkl/foot/ Foot] terminal, [[Swayidle]], [[Swaylock]], and [https://codeberg.org/adnano/wmenu/ wmenu], which may be configured under the <code>[https://search.nixos.org/options?show=programs.sway.extraPackages programs.sway.extraPackages]</code> option. You may also want to include <code>wl-clipboard</code> for clipboard functionality, as well as a screenshot utility such as [https://github.com/emersion/slurp Slurp] or [[Flameshot]] for screenshot region selection.
 
Additionally, for a more customizable bar implementation than <code>sway-bar</code>, [[Waybar]] may be enabled with <code>programs.waybar.enable</code>.
 
The default Sway configuration is symlinked to <code>/etc/sway/config</code> and <code>/etc/sway/config.d/nixos.conf</code>. The latter file contains dbus and systemd configuration that is critical to using apps that depend on XDG desktop portals with Sway, and should be included in any custom configuration files.
 
A few general comments:
* There is some friction between GTK theming and Sway. Currently the Sway developers suggest using gsettings to set gtk theme attributes as described here [https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland]. There is currently a plan to allow GTK theme attributes to be set directly in the Sway config.
* Running Sway as a systemd user service is not recommended [https://github.com/swaywm/sway/wiki/Systemd-integration#running-sway-itself-as-a---user-service] [https://github.com/swaywm/sway/issues/5160]
 
=== Using Home Manager ===
To set up Sway using [[Home Manager]], you must first enable [[Polkit]] in your NixOS configuration.
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
security.polkit.enable = true;
</nowiki>}}
Then you may enable Sway in your Home Manager configuration. Here is a minimal example:
 
{{File|3=wayland.windowManager.sway = {
    enable = true;
    wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps
    config = rec {
      modifier = "Mod4";
      # Use kitty as default terminal
      terminal = "kitty";
      startup = [
        # Launch Firefox on start
        {command = "firefox";}
      ];
    };
  };|name=/etc/nixos/home.nix|lang=nix}}
 
See [https://nix-community.github.io/home-manager/options.xhtml#opt-wayland.windowManager.sway.enable Home Manager's Options for Sway] for a complete list of configuration options.
 
You may need to activate dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service]
 
=== Systemd services ===
Kanshi is an output configuration daemon. As explained above, we don't run Sway itself as a systemd service. There are auxiliary daemons that we do want to run as systemd services, for example Kanshi [https://gitlab.freedesktop.org/emersion/kanshi], which implements monitor hot swapping. It would be enabled as follows:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  # kanshi systemd service
  systemd.user.services.kanshi = {
    description = "kanshi daemon";
    environment = {
      WAYLAND_DISPLAY="wayland-1";
      DISPLAY = ":0";
    };
    serviceConfig = {
      Type = "simple";
      ExecStart = ''${pkgs.kanshi}/bin/kanshi -c kanshi_config_file'';
    };
  };
</nowiki>}}
 
{{file|sway config|bash|
# give Sway a little time to startup before starting kanshi.
exec sleep 5; systemctl --user start kanshi.service
}}
When you launch Sway, the systemd service is started.
 
=== Using a greeter ===
Installing a greeter based on [[greetd]] is the most straightforward way to launch Sway.
 
==== TUIGreet ====
Tuigreet is a simple and lightweight option that does not require a separate compositor to launch.
 
{{file|||<nowiki>
services.greetd = {                                                     
  enable = true;                                                       
  settings = {                                                         
    default_session = {                                                 
      command = "${pkgs.tuigreet}/bin/tuigreet --time --cmd sway";
      user = "greeter";                                                 
    };                                                                 
  };                                                                   
};                                                                     
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}}
 
==== Regreet ====
[https://github.com/rharish101/ReGreet Regreet] is a clean and customizable GTK-based greeter written in Rust. It will automatically find Sway and remembers the last picked option. Additional configuration options may be found under [https://search.nixos.org/options?&query=regreet programs.regreet].
{{File|3=programs.regreet.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}


=== Home Manager ===
=== Automatic startup on boot ===
[https://rycee.gitlab.io/home-manager/options.html#opt-wayland.windowManager.sway.enable Home Manager options for sway]
The snippet below will start Sway immediately on startup, without a greeter and '''without a login prompt'''. Only consider using this in conjunction with [[Full Disk Encryption]].


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
wayland.windowManager.sway = {
services.getty = {
   enable = true;
   autologinUser = "your_username";
   wrapperFeatures.gtk = true ;
   autologinOnce = true;
};
};
home.packages = with pkgs; [
environment.loginShellInit = ''
  swaylock
    [[ "$(tty)" == /dev/tty1 ]] && sway
  swayidle
'';
  wl-clipboard
</syntaxhighlight>When launched directly from the TTY, Sway will not inherit the user environment. This may cause issues with systemd user services such as application launchers or [[Swayidle]]. To fix this, add the following to your Home Manager configuration:{{file|home.nix|nix|<nowiki>
  mako # notification daemon
wayland.windowManager.sway.systemd.variables = ["--all"];
  alacritty # Alacritty is the default terminal in the config
</nowiki>}}
   dmenu # Dmenu is the default in the config but i recommend wofi since its wayland native
 
];
=== Secret Service ===
</syntaxhighlight>
It is recommended to enable a secret service provider such as [https://wiki.gnome.org/Projects/GnomeKeyring Gnome Keyring]. For more information on secret services check the [[Secret Service]] page.
 
Install and enable:
{{File|3=services.gnome.gnome-keyring.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}
In order to unlock the keyring through logins from greeters and screen locking utilities you will need to enable them through PAM.
{{File|3=security.pam.services = {
   greetd.enableGnomeKeyring = true;
  swaylock.enableGnomeKeyring = true;


== Info ==
  # If using a display manager such as GDM
  #gdm.enableGnomeKeyring = true;
};|name=/etc/nixos/configuration.nix|lang=nix}}


=== Clipboard ===
== Configuration ==
Sway may be configured for specific users using Home Manager or manually through configuration files. The default location is <code>/etc/sway/config</code>, and custom user configuration in <code>~/.config/sway/config</code>.


For clipboard support
=== Keyboard layout ===
<syntaxhighlight lang="nix">
Changing layout for all keyboards to German (de):<syntaxhighlight lang="console">
environment.systemPackages = with pkgs; [ wl-clipboard ];
input * xkb_layout "de"
</syntaxhighlight>The same thing accomplished in Home Manager:<syntaxhighlight lang="nix">
wayland.windowManager.sway.input."*".xkb_layout = "de";
</syntaxhighlight>
</syntaxhighlight>


to use [https://github.com/brunelli/wl-clipboard-x11/ wl-clipboard-x11] which is a wrapper to use wl-clipboard as a drop-in replacement to X11 clipboard tools
=== High-DPI scaling ===
 
Changing scale for all screens to factor 1.5:<syntaxhighlight lang="console">
<syntaxhighlight lang="nix">
output * scale 1.5
nixpkgs.overlays = [
  (self: super: {
    wl-clipboard-x11 = super.stdenv.mkDerivation rec {
    pname = "wl-clipboard-x11";
    version = "5";
 
    src = super.fetchFromGitHub {
      owner = "brunelli";
      repo = "wl-clipboard-x11";
      rev = "v${version}";
      sha256 = "1y7jv7rps0sdzmm859wn2l8q4pg2x35smcrm7mbfxn5vrga0bslb";
    };
 
    dontBuild = true;
    dontConfigure = true;
    propagatedBuildInputs = [ super.wl-clipboard ];
    makeFlags = [ "PREFIX=$(out)" ];
    };
 
    xsel = self.wl-clipboard-x11;
    xclip = self.wl-clipboard-x11;
  })
];
</syntaxhighlight>
</syntaxhighlight>
{{Note|This will recompile all packages that have xclip or xsel in their dependencies|warn}}


=== Brightness and volume ===
=== Brightness and volume ===
 
You may set the brightness and volume function keys by binding the key codes to their corresponding commands within your sway config. The following configurations accomplish this using <code>light</code> and <code>pulseaudio</code>:
Brightnessctl has worked better for me than light
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
environment.systemPackages = with pkgs; [ brightnessctl ];
users.users.yourusername.extraGroups = [ "video" ];
users.users.yourusername.extraGroups = [ "video" ];
# or
programs.light.enable = true;
programs.light.enable = true;
 
environment.systemPackages = [ pkgs.pulseaudio ];
environment.systemPackages = with pkgs; [ pactl ];
</nowiki>}}
</nowiki>}}


{{file|sway config|bash|
{{file|||


# Brightness
# Brightness
bindsym XF86MonBrightnessDown exec "brightnessctl set 2%-"
bindsym XF86MonBrightnessDown exec light -U 10
bindsym XF86MonBrightnessUp exec "brightnessctl set +2%"
bindsym XF86MonBrightnessUp exec light -A 10


# Volume
# Volume
Line 101: Line 167:
bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -1%'
bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -1%'
bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle'
bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle'
}}
|name=Sway Config|lang=bash}}Or alternatively in Home Manager:
{{File|3=wayland.windowManager.sway = {
  enable = true;
  config = {
    keybindings = {
      # Brightness Controls
      "XF86MonBrightnessDown" = "exec light -U 10";
      "XF86MonBrightnessUp" = "exec light -A 10";
       
      # Volume Controls
      "XF86AudioRaiseVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ +1%";
      "XF86AudioLowerVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ -1%";
      "XF86AudioMute" = "exec pactl set-sink-mute @DEFAULT_SINK@ toggle";
    };
  };
};|name=/etc/nixos/home.nix|lang=nix}}For an on screen display for audio and brightness, check [[swayosd]].
 
=== Input ===
 
==== Touchpad ====
See the [https://www.mankier.com/5/sway-input sway-input man page] for options.
{{File|3=wayland.windowManager.sway =
  {
    enable = true;
    config.input = {
      "type:touchpad" = {
        # Enables or disables tap for specified input device.
        tap = "enabled";
        # Enables or disables natural (inverted) scrolling for the specified input device.
        natural_scroll = "enabled";
        # Enables or disables disable-while-typing for the specified input device.
        dwt = "enabled";
      };
    };
  };|name=/etc/nixos/home.nix|lang=nix}}
 
== Troubleshooting ==
 
=== Cursor is missing icons or too tiny on HiDPI displays ===
 
==== With programs.sway ====
<syntaxhighlight lang="nix>
{
  programs.sway.extraPackages = with pkgs; [
    adwaita-icon-theme # mouse cursor and icons
    gnome-themes-extra # dark adwaita theme
    ...
  ];
}
</syntaxhighlight>
 
In ~/.config/sway/config
<syntaxhighlight>seat "*" xcursor_theme Adwaita 32</syntaxhighlight>
 
==== With Home Manager ====


=== Autostart Sway ===
Using [[Home Manager]] you may configure the mouse cursor size and theme. The reason that your cursor might be missing in some applications, is because <code>XCURSOR_THEME</code> is missing, which will cause applications relying on <code>XWAYLAND</code> to misbehave. Setting <code>sway.enable = true</code>, combined with the <code>name</code>, <code>package</code> and size will set the correct environment variables, which sway will then use.
It is possible to use greetd, a minimal login manager, to autostart Sway:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{File|3=home.pointerCursor = {
services.greetd = {
    name = "Adwaita";
  enable = true;
    package = pkgs.adwaita-icon-theme;
  settings = rec {
    size = 24;
     initial_session = {
     x11 = {
       command = "${pkgs.sway}/bin/sway";
       enable = true;
       user = "myuser";
       defaultCursor = "Adwaita";
     };
     };
    default_session = initial_session;
  };
};
</nowiki>}}


Where <code>myuser</code> needs to be replaced with the username which should execute Sway.
  sway.enable = true;
 
};|name=/etc/nixos/home.nix|lang=nix}}


Alternatively,  you could use <code>getty</code> to auto login into <code>tty1</code> with <code>myuser</code>. Using <code>loginShellInit</code> Sway will automatically get started after user login:
=== Missing fonts in Xorg applications ===


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
If fonts for certain languages are missing in Xorg applications (e.g. Japanese fonts don't appear in Discord)  even though they're in the system, you can set them as default fonts in your configuration file.
services.getty.autologinUser = "myuser";


environment.loginShellInit = ''
<syntaxhighlight lang="nix>
  if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
    exec sway
  fi
'';
</nowiki>}}


=== Polkit ===
  fonts = {
    packages = with pkgs; [
      noto-fonts
      noto-fonts-cjk
      noto-fonts-emoji
      font-awesome
      source-han-sans
      source-han-sans-japanese
      source-han-serif-japanese
    ];
    fontconfig.defaultFonts = {
      serif = [ "Noto Serif" "Source Han Serif" ];
      sansSerif = [ "Noto Sans" "Source Han Sans" ];
    };
  };


nix generated sway config
<syntaxhighlight lang="nix">
${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1
</syntaxhighlight>
</syntaxhighlight>


normal sway config
=== Swaylock cannot be unlocked with the correct password ===
<syntaxhighlight lang="nix">
 
environment.systemPackages = with pkgs; [ polkit_gnome ];
Add the following to your NixOS configuration.
environment.pathsToLink = [ "/libexec" ];
 
<syntaxhighlight lang="nix>
  security.pam.services.swaylock = {};
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="bash">
The <code>programs.sway.enable</code> option does this automatically.
# NixOS
 
exec /run/current-system/sw/libexec/polkit-gnome-authentication-agent-1
=== Inferior performance compared to other distributions ===
# Home Manager | pathsToLink is not needed
 
exec ~/.nix-profile/libexec/polkit-gnome-authentication-agent-1
Enabling realtime may improve latency and reduce stuttering, specially in high load scenarios.
 
<syntaxhighlight lang="nix">
security.pam.loginLimits = [
  { domain = "@users"; item = "rtprio"; type = "-"; value = 1; }
];
</syntaxhighlight>
</syntaxhighlight>


Enabling this option allows any program run by the "users" group to request real-time priority.


=== WLR Error when trying to launch Sway ===


=== Theming ===
When this happens on a new NixOS system, enabling OpenGL in configuration.nix may fix this issue. 


==== Gtk ====
{{Note|<code>hardware.opengl</code> was renamed to <code>hardware.graphics</code> in NixOS 24.11.}}


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
hardware.graphics.enable = true;
  gtk-engine-murrine
  gtk_engines
  gsettings-desktop-schemas
  lxappearance
];
</syntaxhighlight>
</syntaxhighlight>
open lxappearance and pick your themes


read [https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland GTK3 settings on Wayland]
=== Systemd user services missing environment variables (PATH, etc) ===
When sway is launched with out display manager systemd won't inherit the users environment variables. To fix this add the following to your home-manager configuration:
{{File|3=wayland.windowManager.sway.systemd.variables = ["--all"];|name=home.nix|lang=nix}}
 
=== Touchscreen input bound to the wrong monitor in multi-monitor setups ===


==== Qt ====
See this [https://github.com/swaywm/sway/issues/6590#issue-1021207180 GitHub issue for Sway] and the solution give in [https://github.com/swaywm/sway/issues/6590#issuecomment-938724355 this response].


Using [[Home Manager]] add the following to your Sway configuration:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.qt5ct.enable = true;
  wayland.windowManager.sway = {
    [...]
    config = {
      [...]
      input = {
        [...]
        "type:touch" = {
          # Replace touchscreen_output_identifier with the identifier of your touchscreen.
          map_to_output = touchscreen_output_identifier;
        };
      };
    };
  };
</syntaxhighlight>
</syntaxhighlight>
open qt5ct and pick your theme


=== Additional packages ===
=== GTK apps take an exceptionally long time to start ===
This occurs because GTK apps make blocking calls to freedesktop portals to be displayed. If Sway is not integrated with dbus and systemd, it will not be able to communicate via the <code>org.freedesktop.portal.Desktop</code> portal. To fix this, see the [[Sway#Using NixOS|description]] of default Sway configurations earlier. Adding the following to your sway configuration, if it is not already present, may resolve the issue:
include /etc/sway/config.d/*


===dbus-issues: no icons in tray, can't open files from Nautilus with the right program===


{{app|waybar|Highly customizable Wayland bar for Sway and Wlroots based compositors|https://github.com/Alexays/Waybar|waybar}}
If you're using Gnome-Apps like Nautilus on NixOS with Sway, you might run into issue with settings standard applications to open files from Nautilus (e.g. there being no way of linking PDF to your preferred PDF-reader). You might  also experience tray icons not showing up in your bar.
{{app|autotiling|Script for sway and i3 to automatically switch the horizontal / vertical window split orientation|https://github.com/nwg-piotr/autotiling|autotiling}}
{{app|gammastep|Reduces bluelight and saves your eyes|https://gitlab.com/chinstrap/gammastep|gammastep}}
{{app|clipman|Simple clipboard manager for Wayland|https://github.com/yory8/clipman/|clipman}}
{{app|wofi|Launcher/menu program for wlroots based wayland compositors such as sway|https://hg.sr.ht/~scoopta/wofi|wofi}}
{{app|flashfocus|Simple focus animations for tiling window managers|https://github.com/fennerm/flashfocus|flashfocus}}
{{app|wf-recorder|Screen recorder for wlroots-based compositors such as sway|https://github.com/ammen99/wf-recorder|wf-recorder}}
{{app|i3-ratiosplit|Configurable window size on creation|https://github.com/333fred/i3-ratiosplit|i3-ratiosplit}}


more packages here [https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide]
This is fixed by running <code>dbus-update-activation-environment --all</code> after starting your session. Make it permanent by adding <code>exec dbus-update-activation-environment --all</code> to your sway config file.


== Tips and tricks ==


=== Systemd integration ===
=== Toggle monitor modes script ===
Following script toggles screen / monitor modes if executed. It can also be mapped to a specific key in Sway.


In an article on the sway wiki [https://github.com/swaywm/sway/wiki/Systemd-integration], a way to integrate Sway with systemd user services is proposed. Starting sway that way has some benefits:
First add the Flake input required for the script<syntaxhighlight lang="nix">
{
  inputs = {
    [...]
    wl-togglescreens.url = "git+https://git.project-insanity.org/onny/wl-togglescreens.git?ref=main";
  };


* Services like Waybar, kanshi, redshift can depend on <code>graphical-session.target</code> and can therefore be started as their own user service, including convenient service management and logging.
  outputs = {self, nixpkgs, ...}@inputs: {
    nixosConfigurations.myhost = inputs.nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs.inputs = inputs;
      [...]
</syntaxhighlight>Map the script binary to a specific key<syntaxhighlight lang="nix">
{ config, pkgs, lib, inputs, ... }:{
  home-manager.users.onny = {
    programs = {
      [...]
      wayland.windowManager.sway = {
        enable = true;
        config = {
          [...]
          keybindings = lib.mkOptionDefault{
            [...]
            "XF86Display" = "exec ${inputs.wl-togglescreens.packages.x86_64-linux.wl-togglescreens}/bin/wl-togglescreens";
          };
        };
      };
    };
</syntaxhighlight>
 
=== Screenshots ===
Screenshots using grim, slurp, and [https://github.com/XodTech/grimshot grimshot] for selection screenshots/full screen screenshots.


<syntaxhighlight lang="nix">
Install tools
{ config, pkgs, lib, ... }: {
{{File|3=environment.systemPackages = with pkgs; [
  grim
  slurp
  sway-contrib.grimshot
];|name=/etc/nixos/configuration.nix|lang=nix}}
Example Home Manager configuration.
{{File|3=wayland.windowManager.sway = {
  enable = true;
  config = let
    modifier = config.wayland.windowManager.sway.config.modifier;
    in {
    modifier = "Mod4";
    keybindings = lib.mkOptionDefault {


  programs.sway = {
      # Super + Shift + S
    enable = true;
      # Screenshot a selection that saves to ~/Screenshots and copies to clipboard.
    extraPackages = with pkgs; [
      "${modifier}+Shift+s" = "exec selection=$(slurp) && grim -g \"$selection\" - {{!}} tee ~/Screenshots/$(date +%Y-%m-%d_%H-%M-%S).png {{!}} wl-copy";
       swaylock # lockscreen
        
       swayidle
       # Print Screen Button
      xwayland # for legacy apps
       # Screenshot the currently focused screen, save to ~/Screenshots and copy to clipboard.
       waybar # status bar
       "Print" = "exec grimshot save output - {{!}} tee ~/Screenshots/$(date +%Y-%m-%d_%H-%M-%S).png {{!}} wl-copy";
       mako # notification daemon
      kanshi # autorandr
    ];
  };


  environment = {
    etc = {
      # Put config files in /etc. Note that you also can put these in ~/.config, but then you can't manage them with NixOS anymore!
      "sway/config".source = ./dotfiles/sway/config;
      "xdg/waybar/config".source = ./dotfiles/waybar/config;
      "xdg/waybar/style.css".source = ./dotfiles/waybar/style.css;
     };
     };
   };
   };
};|name=/etc/nixos/home.nix|lang=nix}}


  systemd.user.targets.sway-session = {
=== Screen sharing ===
    description = "Sway compositor session";
{{File|3={ pkgs, ... }:
    documentation = [ "man:systemd.special(7)" ];
{
     bindsTo = [ "graphical-session.target" ];
  # xdg portal + pipewire = screensharing
     wants = [ "graphical-session-pre.target" ];
  xdg.portal = {
    after = [ "graphical-session-pre.target" ];
     enable = true;
     wlr.enable = true;
   };
   };
 
   services.pipewire = {
   services.redshift = {
     enable = true;
     enable = true;
     # Redshift with wayland support isn't present in nixos-19.09 atm. You have to cherry-pick the commit from https://github.com/NixOS/nixpkgs/pull/68285 to do that.
     alsa.enable = true;
     package = pkgs.redshift-wlr;
     pulse.enable = true;
   };
   };
}|name=/etc/nixos/configuration.nix|lang=nix}}{{Tip|Make sure that you do not have conflicting definitions for xdg.portal in Home Manager.}}
=== Auto mounting ===
==== USB storage devices (e.g. Flash Drives) ====
You can use [https://github.com/coldfix/udiskie udiskie] to automatically mount external storage medias.
You will need to install and enable [https://www.freedesktop.org/wiki/Software/udisks/ udisks2].
{{File|3=services.udisks2.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}
Then, in Home Manager you can enable udiskie.
{{File|3=services.udiskie.enable = true;|name=/etc/nixos/home.nix|lang=nix}}
Udiskie will automatically mount attached USB storage media.
See related info on [[USB storage devices]].


  programs.waybar.enable = true;
==== MTP (Android Phone Storage) ====
File managers that support [https://wiki.gnome.org/Projects/gvfs GVfs], such as [[Thunar]], can mount MTP devices using GVfs. See the page on [[MTP]] for related information.
{{File|3=services.gvfs.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}


  systemd.user.services.kanshi = {
=== SwayFX ===
    description = "Kanshi output autoconfig ";
[https://github.com/WillPower3309/swayfx SwayFX] is a fork of Sway that adds eye-candy effects, installing it is as simple as replacing your Sway package with SwayFX. Check the [[SwayFX]] page on the wiki for additional details.
    wantedBy = [ "graphical-session.target" ];
{{File|3=wayland.windowManager.sway = {
    partOf = [ "graphical-session.target" ];
  enable = true;
     serviceConfig = {
  package = pkgs.swayfx;
      # kanshi doesn't have an option to specifiy config file yet, so it looks
 
      # at .config/kanshi/config
  # Needed to build without errors.
      ExecStart = ''
  checkConfig = false;
        ${pkgs.kanshi}/bin/kanshi
      
      '';
  # SwayFX options must be configured through extraConfig.
      RestartSec = 5;
  extraConfig = ''
      Restart = "always";
    shadows enable
     };
    corner_radius 11
   };
    blur_radius 7
     blur_passes 2
   '';


}
};|name=/etc/nixos/home.nix|lang=nix}}
</syntaxhighlight>


And then simply add the following to the ''end'' of your sway configuration
=== Screen dimming with wl-gammarelay-rs ===
Add <code>wl-gammarelay-rs</code> to programs.sway.extraPackages, then add the following to sway config:
<syntaxhighlight>
<syntaxhighlight>
exec "systemctl --user import-environment; systemctl --user start sway-session.target"
# start daemon
exec wl-gammarelay-rs
 
# bind shortcut to reset brightness
bindsym $mod+Control+0 exec busctl --user set-property rs.wl-gammarelay / rs.wl.gammarelay Brightness d 1
 
# bind shortcut to dim screen for a particular output
bindsym $mod+Control+Underscore exec busctl --user set-property rs.wl-gammarelay /outputs/DP_1 rs.wl.gammarelay Brightness d 0.5
 
</syntaxhighlight>
</syntaxhighlight>


Note: swayidle will fail cryptically if it cannot find {{ic|sh}} in {{ic|PATH}}, so you must provide this if you create a service file for it. An example is below:
=== Inhibit swayidle/suspend when fullscreen ===
Add to sway config:
<syntaxhighlight>
# When you use `for_window` the command you give is not executed
# immediately. It is stored in a list and the command is executed
# every time a window opens or changes (eg. title) in a way that
# matches the criteria.


<syntaxhighlight lang="nix">
# inhibit idle for fullscreen apps
  systemd.user.services.swayidle = {
for_window [app_id="^.*"] inhibit_idle fullscreen
    description = "Idle Manager for Wayland";
    documentation = [ "man:swayidle(1)" ];
    wantedBy = [ "sway-session.target" ];
    partOf = [ "graphical-session.target" ];
    path = [ pkgs.bash ];
    serviceConfig = {
      ExecStart = '' ${pkgs.swayidle}/bin/swayidle -w -d \
        timeout 300 '${pkgs.sway}/bin/swaymsg "output * dpms off"' \
        resume '${pkgs.sway}/bin/swaymsg "output * dpms on"'
      '';
    };
  };
</syntaxhighlight>
</syntaxhighlight>
[[Category:Window managers]]
[[Category:Window managers]]
[[Category:Applications]]