Jump to content

Qtile: Difference between revisions

From Official NixOS Wiki
Jooooscha (talk | contribs)
m Change link of qtile.org from http to https. Also, remove the www
Gurjaka (talk | contribs)
Line 1: Line 1:
[https://qtile.org/ Qtile] is a full-featured, hackable tiling window manager written and configured in Python.
[https://qtile.org/ Qtile] is a full-featured, hackable tiling window manager written and configured in Python. It's available both as an X11 window manager and also as [https://docs.qtile.org/en/stable/manual/wayland.html#wayland a Wayland compositor].
 
== Setup ==
== Enabling ==


To enable Qtile as your window manager, set <code>services.xserver.windowManager.qtile.enable = true</code>. For example:
To enable Qtile as your window manager, set <code>services.xserver.windowManager.qtile.enable = true</code>. For example:
Line 10: Line 9:
   services.xserver.windowManager.qtile.enable = true;
   services.xserver.windowManager.qtile.enable = true;
}
}
</syntaxhighlight>To start Qtile on Wayland from your display manager (sddm, lightdm, etc) you have to add a Desktop Entry to your config like this.{{file|/etc/nixos/qtile.nix|nix|}}
</syntaxhighlight>
<syntaxHighlight lang=nix>
{{Note|The Qtile package creates desktop files for both X11 and Wayland, to use one of the backends choose the right session in your display manager.}}
{ config, pkgs, lib, ... }:
 
Other options for Qtile can be declared within the <code>services.xserver.windowManager.qtile</code> attribute set.
 
=== Config File ===
 
The configuration file can be changed from its default location <code>$XDG_CONFIG/qtile/config.py</code> by setting the <code>configFile</code> attribute:
<syntaxhighlight lang="nix">
services.xserver.windowManager.qtile = {
  enable = true;
  configFile = ./my_qtile_config.py;
};
</syntaxhighlight>
 
==== Home manager ====
 
If you are using home-manager, you can copy your qtile configuration by using the following:
<syntaxhighlight lang="nix">
xdg.configFile."qtile/config.py".source = ./my_qtile_config.py;
</syntaxhighlight>
 
or, if you have a directory containing multiple python files:
 
<syntaxhighlight lang="nix">
xdg.configFile."qtile" = {
  source = ./src;
  recursive = true;
};
</syntaxhighlight>
 
=== Extra Packages ===
 
You may add extra packages in the Qtile python environment by putting them in the <code>extraPackages</code> list. For example:
<syntaxhighlight lang="nix">
services.xserver.windowManager.qtile = {
  enable = true;
  extraPackages = python3Packages: with python3Packages; [
    qtile-extras
    qtile-bonsai
  ];
};
</syntaxhighlight>
 
