Skip to content

nixos/x11/display-managers: don't touch graphical-session.target in xsession-wrapper#233981

Merged
K900 merged 1 commit intoNixOS:masterfrom
K900:dont-touch-graphical-session-target
Jul 8, 2023
Merged

nixos/x11/display-managers: don't touch graphical-session.target in xsession-wrapper#233981
K900 merged 1 commit intoNixOS:masterfrom
K900:dont-touch-graphical-session-target

Conversation

@K900
Copy link
Contributor

@K900 K900 commented May 25, 2023

This is not correct and will in fact break things because they try to run before the target is reached.

WMs users may need some sort of a manual workaround for this...

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels May 25, 2023
@apfelkuchen6
Copy link
Contributor

Looks like this should fix #225605.

@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels May 25, 2023
@K900
Copy link
Contributor Author

K900 commented May 25, 2023

Yes, it should.

@K900
Copy link
Contributor Author

K900 commented Jul 7, 2023

Pinging everyone who touched all the other DE/WM modules recently for testing:

@FedericoSchonborn for Budgie
@bobby285271 for Cinnamon
@wineee for Deepin
@romildo for a bunch of stuff
@jtojnar for GNOME
@edwtjo for Kodi
@worldofpeace for MATE
@tomfitzhenry for Phosh
@j0hax for RetroArch
@etu for Surf
@sternenseemann for 2bwm and xmonad
@AndersonTorres for a bunch of stuff
@necauqua and @teto for Awesome
@3JlOy-PYCCKUi for dk
@bobvanderlinden for dwm
@reedrw and @Ma27 for i3
@marcusramberg for nimdow
@arjan-s for qtile
@Uthar for StumpWM

If anyone else knows anyone who's actively using the more obscure sessions, please ping them so they can test too.

@wineee
Copy link
Member

wineee commented Jul 7, 2023

image
DDE (deepin) works fine

test by:
    # nix run -v -L
    {
      inputs.nixpkgs.url = "github:K900/nixpkgs/dont-touch-graphical-session-target";
      #inputs.nixpkgs.url = "path:/home/rewine/nur/nixpkgs";
    
      outputs = inputs@{ self, nixpkgs }: let 
        system = "x86_64-linux";
        pkgs = import nixpkgs { inherit system; };
      in {
        nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            {
            imports = [ "${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix" ];
            services.xserver = {
              enable = true;
              displayManager = {
                lightdm.enable = true;
                autoLogin = {
                  enable = false;
                  user = "test";
                };
              };
              desktopManager.deepin.enable = true;
            };
            
            users.users.test = {
              isNormalUser = true;
              uid = 1000;
              extraGroups = [ "wheel" "networkmanager" ];
              password = "test";
              createHome = true;
            };
            virtualisation = {
              qemu.options = [ "-device intel-hda -device hda-duplex" ];
              cores = 8;
              memorySize = 8192;
              diskSize = 16384;
              resolution = { x = 1024; y = 768; };
            };
            system.stateVersion = "23.05";
          }];
        };
        packages.${system}.default = self.nixosConfigurations.vm.config.system.build.vm;
        apps.${system}.default = {
          type = "app";
          program = "${self.packages.${system}.default}/bin/run-nixos-vm";
        };
      };
    }

@wineee
Copy link
Member

wineee commented Jul 7, 2023

@OPNA2608 You can test whether this modification affects lomiri

@bobvanderlinden
Copy link
Member

I'm not maintaining/using dwm. @viric and @neonfuz are 👍

@K900
Copy link
Contributor Author

K900 commented Jul 7, 2023

FWIW I can personally vouch for this working fine on Plasma, but Plasma is the odd one out here, as it actually uses systemd correctly.

@OPNA2608
Copy link
Contributor

OPNA2608 commented Jul 7, 2023

You can test whether this modification affects lomiri

Lomiri seems to still work fine after this.

@3JlOy-PYCCKUi
Copy link
Contributor

3JlOy-PYCCKUi commented Jul 7, 2023

well, i tested bspwm and dk (via sddm), both started fine, but auto start via systemd user services is broken, cuz graphical-session.target is not started/reached

i don't get purpose of this pr, from my point of view it just breaks things

(i just applied this pr as patch to f292b49 commit)

@K900
Copy link
Contributor Author

K900 commented Jul 7, 2023

The purpose of this PR is to stop breaking things that actually rely on a graphical session being fully started. Right now every autostart application is basically racing the session setup to determine whether it gets the right environment set up.

@AndersonTorres
Copy link
Member

We will figure the correct workaround in the future.

Copy link
Member

@AndersonTorres AndersonTorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reword the commit as:


Modifying the state of graphical-session.target breaks things that try to run before the target is fully reached. This is wrong behavior and should not happen.

This change affect users of window managers, that will need some sort of a manual workaround.


@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

I'd rather just not merge this until a workaround is in place.

@tomfitzhenry
Copy link
Contributor

Pinging everyone who touched all the other DE/WM modules recently for testing:
@tomfitzhenry for Phosh

Seeing nixosTests.phosh pass would be sufficient for this change.

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

The tests do pass, but this may have unexpected side effects that are not caught by the test.

@K900 K900 force-pushed the dont-touch-graphical-session-target branch 2 times, most recently from 99cdb3e to 0bc03c7 Compare July 8, 2023 11:21
@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

Updated with a hack to retain the old behavior for non-compliant WMs. Thanks to @hrnz on Matrix for coming up with the XDG_CURRENT_DESKTOP idea.

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

Tested locally with Plasma and i3 and things work mostly as expected.

…session-wrapper if the desktop knows how to handle it

This is not correct and will in fact break things because they try to run before the target is reached.
Ideally we'd get rid of it entirely, but WM users rely on this behavior, so allowlist some desktops
to get the sane behavior, and fake the session for the rest until upstreams/NixOS modules catch up.
@K900 K900 force-pushed the dont-touch-graphical-session-target branch from 0bc03c7 to d26393d Compare July 8, 2023 12:09
@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

Also added a magic value X-NIXOS-SYSTEMD-AWARE to allow custom sessions to opt into this behavior.

@K900 K900 requested a review from AndersonTorres July 8, 2023 12:20
@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

@3JlOy-PYCCKUi can you retest if the current workaround works for your setup?

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

So I just went through and checked the session configs for the most common WMs, and I'm pretty sure we're fine here.

@K900 K900 merged commit 9c98b1a into NixOS:master Jul 8, 2023
@jtojnar
Copy link
Member

jtojnar commented Jul 8, 2023

Looks like for GNOME-based DEs, gnome-session.target has BindsTo=graphical-session.target.

Tested GNOME Shell and the graphical-session.target is properly started there:

$ systemctl status --user graphical-session.target
● graphical-session.target - Current graphical user session
     Loaded: loaded (/etc/systemd/user/graphical-session.target; static)
     Active: active since Sat 2023-07-08 14:25:58 UTC; 25s ago
       Docs: man:systemd.special(7)

Jul 08 14:25:58 nixos systemd[1340]: Reached target Current graphical user session.

However, in GNOME Flashback (XDG_CURRENT_DESKTOP=GNOME-Flashback:GNOME), it does not appear to be the case:

$ systemctl status --user graphical-session.target
○ graphical-session.target - Current graphical user session
     Loaded: loaded (/etc/systemd/user/graphical-session.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

cc @chpatrick

VM configuration
{ pkgs, lib, config, ... }:
{
  environment.systemPackages = with pkgs; [
    gdb
  ];

  environment.enableDebugInfo = true;

  services.xserver = {
    enable = true;

    displayManager.defaultSession = "gnome-flashback-metacity";
    displayManager.gdm = {
      enable = true;
    };
    desktopManager.gnome = {
      flashback.enableMetacity = true;
    };
  };

  services.openssh.enable = true;

  systemd.coredump.extraConfig = ''
    Storage=external
  '';

  users.extraUsers.jtojnar = {
    isNormalUser = true;
    uid = 1000;
    extraGroups = [ "wheel" "networkmanager" ];
    password = "";
    openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYbOlZydfRRCGCT08wdtPcpfSrgxMc6weDx3NcWrnMpVgxnMs3HozzkaS/hbcZUocn7XbCOyaxEd1O8Fuaw4JXpUBcMetpPXkQC+bZHQ3YsZZyzVgCXFPRF88QQj0nR7YVE1AeAifjk3TCODstTxit868V1639/TVIi5y5fC0/VbYG2Lt4AadNH67bRv8YiO3iTsHQoZPKD1nxA7yANHCuw38bGTHRhsxeVD+72ThbsYSZeA9dBrzACpEdnwyXclaoyIOnKdN224tu4+4ytgH/vH/uoUfL8SmzzIDvwZ4Ba2yHhZHs5iwsVjTvLe7jjE6I1u8qY7X8ofnanfNcsmz/ jtojnar@kaiser" ];
  };

  imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];
  virtualisation.memorySize = 3 * 2048;
  virtualisation.diskSize = 28048;
  virtualisation.qemu.options = [ "-device intel-hda" "-device hda-duplex" ];
  virtualisation.forwardPorts = [
    # forward local port 2222 -> 22, to ssh into the VM
    { from = "host"; host.port = 2222; guest.port = 22; }
  ];

  systemd.user.services.test-g-s-t = {
    description = "test-g-s-t";
    wantedBy = [ "graphical-session.target" ];
    partOf = [ "graphical-session.target" ];
    serviceConfig.ExecStart = "${pkgs.bash}/bin/sh -c 'while true; do echo running in graphical-session; sleep 5; done'";
  };
}

I would also expect it to work in Pantheon if I add it to the list but it does not appear to.

--- a/nixos/modules/services/x11/display-managers/default.nix
+++ b/nixos/modules/services/x11/display-managers/default.nix
@@ -40,7 +40,7 @@ let
         IFS=:
         for i in $XDG_CURRENT_DESKTOP; do
           case $i in
-            KDE|GNOME|X-NIXOS-SYSTEMD-AWARE) echo "1"; exit; ;;
+            KDE|GNOME|Pantheon|X-NIXOS-SYSTEMD-AWARE) echo "1"; exit; ;;
             *) ;;
           esac
         done

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

I thought Pantheon used gnome-session?

@jtojnar
Copy link
Member

jtojnar commented Jul 8, 2023

Oh, we do not actually use systemd code path for Budgie, Pantheon and GNOME Flashback yet, only for GNOME Shell: #228946

Comment on lines +38 to +52
fakeSession = action: ''
session_is_systemd_aware=$(
IFS=:
for i in $XDG_CURRENT_DESKTOP; do
case $i in
KDE|GNOME|X-NIXOS-SYSTEMD-AWARE) echo "1"; exit; ;;
*) ;;
esac
done
)

if [ -z "$session_is_systemd_aware" ]; then
/run/current-system/systemd/bin/systemctl --user ${action} nixos-fake-graphical-session.target
fi
'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more nixos like if this was an option and sessions know to support it turn it off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really do that because the same wrapper is used for all sessions, so we have to resort to runtime dispatch.

@bobby285271
Copy link
Member

However, in GNOME Flashback (XDG_CURRENT_DESKTOP=GNOME-Flashback:GNOME), it does not appear to be the case:

It looks like nixosTests.gnome-flashback is now failing 👀

@K900
Copy link
Contributor Author

K900 commented Jul 13, 2023

I think this might be #228946 ?

@bobby285271
Copy link
Member

bobby285271 commented Jul 13, 2023

Ah yeah, I was confused why the Pantheon test passed while not systemd managed but later found it does not have GNOME in XDG_CURRENT_DESKTOP 🤷‍♀️

So I think the budgie test should be failing with same reason, which has Budgie:GNOME as XDG_CURRENT_DESKTOP (cc @FedericoSchonborn)

Edit: #246743

@Uthar
Copy link
Contributor

Uthar commented Jul 14, 2023

I'm not sure if still needed, but I tested stumpwm like this:

In one terminal:

Xephyr :3

In another terminal:

DISPLAY=:3 /nix/store/...-stumpwm-22.11/bin/stumpwm

And it started.

@AndersonTorres
Copy link
Member

Cute :3

@K900 K900 deleted the dont-touch-graphical-session-target branch July 27, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.