From cf39ba5e07cf38a4171265c66a3fdfbca1c90c7a Mon Sep 17 00:00:00 2001 From: Bobby Rong Date: Sun, 15 Jun 2025 13:17:46 +0800 Subject: [PATCH 1/2] nixos/{budgie,cinnamon,mate}: Hack around SSH_AUTH_SOCK Make sure SSH_AUTH_SOCK is known by these sessions, which are not systemd managed. It should not be a problem for users who know this environment variable and use multiple desktops environments to opt-out of this and I would prefer a more out-of-the-box experience for those who don't. --- .../services/x11/desktop-managers/budgie.nix | 28 ++++++++++++------- .../x11/desktop-managers/cinnamon.nix | 28 ++++++++++++------- .../services/x11/desktop-managers/mate.nix | 8 ++++++ 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/nixos/modules/services/x11/desktop-managers/budgie.nix b/nixos/modules/services/x11/desktop-managers/budgie.nix index cdd2e9453133..9d7161a7560c 100644 --- a/nixos/modules/services/x11/desktop-managers/budgie.nix +++ b/nixos/modules/services/x11/desktop-managers/budgie.nix @@ -130,17 +130,25 @@ in services.xserver.desktopManager.budgie.sessionPath = [ pkgs.budgie-desktop-view ]; - environment.extraInit = '' - ${concatMapStrings (p: '' - if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then - export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name} + environment.extraInit = + '' + ${concatMapStrings (p: '' + if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then + export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name} + fi + if [ -d "${p}/lib/girepository-1.0" ]; then + export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0 + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib + fi + '') cfg.sessionPath} + '' + + lib.optionalString config.services.gnome.gcr-ssh-agent.enable '' + # Hack: https://bugzilla.redhat.com/show_bug.cgi?id=2250704 still + # applies to sessions not managed by systemd. + if [ -z "$SSH_AUTH_SOCK" ] && [ -n "$XDG_RUNTIME_DIR" ]; then + export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/gcr/ssh" fi - if [ -d "${p}/lib/girepository-1.0" ]; then - export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0 - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib - fi - '') cfg.sessionPath} - ''; + ''; environment.systemPackages = with pkgs; diff --git a/nixos/modules/services/x11/desktop-managers/cinnamon.nix b/nixos/modules/services/x11/desktop-managers/cinnamon.nix index 60880d826962..44068bfb62d6 100644 --- a/nixos/modules/services/x11/desktop-managers/cinnamon.nix +++ b/nixos/modules/services/x11/desktop-managers/cinnamon.nix @@ -87,18 +87,26 @@ in }; # Have to take care of GDM + Cinnamon on Wayland users - environment.extraInit = '' - ${concatMapStrings (p: '' - if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then - export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name} - fi + environment.extraInit = + '' + ${concatMapStrings (p: '' + if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then + export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name} + fi - if [ -d "${p}/lib/girepository-1.0" ]; then - export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0 - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib + if [ -d "${p}/lib/girepository-1.0" ]; then + export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0 + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib + fi + '') cfg.sessionPath} + '' + + lib.optionalString config.services.gnome.gcr-ssh-agent.enable '' + # Hack: https://bugzilla.redhat.com/show_bug.cgi?id=2250704 still + # applies to sessions not managed by systemd. + if [ -z "$SSH_AUTH_SOCK" ] && [ -n "$XDG_RUNTIME_DIR" ]; then + export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/gcr/ssh" fi - '') cfg.sessionPath} - ''; + ''; # Default services services.blueman.enable = mkDefault (notExcluded pkgs.blueman); diff --git a/nixos/modules/services/x11/desktop-managers/mate.nix b/nixos/modules/services/x11/desktop-managers/mate.nix index dd8f10061910..74cbca78e6b2 100644 --- a/nixos/modules/services/x11/desktop-managers/mate.nix +++ b/nixos/modules/services/x11/desktop-managers/mate.nix @@ -59,6 +59,14 @@ in pkgs.mate.mate-session-manager ]; + environment.extraInit = lib.optionalString config.services.gnome.gcr-ssh-agent.enable '' + # Hack: https://bugzilla.redhat.com/show_bug.cgi?id=2250704 still + # applies to sessions not managed by systemd. + if [ -z "$SSH_AUTH_SOCK" ] && [ -n "$XDG_RUNTIME_DIR" ]; then + export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/gcr/ssh" + fi + ''; + # Debugging environment.sessionVariables.MATE_SESSION_DEBUG = mkIf cfg.debug "1"; From 4131df3bf4c88a3ad1e21a00c24cb200ef04d981 Mon Sep 17 00:00:00 2001 From: Bobby Rong Date: Sun, 15 Jun 2025 13:53:54 +0800 Subject: [PATCH 2/2] nixos/tests/{budgie,cinnamon,mate,pantheon}: Add tests for SSH_AUTH_SOCK As a follow-up to the previous commit. Note that Pantheon is systemd managed so no hacks are needed. --- nixos/tests/budgie.nix | 2 ++ nixos/tests/cinnamon-wayland.nix | 7 +++++++ nixos/tests/cinnamon.nix | 7 +++++++ nixos/tests/mate-wayland.nix | 2 ++ nixos/tests/mate.nix | 2 ++ nixos/tests/pantheon-wayland.nix | 2 ++ nixos/tests/pantheon.nix | 2 ++ 7 files changed, 24 insertions(+) diff --git a/nixos/tests/budgie.nix b/nixos/tests/budgie.nix index 04e5300ec4fb..a6c40f6a9ab4 100644 --- a/nixos/tests/budgie.nix +++ b/nixos/tests/budgie.nix @@ -68,6 +68,8 @@ cmd = "xargs --null --max-args=1 echo < /proc/$(pgrep -xf /run/current-system/sw/bin/budgie-wm)/environ" machine.succeed(f"{cmd} | grep 'XDG_CURRENT_DESKTOP' | grep 'Budgie:GNOME'") machine.succeed(f"{cmd} | grep 'BUDGIE_PLUGIN_DATADIR' | grep '${pkgs.budgie-desktop-with-plugins.pname}'") + # From the nixos/budgie module + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") with subtest("Open run dialog"): machine.send_key("alt-f2") diff --git a/nixos/tests/cinnamon-wayland.nix b/nixos/tests/cinnamon-wayland.nix index a80199956cc2..d19ac920b388 100644 --- a/nixos/tests/cinnamon-wayland.nix +++ b/nixos/tests/cinnamon-wayland.nix @@ -58,6 +58,13 @@ with subtest("Check if sessionPath option actually works"): machine.succeed("${eval "imports.gi.GIRepository.Repository.get_search_path\\(\\)"} | grep gpaste") + with subtest("Check if various environment variables are set"): + cmd = "xargs --null --max-args=1 echo < /proc/$(pgrep -xf /run/current-system/sw/bin/nemo-desktop)/environ" + machine.succeed(f"{cmd} | grep 'XDG_SESSION_TYPE' | grep 'wayland'") + machine.succeed(f"{cmd} | grep '__NIXOS_SET_ENVIRONMENT_DONE' | grep '1'") + # From the nixos/cinnamon module + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") + with subtest("Open Cinnamon Settings"): machine.succeed("${su "cinnamon-settings themes >&2 &"}") machine.wait_until_succeeds("${eval "global.display.focus_window.wm_class"} | grep -i 'cinnamon-settings'") diff --git a/nixos/tests/cinnamon.nix b/nixos/tests/cinnamon.nix index 3230d7b07358..9ff43a8dbbb7 100644 --- a/nixos/tests/cinnamon.nix +++ b/nixos/tests/cinnamon.nix @@ -69,6 +69,13 @@ with subtest("Check if sessionPath option actually works"): machine.succeed("${eval "imports.gi.GIRepository.Repository.get_search_path\\(\\)"} | grep gpaste") + with subtest("Check if various environment variables are set"): + cmd = "xargs --null --max-args=1 echo < /proc/$(pgrep -xf /run/current-system/sw/bin/nemo-desktop)/environ" + machine.succeed(f"{cmd} | grep 'XDG_SESSION_TYPE' | grep 'x11'") + machine.succeed(f"{cmd} | grep '__NIXOS_SET_ENVIRONMENT_DONE' | grep '1'") + # From the nixos/cinnamon module + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") + with subtest("Open Cinnamon Settings"): machine.succeed("${su "cinnamon-settings themes >&2 &"}") machine.wait_until_succeeds("${eval "global.display.focus_window.wm_class"} | grep -i 'cinnamon-settings'") diff --git a/nixos/tests/mate-wayland.nix b/nixos/tests/mate-wayland.nix index 42b88439357a..c2e0ee1feaf7 100644 --- a/nixos/tests/mate-wayland.nix +++ b/nixos/tests/mate-wayland.nix @@ -52,6 +52,8 @@ machine.succeed(f"{cmd} | grep 'XDG_SESSION_TYPE' | grep 'wayland'") machine.succeed(f"{cmd} | grep 'XDG_SESSION_DESKTOP' | grep 'MATE'") machine.succeed(f"{cmd} | grep 'MATE_PANEL_APPLETS_DIR' | grep '${pkgs.mate.mate-panel-with-applets.pname}'") + # From the nixos/mate module + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") with subtest("Check if Wayfire config is properly configured"): for i in ["button_style = mate", "firedecor", "mate-wayland-components.sh"]: diff --git a/nixos/tests/mate.nix b/nixos/tests/mate.nix index 6112044837db..45fd877c1ca4 100644 --- a/nixos/tests/mate.nix +++ b/nixos/tests/mate.nix @@ -58,6 +58,8 @@ machine.succeed("xargs --null --max-args=1 echo < /proc/$(pgrep -xf marco)/environ | grep 'XDG_CURRENT_DESKTOP' | grep 'MATE'") # From mate-panel-with-applets packaging machine.succeed("xargs --null --max-args=1 echo < /proc/$(pgrep -xf mate-panel)/environ | grep 'MATE_PANEL_APPLETS_DIR' | grep '${pkgs.mate.mate-panel-with-applets.pname}'") + # From the nixos/mate module + machine.succeed("xargs --null --max-args=1 echo < /proc/$(pgrep -xf mate-panel)/environ | grep 'SSH_AUTH_SOCK' | grep 'gcr'") with subtest("Check if applets are built with in-process support"): # This is needed for Wayland support diff --git a/nixos/tests/pantheon-wayland.nix b/nixos/tests/pantheon-wayland.nix index 6bda9e508ef2..87c8b17a692c 100644 --- a/nixos/tests/pantheon-wayland.nix +++ b/nixos/tests/pantheon-wayland.nix @@ -78,6 +78,8 @@ machine.succeed(f"{cmd} | grep 'XDG_DATA_DIRS' | grep 'gsettings-schemas/pantheon-agent-geoclue2'") # Hopefully from login shell. machine.succeed(f"{cmd} | grep '__NIXOS_SET_ENVIRONMENT_DONE' | grep '1'") + # Hopefully from gcr-ssh-agent. + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") with subtest("Wait for elementary videos autostart"): machine.wait_until_succeeds("pgrep -f io.elementary.videos") diff --git a/nixos/tests/pantheon.nix b/nixos/tests/pantheon.nix index b8cb0512c542..855d0f48f80c 100644 --- a/nixos/tests/pantheon.nix +++ b/nixos/tests/pantheon.nix @@ -73,6 +73,8 @@ machine.succeed(f"{cmd} | grep 'XDG_DATA_DIRS' | grep 'gsettings-schemas/pantheon-agent-geoclue2'") # Hopefully from login shell. machine.succeed(f"{cmd} | grep '__NIXOS_SET_ENVIRONMENT_DONE' | grep '1'") + # Hopefully from gcr-ssh-agent. + machine.succeed(f"{cmd} | grep 'SSH_AUTH_SOCK' | grep 'gcr'") with subtest("Open elementary videos"): machine.execute("su - ${user.name} -c 'DISPLAY=:0 io.elementary.videos >&2 &'")