Skip to content

nixos/xsession: use graphical systemd user target#26094

Merged
fpletz merged 2 commits intoNixOS:masterfrom
mayflower:feature/graphical-user-session
May 29, 2017
Merged

nixos/xsession: use graphical systemd user target#26094
fpletz merged 2 commits intoNixOS:masterfrom
mayflower:feature/graphical-user-session

Conversation

@fpletz
Copy link
Copy Markdown
Member

@fpletz fpletz commented May 25, 2017

Motivation for this change

While systemd suggests using the pre-defined graphical-session user
target, I found that this interface is difficult to use. Additionally,
no other major distribution, even in their unstable versions, currently
use this mechanism.

The window or desktop manager is supposed to run in a systemd user service
which activates graphical-session.target and the user services that are
binding to this target. The issue is that we can't elegantly pass the
xsession environment to the window manager session, in particular
whereas the PassEnvironment option does work for DISPLAY, it for some
mysterious reason won't for PATH.

This commit implements a new graphical user target that works just like
default.target. Services which should be run in a graphical session just
need to declare wantedBy graphical.target. The graphical target will be
activated in the xsession before executing the window or display manager.

Fixes #17858.

Things done

Only tested with i3 and slim right now but will test other window and desktop managers before merging.

@fpletz fpletz 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, 2017
@fpletz fpletz added this to the 17.09 milestone May 25, 2017
@mention-bot
Copy link
Copy Markdown

@fpletz, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @nckx and @nbp to be potential reviewers.

@michaelpj
Copy link
Copy Markdown
Contributor

Is there a reason that this couldn't be graphical-session.target? It's not quite how it's supposed to be used, but a) if we ever implement it properly then the things which depend on it will automatically do the right thing, and b) if we have it around then we're more likely to be able to use upstream units.

Also, if you're looking for more test cases, the arbtt service should also depend on this rather than default.target.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo -> graphical

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed!

@pbogdan
Copy link
Copy Markdown
Member

pbogdan commented May 25, 2017

FWIW both redshift and unclutter service (patched locally in the same way as redshift in this PR) are working for me on lightdm / xmonad setup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is DBUS_SESSION_BUS_ADDRESS also inherited by default? pinentry-gtk-2 needs that.

Copy link
Copy Markdown
Member

@Mic92 Mic92 May 25, 2017

Choose a reason for hiding this comment

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

otherwise passing --systemd to dbus-update-activation-environment might be a good idea: https://dbus.freedesktop.org/doc/dbus-update-activation-environment.1.html or using systemctl --user import-environment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't seem like it:

$ systemctl --user status redshift.service | grep PID
 Main PID: 5762 (redshift)
$ cat /proc/5762/environ | awk -v 'RS=\0' '{ print $0 }' | grep DBUS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

pinentry-gtk-2 works for me in X. :) I've removed the PassEnvironment because it's not needed anymore. (GPG_TTY is picked up by gpg).

@Mic92
Copy link
Copy Markdown
Member

Mic92 commented May 25, 2017

It would be also cool, if we can make graphical-session.target a recommendation/standard in systemd. That way also upstream project would begin to use the target in their units. This might be worth a discussion in upstream.

@fpletz fpletz force-pushed the feature/graphical-user-session branch from 16067d2 to d3615e0 Compare May 25, 2017 20:06
@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

I've fixed the gnupg agent module to find the correct terminal every time for gpg invocations, even if logged in in different terminals. Unfortunately, this doesn't always work for SSH but we can't fix that because it's a missing feature in the SSH agent protocol. Only use one tty or gpg-connect-agent updatestartuptty /bye. :)

@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

Oh, and the module is using the upstream gpg-agent units now, so we have socket activation if SSH is not enabled! 🍻

@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

Is there a reason that this couldn't be graphical-session.target?

I wanted to use a different target name because we would have to override some options and the semantics of the unit would slightly change. My guess is that no package is currently shipping systemd units with graphical-session.target anyways because no distro I checked (Debian, Fedora) adopted this but please prove me wrong. :)

It would be also cool, if we can make graphical-session.target a recommendation/standard in systemd. That way also upstream project would begin to use the target in their units. This might be worth a discussion in upstream.

Here is a talk about graphical-session.target from systemd.conf and about some of the problems and hacks needed with this approach: https://www.youtube.com/watch?v=hq18daxTkLA

@fpletz fpletz force-pushed the feature/graphical-user-session branch 2 times, most recently from 78d661d to b7069cc Compare May 25, 2017 20:32
@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

Oh, and there is also documentation about graphical-session.target in the manpage systemd.special(7).

Pondering about it some more, I think we should indeed override graphical-session.target instead of defining a new target because the semantic differences are in fact not very serious. The main difference is how the target can be activated but services would be activated the same way. I'll update the code.

@Mic92
Copy link
Copy Markdown
Member

Mic92 commented May 25, 2017

oh, did not know it was already a standard.

@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

Okay, now using graphical-session.target. Works just like graphical.target. I'm also using partOf now because this will ensure the services get stopped when graphical-session.target is stopped. This ensures X services are terminated even if a user is still logged in on another TTY. systemd.special(7) also recommends this. :)

Will squash and fix commit description before merging. I'm also in the process of converting and testing all remaining user services that depend on X.

@fpletz fpletz requested a review from peti May 25, 2017 21:31
@fpletz
Copy link
Copy Markdown
Member Author

fpletz commented May 25, 2017

All remaining services I could identify are fixed. Another highlight: We now have a working socket-activated pulseaudio user service. ;)

fpletz added 2 commits May 29, 2017 15:05
While systemd suggests using the pre-defined graphical-session user
target, I found that this interface is difficult to use. Additionally,
no other major distribution, even in their unstable versions, currently
use this mechanism.

The window or desktop manager is supposed to run in a systemd user service
which activates graphical-session.target and the user services that are
binding to this target. The issue is that we can't elegantly pass the
xsession environment to the window manager session, in particular
whereas the PassEnvironment option does work for DISPLAY, it for some
mysterious reason won't for PATH.

This commit implements a new graphical user target that works just like
default.target. Services which should be run in a graphical session just
need to declare wantedBy graphical.target. The graphical target will be
activated in the xsession before executing the window or display manager.

Fixes NixOS#17858.
Creates a systemd user service and updates the tty on new logins so
that gpg-agent may find the current tty even if the SSH agent mode
is used.
@fpletz fpletz force-pushed the feature/graphical-user-session branch from ea92510 to 04158d9 Compare May 29, 2017 13:05
@fpletz fpletz merged commit a1b5328 into NixOS:master May 29, 2017
@fpletz fpletz deleted the feature/graphical-user-session branch May 29, 2017 13:06
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/`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants