NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.98k stars 14k forks source link

xrdp configuration cannot easily get access to xsession start scripts #126265

Open ryantm opened 3 years ago

ryantm commented 3 years ago

Describe the bug

I have a NixOS 21.05 VM running atop Hyper-V and when I connect to it using the Enhanced Session, which uses xrdp, the desktop displays fine, but no applications launch.

To Reproduce Steps to reproduce the behavior:

  1. Connect to NixOS 21.05 VM running GNOME via xrdp
  2. Try to open gnome-terminal from the applications menu
  3. It looks like it is starting (has an icon in the top bar), but then it doesn't.

Expected behavior

Gnome terminal opens. (This used to work on NixOS 20.09.)

Screenshots image

Additional context

systemctl --user output:

● gnome-terminal-server.service                                                                                                                             loaded failed failed    GNOME Terminal Server
● xdg-desktop-portal-gtk.service                                                                                                                            loaded failed failed    Portal service (GTK+/GNOME implementation)
● xdg-desktop-portal.service                                                                                                                                loaded failed failed    Portal service

relevant nixos config:

{
    services.xserver = {
      enable = true;
      desktopManager = {
        gnome3.enable = true;
        xterm.enable = false;
      };
    };

    services.xrdp = {
      enable = true;
      defaultWindowManager = "${pkgs.gnome3.gnome-shell}/bin/gnome-shell";
      package = pkgs.xrdp.overrideAttrs (oldAttrs: {
        configureFlags = oldAttrs.configureFlags ++ [ "--enable-vsock" ];
        postInstall = oldAttrs.postInstall + ''
          substituteInPlace $out/etc/xrdp/xrdp.ini \
            --replace "use_vsock=false" "use_vsock=true" \
            --replace "security_layer=negotiate" "security_layer=rdp" \
            --replace "crypt_level=high" "crypt_level=none" \
            --replace "bitmap_compression=true" "bitmap_compression=false"

          substituteInPlace $out/etc/xrdp/sesman.ini \
            --replace "X11DisplayOffset=10" "X11DisplayOffset=0" \
            --replace "FuseMountName=thinclient_drives" "FuseMountName=host_drives"
        '';
      });
    };

    environment.etc."X11/Xwrapper.config".text = ''
      allowed_users=anybody
    '';
}

journal logs:

Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.ControlCenter.SearchProvider' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.Nautilus' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.Calculator.SearchProvider' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.Calendar' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.Characters.BackgroundService' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.clocks' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.seahorse.Application' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activating service name='org.gnome.Photos' requested by ':1.1' (uid=25001 pid=1539 comm="/nix/store/sv5cbszgsp1j14786c63wzpvjsn9jlbw-gnome-" label="kernel")
Jun 08 13:08:39 nix-ryantm org.gnome.Calculator.SearchProvider[38554]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .gnome-calculat[38554]: cannot open display: 
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Activated service 'org.gnome.Calculator.SearchProvider' failed: Process org.gnome.Calculator.SearchProvider exited with status 1
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.ControlCenter.SearchProvider'
Jun 08 13:08:39 nix-ryantm org.gnome.ControlCenter.SearchProvider[38550]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .gnome-control-[38550]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.Calculator.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.gnome.Calculator.SearchProvider exited with status 1
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider gnome-control-center.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.clocks'
Jun 08 13:08:39 nix-ryantm org.gnome.clocks[38560]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .gnome-clocks-w[38560]: cannot open display: 
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.seahorse.Application'
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.clocks.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm org.gnome.seahorse.Application[38562]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .seahorse-wrapp[38562]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.seahorse.Application.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.Nautilus'
Jun 08 13:08:39 nix-ryantm org.gnome.Nautilus[38552]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .nautilus-wrapp[38552]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.Nautilus.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.Photos'
Jun 08 13:08:39 nix-ryantm org.gnome.Photos[38564]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .gnome-photos-w[38564]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.Photos.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.Characters.BackgroundService'
Jun 08 13:08:39 nix-ryantm org.gnome.Characters.BackgroundService[38558]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .org.gnome.Char[38558]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.Characters.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:08:39 nix-ryantm dbus-daemon[1546]: [session uid=25001 pid=1546] Successfully activated service 'org.gnome.Calendar'
Jun 08 13:08:39 nix-ryantm org.gnome.Calendar[38556]: Unable to init server: Could not connect: Connection refused
Jun 08 13:08:39 nix-ryantm .gnome-calendar[38556]: cannot open display: 
Jun 08 13:08:39 nix-ryantm .gnome-shell-wr[1539]: Received error from D-Bus search provider org.gnome.Calendar.desktop: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Jun 08 13:09:03 nix-ryantm dbus-daemon[786]: [system] Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)
Jun 08 13:09:06 nix-ryantm org.gnome.Terminal.desktop[38597]: # Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Error calling StartServiceByName for org.gnome.Terminal: Timeout was reached

Notify maintainers

@NixOS/gnome

Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 5.12.4, NixOS, 21.05pre-git (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.12`
 - channels(ryantm): `""`
 - nixpkgs: `/home/ryantm/p/nixpkgs`
sydneymeyer commented 3 years ago

I had similar errors in my logs and issues with gtk-apps after the upgrade to 21.05, although i use sway instead of gnome.

I do not fully understand what has happened here, but after much fiddling around, manually starting a dbus user session with dbus-daemon --session --address=unix:path=$XDG_RUNTIME_DIR/bus appears to have things started working again.

ryantm commented 3 years ago

@sydneymeyer Thanks, I confirmed that also fixes it for me. And it lead me to investigate further. I figured out that GNOME sets services.xserver.updateDbusEnvironment which translates to ${lib.getBin pkgs.dbus}/bin/dbus-update-activation-environment --systemd --all in the xsession start script.

So changing it to something like this fixes the problem:

{
  services.xrdp.defaultWindowManager = "${pkgs.writeScript "xrdp-xsession-gnome" ''
    ${pkgs.gnome3.gnome-shell}/bin/gnome-shell &
    waitPID=$!
    ${lib.getBin pkgs.dbus}/bin/dbus-update-activation-environment --systemd --all
    test -n "$waitPID" && wait "$waitPID"
    /run/current-system/systemd/bin/systemctl --user stop graphical-session.target
    exit 0
  ''}";
}

It seems like a good way forward would be to expose the already created xsession scripts in a way that they could be used by xrdp. Or, update xrdp docs to recommend a login manager that can detect them.

ryantm commented 3 years ago

Related https://github.com/NixOS/nixpkgs/pull/83927

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

pdg137 commented 1 year ago

I can confirm this is still an issue with xrdp+GNOME on 22.11, including with the normal xrdp configuration (which now seems to to work fine so maybe there's no more need for Enhanced Session). The workaround @ryantm suggested seems not to work anymore, though I could easily be doing it wrong.

Putting

dbus-daemon --session --address=unix:path=$XDG_RUNTIME_DIR/bus

in a user .Xclients file does make it usable.

nixos-discourse commented 1 year ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/xrdp-issues-on-nixos/34581/1

rmst commented 10 months ago

On 23.11 @pdg137's workaround didn't work for me but @ryantm's workaround still kinda worked. I seem to be able to launch different apps but not the GNOME Settings app.

Are there any updates on this? Any alternative better ways to get RDP / remote desktop working with GNOME on NixOS?

jtojnar commented 10 months ago

GNOME supports RDP out of the box through gnome-remote-desktop. It can be enabled in the Settings app. You will also need to open the relevant port in firewall.

rmst commented 9 months ago

@jtojnar that failed when I first tried but your comment led to me trying again and I managed to make it work, thanks! The issue was with auto login and the resulting keyring problems. Needed to set the keyring password to be empty to make it work. Same bug: https://bugs.launchpad.net/ubuntu/+source/meta-gnome3/+bug/2000063

gotjoshua commented 6 months ago

It can be enabled in the Settings app. You will also need to open the relevant port in firewall.

true, but not with declarative config.

i adapted the settings from above and elsewhere, and got a working setup needed to also patch the service ExecStart cmd as it was only binding to ipv6 https://gist.github.com/gotjoshua/3d7c51a76b3d74b213fc86e32cea3935#file-configuration-nix-L38-L46

maybe it helps another poor soul looking for help with xrdp config shenanigans