{{Note|Some options may change over time, please refer to see all the options for the latest stable: [https://search.nixos.org search.nixos.org] if you have any doubt}}
 
== Wayland ==
 
=== Screen sharing & desktop portals ===
Screen sharing is supported with xdg desktop portals.
 
You need to have the following dependencies installed:
* <code>xdg-desktop-portal</code> (NEEDED)
* <code>xdg-desktop-portal-wlr</code> (NEEDED), the wlroots "portal"
* <code>xdg-desktop-portal-gtk</code> (RECOMMENDED) for proper GTK popup support
 
It's recommended to acquire them as shown:
<syntaxhighlight lang="nix">
xdg.portal = {
  enable = true;
  config.common.default = "*";
  extraPortals = with pkgs; [
    xdg-desktop-portal-wlr
    xdg-desktop-portal-gtk
  ];
};
</syntaxhighlight>
 
=== Making apps use Wayland ===
Qtile has support for running X11 applications through XWayland. Whilst XWayland works, it is often not an optimal experience. Due to this we recommend to set some environment variables such that some applications use Wayland rather than X11.
 
{{Note|Note that in some systems these wayland backends can be experimental, so use these configurations with caution.}}
 
Environment variables:
<syntaxhighlight lang="nix">
environment.sessionVariables = {
  WLR_NO_HARDWARE_CURSORS = 1;
  NIXOS_OZONE_WL = 1;
  MOZ_ENABLE_WAYLAND = 1;
  GDK_BACKEND = "wayland,x11";
  ELECTRON_OZONE_PLATFORM_HINT = "auto";
  SDL_VIDEODRIVER = "wayland,x11";
};
</syntaxhighlight>
 
== Flakes ==
Qtile provides a Nix flake in its repository. This can be useful for:
 
* Running a bleeding-edge version of Qtile by specifying the flake input as the package.
* Hacking on Qtile using a Nix develop shell.
 
{{Note|Nix flakes are still an experimental NixOS feature, but they are already widely used. This section is intended for users who are already familiar with flakes.}}


To run a bleeding-edge version of Qtile with the flake, add the Qtile repository to your flake inputs and define the package. For example:
<syntaxhighlight lang="nix">
{
{
   nixpkgs.overlays = [
   description = "A very basic flake";
   (self: super: {
   inputs = {
     qtile-unwrapped = super.qtile-unwrapped.overrideAttrs(_: rec {
     nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
      postInstall = let
        qtileSession = ''
        [Desktop Entry]
        Name=Qtile Wayland
        Comment=Qtile on Wayland
        Exec=qtile start -b wayland
        Type=Application
        '';
        in
        ''
      mkdir -p $out/share/wayland-sessions
      echo "${qtileSession}" > $out/share/wayland-sessions/qtile.desktop
      '';
      passthru.providedSessions = [ "qtile" ];
    });
  })
];


services.xserver.displayManager.sessionPackages = [ pkgs.qtile-unwrapped ];
    qtile-flake = {
      url = "github:qtile/qtile";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
 
  outputs =
    {
      self,
      nixpkgs,
      qtile-flake,
    }:
    {
      nixosConfigurations.demo = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
 
        modules = [
          (
            {
              config,
              pkgs,
              lib,
              ...
            }:
            {
              services.xserver = {
                enable = true;
                windowManager.qtile = {
                  enable = true;
                  package = qtile-flake.packages.${pkgs.system}.default;
                };
              };
 
              # make qtile X11 the default session
              services.displayManager.defaultSession = lib.mkForce "qtile";
 
              # rest of your NixOS config
            }
          )
        ];
      };
    };
}
}
</syntaxHighlight>
</syntaxhighlight>
 
This flake can also be tested with a vm:
<syntaxhighlight lang="nix">
sudo nixos-rebuild build-vm --flake .#demo
</syntaxhighlight>
 
Gives you a script to run that runs Qemu to test your config. For this to work you have to set a user with a password.
 
{{Note|1=For a detailed walkthrough on setting up Qtile with flakes—from basic installation to package overrides, see [https://gurjaka.codeberg.page/blog.html?post=qtile-flake Gurjaka's Qtile Flake Guide].}}


== Warning ==
== Credits ==
The installation of Qtile leads to several of its dependencies being leaked in the user's PATH. This prevents the user from running a custom installation of python3 as Qtile will shadow the systemPackages in the PATH with its own python3. For more information see: [https://github.com/NixOS/nixpkgs/issues/186243 Cannot use Globally Defined Python Environment While Inside Qtile] and [https://github.com/NixOS/nixpkgs/issues/171972 Kitty leaks packages into system environment (Additional context)]
* Based on the official [https://docs.qtile.org/en/latest/manual/install/nixos.html# Qtile Documentation].
* Wayland details from [https://gist.github.com/jwijenbergh/48da1a8f4c4a56d122407c4d009bc81f#screen-sharing--desktop-portals Gist by Jwijenbergh]
* NixOS implementation details maintained by the community.


[[Category:Window managers]]
[[Category:Window managers]]
[[Category:Applications]]
[[Category:Applications]]

Revision as of 19:59, 9 March 2026

Qtile is a full-featured, hackable tiling window manager written and configured in Python. It's available both as an X11 window manager and also as a Wayland compositor.

Setup

To enable Qtile as your window manager, set services.xserver.windowManager.qtile.enable = true. For example:

❄︎ /etc/nixos/configuration.nix
{
  services.xserver.windowManager.qtile.enable = true;
}
Note: The Qtile package creates desktop files for both X11 and Wayland, to use one of the backends choose the right session in your display manager.

Other options for Qtile can be declared within the services.xserver.windowManager.qtile attribute set.

Config File

The configuration file can be changed from its default location $XDG_CONFIG/qtile/config.py by setting the configFile attribute:

services.xserver.windowManager.qtile = {
  enable = true;
  configFile = ./my_qtile_config.py;
};

Home manager

If you are using home-manager, you can copy your qtile configuration by using the following:

xdg.configFile."qtile/config.py".source = ./my_qtile_config.py;

or, if you have a directory containing multiple python files:

xdg.configFile."qtile" = {
  source = ./src;
  recursive = true;
};

Extra Packages

You may add extra packages in the Qtile python environment by putting them in the extraPackages list. For example:

services.xserver.windowManager.qtile = {
  enable = true;
  extraPackages = python3Packages: with python3Packages; [
    qtile-extras
    qtile-bonsai
  ];
};
Note: Some options may change over time, please refer to see all the options for the latest stable: search.nixos.org if you have any doubt

Wayland

Screen sharing & desktop portals

Screen sharing is supported with xdg desktop portals.

You need to have the following dependencies installed:

  • xdg-desktop-portal (NEEDED)
  • xdg-desktop-portal-wlr (NEEDED), the wlroots "portal"
  • xdg-desktop-portal-gtk (RECOMMENDED) for proper GTK popup support

It's recommended to acquire them as shown:

xdg.portal = {
  enable = true;
  config.common.default = "*";
  extraPortals = with pkgs; [
    xdg-desktop-portal-wlr
    xdg-desktop-portal-gtk
  ];
};

Making apps use Wayland

Qtile has support for running X11 applications through XWayland. Whilst XWayland works, it is often not an optimal experience. Due to this we recommend to set some environment variables such that some applications use Wayland rather than X11.

Note: Note that in some systems these wayland backends can be experimental, so use these configurations with caution.

Environment variables:

environment.sessionVariables = {
  WLR_NO_HARDWARE_CURSORS = 1;
  NIXOS_OZONE_WL = 1;
  MOZ_ENABLE_WAYLAND = 1;
  GDK_BACKEND = "wayland,x11";
  ELECTRON_OZONE_PLATFORM_HINT = "auto";
  SDL_VIDEODRIVER = "wayland,x11";
};

Flakes

Qtile provides a Nix flake in its repository. This can be useful for:

  • Running a bleeding-edge version of Qtile by specifying the flake input as the package.
  • Hacking on Qtile using a Nix develop shell.
Note: Nix flakes are still an experimental NixOS feature, but they are already widely used. This section is intended for users who are already familiar with flakes.

To run a bleeding-edge version of Qtile with the flake, add the Qtile repository to your flake inputs and define the package. For example:

{
  description = "A very basic flake";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

    qtile-flake = {
      url = "github:qtile/qtile";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      qtile-flake,
    }:
    {
      nixosConfigurations.demo = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";

        modules = [
          (
            {
              config,
              pkgs,
              lib,
              ...
            }:
            {
              services.xserver = {
                enable = true;
                windowManager.qtile = {
                  enable = true;
                  package = qtile-flake.packages.${pkgs.system}.default;
                };
              };

              # make qtile X11 the default session
              services.displayManager.defaultSession = lib.mkForce "qtile";

              # rest of your NixOS config
            }
          )
        ];
      };
    };
}

This flake can also be tested with a vm:

sudo nixos-rebuild build-vm --flake .#demo

Gives you a script to run that runs Qemu to test your config. For this to work you have to set a user with a password.

Note: For a detailed walkthrough on setting up Qtile with flakes—from basic installation to package overrides, see Gurjaka's Qtile Flake Guide.

Credits