git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/displayManager: add XDG_SESSION_ID to systemd user environment

xss-lock needs XDG_SESSION_ID to respond to loginctl lock-session(s) (and possibly other session operations such as idle hint management). This change adds XDG_SESSION_ID to the list of imported environment variables when starting systemctl. Inspired by home-manager, add importVariables configuration. Set session to XDG_SESSION_ID when running xss-lock as a service. Co-authored-by: misuzu <bakalolka@gmail.com>

commit660882d8830153422a79d6cbea45f2dbe272cf21 authorEven Brenden <evenbrenden@gmail.com> dateFri 24 Jul 2020, 13:41 (6 years ago) parent48faedc
2 files changed+25−8
nixos/modules/programs/xss-lock.nix+1−1 nixos/modules/services/x11/display-managers/default.nix+24−7
nixos/modules/programs/xss-lock.nix+1−1
@@ -34,7 +34,7 @@ in
3434 partOf = [ "graphical-session.target" ];
3535 serviceConfig.ExecStart = with lib;
3636 strings.concatStringsSep " " ([
37− "${pkgs.xss-lock}/bin/xss-lock"
37+ "${pkgs.xss-lock}/bin/xss-lock" "--session \${XDG_SESSION_ID}"
3838 ] ++ (map escapeShellArg cfg.extraOptions) ++ [
3939 "--"
4040 cfg.lockerCommand
nixos/modules/services/x11/display-managers/default.nix+24−7
@@ -55,13 +55,6 @@ let
5555 exec &> >(tee ~/.xsession-errors)
5656 ''}
5757
58− # Tell systemd about our $DISPLAY and $XAUTHORITY.
59− # This is needed by the ssh-agent unit.
60− #
61− # Also tell systemd about the dbus session bus address.
62− # This is required by user units using the session bus.
63− /run/current-system/systemd/bin/systemctl --user import-environment DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS
64−
6558 # Load X defaults. This should probably be safe on wayland too.
6659 ${xorg.xrdb}/bin/xrdb -merge ${xresourcesXft}
6760 if test -e ~/.Xresources; then
@@ -70,6 +63,12 @@ let
7063 ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults
7164 fi
7265
66+ # Import environment variables into the systemd user environment.
67+ ${optionalString (cfg.displayManager.importedVariables != []) (
68+ "/run/current-system/systemd/bin/systemctl --user import-environment "
69+ + toString (unique cfg.displayManager.importedVariables)
70+ )}
71+
7372 # Speed up application start by 50-150ms according to
7473 # http://kdemonkey.blogspot.nl/2008/04/magic-trick.html
7574 rm -rf "$HOME/.compose-cache"
@@ -289,6 +288,14 @@ in
289288 '';
290289 };
291290
291+ importedVariables = mkOption {
292+ type = types.listOf (types.strMatching "[a-zA-Z_][a-zA-Z0-9_]*");
293+ visible = false;
294+ description = ''
295+ Environment variables to import into the systemd user environment.
296+ '';
297+ };
298+
292299 job = {
293300
294301 preStart = mkOption {
@@ -360,6 +367,16 @@ in
360367
361368 services.xserver.displayManager.xserverBin = "${xorg.xorgserver.out}/bin/X";
362369
370+ services.xserver.displayManager.importedVariables = [
371+ # This is required by user units using the session bus.
372+ "DBUS_SESSION_BUS_ADDRESS"
373+ # These are needed by the ssh-agent unit.
374+ "DISPLAY"
375+ "XAUTHORITY"
376+ # This is required to specify session within user units (e.g. loginctl lock-session).
377+ "XDG_SESSION_ID"
378+ ];
379+
363380 systemd.user.targets.graphical-session = {
364381 unitConfig = {
365382 RefuseManualStart = false;