Merge pull request #93764 from evenbrenden/xdg-session-id-user-units

nixos/displayManager: add XDG_SESSION_ID to systemd user environment

authored by

WORLDofPEACE and committed by
GitHub
e044909a ff7e38b9

+25 -8
+1 -1
nixos/modules/programs/xss-lock.nix
··· 34 34 partOf = [ "graphical-session.target" ]; 35 35 serviceConfig.ExecStart = with lib; 36 36 strings.concatStringsSep " " ([ 37 - "${pkgs.xss-lock}/bin/xss-lock" 37 + "${pkgs.xss-lock}/bin/xss-lock" "--session \${XDG_SESSION_ID}" 38 38 ] ++ (map escapeShellArg cfg.extraOptions) ++ [ 39 39 "--" 40 40 cfg.lockerCommand
+24 -7
nixos/modules/services/x11/display-managers/default.nix
··· 55 55 exec &> >(tee ~/.xsession-errors) 56 56 ''} 57 57 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 - 65 58 # Load X defaults. This should probably be safe on wayland too. 66 59 ${xorg.xrdb}/bin/xrdb -merge ${xresourcesXft} 67 60 if test -e ~/.Xresources; then ··· 69 62 elif test -e ~/.Xdefaults; then 70 63 ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults 71 64 fi 65 + 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 + )} 72 71 73 72 # Speed up application start by 50-150ms according to 74 73 # http://kdemonkey.blogspot.nl/2008/04/magic-trick.html ··· 289 288 ''; 290 289 }; 291 290 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 + 292 299 job = { 293 300 294 301 preStart = mkOption { ··· 392 399 ]; 393 400 394 401 services.xserver.displayManager.xserverBin = "${xorg.xorgserver.out}/bin/X"; 402 + 403 + services.xserver.displayManager.importedVariables = [ 404 + # This is required by user units using the session bus. 405 + "DBUS_SESSION_BUS_ADDRESS" 406 + # These are needed by the ssh-agent unit. 407 + "DISPLAY" 408 + "XAUTHORITY" 409 + # This is required to specify session within user units (e.g. loginctl lock-session). 410 + "XDG_SESSION_ID" 411 + ]; 395 412 396 413 systemd.user.targets.graphical-session = { 397 414 unitConfig = {