From b427889b06dd7b4733aee1ea8f3e39738e012abf Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Wed, 23 Sep 2026 18:43:38 -0400 Subject: [PATCH] add: desktop xdg integration --- home/default.nix | 14 --------- home/sway.nix | 2 +- modules/apps/xdg.nix | 0 modules/desktop/default.nix | 7 +++++ modules/desktop/xdg.nix | 42 +++++++++++++++++++++++++ modules/machine/cloud/configuration.nix | 27 +++------------- 6 files changed, 55 insertions(+), 37 deletions(-) delete mode 100644 modules/apps/xdg.nix create mode 100644 modules/desktop/xdg.nix diff --git a/home/default.nix b/home/default.nix index 5c56ad1..368896d 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,7 +1,6 @@ { lib , pkgs , userName -, isNixOS ? true , ... }: let # Have a file sturcture that holds all the configuration files that can't be configured by Nix @@ -31,19 +30,6 @@ in stateVersion = "24.11"; } - (lib.mkIf isNixOS { - sessionVariables = { - XDG_CURRENT_DESKTOP = "sway"; - XDG_SESSION_TYPE = "wayland"; - XDG_SESSION_DESKTOP = "sway"; - XDG_CONFIG_HOME = "$HOME/.config"; - XDG_CACHE_HOME = "$HOME/.cache"; - XDG_DATA_HOME = "$HOME/.local/share"; - XDG_STATE_HOME = "$HOME/.local/state"; - NIXOS_OZONE_WL = "1"; - }; - }) - (lib.mkIf pkgs.stdenv.isLinux { pointerCursor = { gtk.enable = true; diff --git a/home/sway.nix b/home/sway.nix index 41a14ae..215ddaa 100644 --- a/home/sway.nix +++ b/home/sway.nix @@ -153,6 +153,6 @@ in { programs.waybar = { enable = pkgs.stdenv.isLinux; - systemd.enable = true; + systemd.enable = false; }; } diff --git a/modules/apps/xdg.nix b/modules/apps/xdg.nix deleted file mode 100644 index e69de29..0000000 diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index fc3201d..07ec5e2 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -42,6 +42,8 @@ then "lightdm" else "none"; in { + imports = [./xdg.nix]; + options.desktop = { displayManager = lib.mkOption { type = lib.types.enum ["auto" "none" "gdm" "lightdm" "ly"]; @@ -141,6 +143,11 @@ in { enable = true; wrapperFeatures.gtk = true; extraPackages = cfg.sway.extraPackages; + extraSessionCommands = '' + export XDG_SESSION_TYPE=wayland + export XDG_SESSION_DESKTOP=sway + export NIXOS_OZONE_WL=1 + ''; }; }) diff --git a/modules/desktop/xdg.nix b/modules/desktop/xdg.nix new file mode 100644 index 0000000..d644902 --- /dev/null +++ b/modules/desktop/xdg.nix @@ -0,0 +1,42 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.desktop; + needsGtkPortal = cfg.xfce.enable || cfg.hyprland.enable; + usesPortal = cfg.gnome.enable || cfg.xfce.enable || cfg.sway.enable || cfg.hyprland.enable; +in { + config = lib.mkMerge [ + # GNOME and Sway configure their own portals in NixOS. XFCE needs a + # portal; Hyprland benefits from GTK as a fallback to its native one. + (lib.mkIf needsGtkPortal { + xdg.portal = { + enable = true; + extraPortals = [pkgs.xdg-desktop-portal-gtk]; + }; + }) + + (lib.mkIf (cfg.sway.enable || needsGtkPortal) { + xdg.portal.config.common.default = ["gtk"]; + }) + + (lib.mkIf (usesPortal && config.services.gnome.gnome-keyring.enable) { + xdg.portal.config.common."org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; + }) + + (lib.mkIf (cfg.sway.enable && config.services.gnome.gnome-keyring.enable) { + xdg.portal.config.sway."org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; + }) + + # A per-desktop config takes precedence over Hyprland's packaged config, + # so include its native portal whenever adding a Secret preference. + (lib.mkIf (cfg.hyprland.enable && config.services.gnome.gnome-keyring.enable) { + xdg.portal.config.hyprland = { + default = ["hyprland" "gtk"]; + "org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; + }; + }) + ]; +} diff --git a/modules/machine/cloud/configuration.nix b/modules/machine/cloud/configuration.nix index d5fe10e..f16afb4 100644 --- a/modules/machine/cloud/configuration.nix +++ b/modules/machine/cloud/configuration.nix @@ -22,6 +22,7 @@ in { }) ../../apps/gaming.nix ../../apps/appimage.nix + ../../desktop ../../graphics ../../pwrMgmt ../../networking/core.nix @@ -74,7 +75,6 @@ in { brightnessctl wttrbar cliphist - xdg-desktop-portal-gtk xdg-utils flatpak-xdg-utils desktop-file-utils @@ -89,6 +89,10 @@ in { # Enable Polkit security.polkit.enable = true; + # Enable desktop support (sway) + desktop.sway.enable = true; + desktop.displayManager = "ly"; + # Graphics module (../../graphics/default.nix) graphics = { enable = true; @@ -189,27 +193,6 @@ in { # AppImage support appimage.enable = true; - # XDG stuff - xdg = { - portal = { - enable = true; - config = { - sway = { - default = ["wlr" "gtk"]; - "org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; - }; - common = { - default = ["gtk"]; - "org.freedesktop.impl.portal.Secret" = ["gnome-keyring"]; - }; - }; - extraPortals = with pkgs; [ - xdg-desktop-portal-wlr - xdg-desktop-portal-gtk - ]; - }; - }; - # sched_ext userspace CPU scheduling stuff - idk services.scx = { enable = true;