Lots of issues with GTK since 24.05 upgrade


I just updated my system flake to switch from NixOS 23.11 to NixOS 24.05 and I now suddently have all sorts of issues with GTK apps.
I am not really sure if the problem is Nix related or Sway/Wayland related and where to search so I will have a try here.

What happens is all GTK programs are now super-slow to launch (about 25 seconds each time), and some even don’t start at all. Waybar for example is failing with the following error: “Error when calling StartServiceByName for org.freedesktop.portal.Desktop : Timeout”. When strace-ing any gtk program, it seems to be stuck in an epoll() call for 25 secs.

To upgrade my system I just changed the inputs of my flake and fixed a bunch of deprecated things here and there but I have not made any big change to the structure of the system, I don’t understand what could have been wrong and where to search.

Googling the waybar error didn’t helped neither as I don’t really understand what ‘org.freedesktop.portal.Desktop’ is or how it works.

I can’t link my config repository anymore as it now contains secrets and I did not took the time to think to another way of storing them but I can show any other part if needed.

Sorry for the inconvenience if the issue is not nix related

Make sure your portals are configured properly. In the desktop environments, this is done for you but in DIY desktops, you will need to do it yourself.

Also you"ll want to export certain envvars to the systemd / dbus user session.
I’d look at some of the troubleshooting options in XDG Desktop Portal - ArchWiki

Ok, I took a look at theses env vars, it seems they are defined in my user environment, but not in the systemd user session. After defining them manually everything works but how to add them via the nixos configuration flake ?
I added an include in my sway config file that loads a the /etc/syay/config.d/nixos.conf file wich seems to be managed by nixos as it is a link to the store. It contains a ‘dbus-update-activation-environment --systemd’ command that seems to be meant to forward the value of some environment vars from the current environment to the systemd user session. However it does not define them in the current env, so if they are not already set, nothing is forwarded. I don’t understand why it suddently stopped working, something was defining theses vars before the update but stopped doing so.

If I understand well, I need to define theses variables in the current environment before launching that ‘dbus-update-activation-environment’ command but I feel like the sway config file is not the right place to do it. Can it be done with the nix code of my config flake ? XDG_CURRENT_DESKTOP seems to be sway specific, so maybe I could define it in the sway part of my flake. WAYLAND_DISPLAY however seems to be wayland specific but not sway specific, I feel like this should not be defined by sway or a sway related config file.

After digging a bit into my config, I found that:

  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;

I feel like the ‘wrapperFeatures.gtk’ option should be the place to define the required environment variables and it is what the description of the option tells on search.nixos.org. I tried to track in the code what do this option do but I don’t really understand the code, it is linked with too much things I don’t know.

After further digging in my config, I think there is something wrong with it but I can’t find what. I took the time to try understanding what I wrote as it is mostly snippets I took from different online resources.

It seems some things are not working as intended, or that I do not understand them correctly:

 dbus-sway-environment = pkgs.writeTextFile {
    name = "dbus-sway-environment";
    destination = "/bin/dbus-sway-environment";
    executable = true;

    text = ''
      dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
      systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
      systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr

As I understand this snippet, it is meaned to create a “dbus-sway-environment” script in the /bin folder. It seems to be where the XDG_CURRENT_DESKTOP and WAYLAND_DISPLAY environment variables are defined. However, there is nothing in my /bin folder after rebuild and the variables are still not defined. What am I not getting ?

Here are the full module code for reference:

{ config, lib, pkgs, ... }:
  # bash script to let dbus know about important env variables and
  # propagate them to relevent services run at the end of sway config
  # see
  # https://github.com/emersion/xdg-desktop-portal-wlr/wiki/"It-doesn't-work"-Troubleshooting-Checklist
  # note: this is pretty much the same as  /etc/sway/config.d/nixos.conf but also restarts  
  # some user services to make sure they have the correct environment variables
  dbus-sway-environment = pkgs.writeTextFile {
    name = "dbus-sway-environment";
    destination = "/bin/dbus-sway-environment";
    executable = true;

    text = ''
      dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
      systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
      systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr

  # currently, there is some friction between sway and gtk:
  # https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland
  # the suggested way to set gtk settings is with gsettings
  # for gsettings to work, we need to tell it where the schemas are
  # using the XDG_DATA_DIR environment variable
  # run at the end of sway config
  configure-gtk = pkgs.writeTextFile {
    name = "configure-gtk";
    destination = "/bin/configure-gtk";
    executable = true;
    text = let
      schema = pkgs.gsettings-desktop-schemas;
      datadir = "${schema}/share/gsettings-schemas/${schema.name}";
    in ''
      export XDG_DATA_DIRS=${datadir}:$XDG_DATA_DIRS
      gsettings set $gnome_schema gtk-theme 'Numix-Black-Pomegranate'

  swayConfig = pkgs.writeText "greetd-sway-config" ''
    exec "${pkgs.greetd.gtkgreet}/bin/gtkgreet -l -s ${greetStyle} >> /tmp/gtkgreet.log 2>&1; swaymsg exit"
      bindsym Mod4+shift+e exec swaynag \
        -t warning \
        -m 'What do you want to do?' \
        -b 'Poweroff' 'systemctl poweroff' \
        -b 'Reboot' 'systemctl reboot'

    include /etc/greetd/hostSpecificConfig

  greetStyle = pkgs.writeText "greet-style.css" ''
    window {
      background-image: url("file:///etc/greetd/background.png");
      background-size: cover;
      background-position: center;
  environment.systemPackages = with pkgs; [
    # Sway related
    dbus   # make dbus-update-activation-environment available in the path
    xdg-utils # for opening default programs when clicking links
    glib # gsettings
#    dracula-theme # gtk theme
#    gnome3.adwaita-icon-theme  # default gnome cursors
#    grim # screenshot functionality
#    slurp # screenshot functionality
#    wl-clipboard # wl-copy and wl-paste for copy/paste from stdin / stdout
    bemenu # wayland clone of dmenu
    mako # notification system developed by swaywm maintainer
    wdisplays # tool to configure displays

    # Web Browsers

    # Terminal utilities


  services.pipewire = {
    enable = true;
    alsa.enable = true;
    pulse.enable = true;

  # xdg-desktop-portal works by exposing a series of D-Bus interfaces
  # known as portals under a well-known name
  # (org.freedesktop.portal.Desktop) and object path
  # (/org/freedesktop/portal/desktop).
  # The portal interfaces include APIs for file access, opening URIs,
  # printing and others.
  services.dbus.enable = true;
  xdg.portal = {
    enable = true;
    wlr.enable = true;
    # gtk portal needed to make gtk apps happy
    extraPortals = [ pkgs.xdg-desktop-portal-gtk ];

  # enable sway window manager
  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;

  fonts.packages = [

  # Disabled as not used and not working due to no config file
  # systemd.user.services.kanshi = {
  #   description = "kanshi daemon";
  #   serviceConfig = {
  #     Type = "simple";
  #     ExecStart = ''${pkgs.kanshi}/bin/kanshi -c kanshi_config_file'';
  #   };
  # };

  security.polkit.enable = true;

  # Greeter
  services.greetd = {
    enable = true;
    settings.default_session = {
      command = "${pkgs.sway}/bin/sway --config ${swayConfig}";

  console.useXkbConfig = true;

  environment.etc."greetd/environments".text = ''

  environment.etc."greetd/background.png".source = ./background.png;

  environment.sessionVariables.NIXOS_OZONE_WL = "1";