Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

437. Session and environment

This page covers the graphical session: how SDDM starts a Plasma session through the KDOS session wrapper, the environment every desktop program inherits, where the KDOS defaults for KDE programs live, how to add a variable of your own, the per-user services that outlive a session, how to end and restart a session, and how to reach a running session from tty2 or over SSH. The login screen itself, and whether a machine logs in by itself, is on Login and autologin. What each part of the session does and why it is started in that order is explained in The session; this page gives the procedures.

Installation

The session is not a service and has no script in /etc/init.d. SDDM starts it after a login, and everything in it runs as the logged-in user. Its pieces:

The live medium and an installed system run the same session. On the live medium the home directory is on the boot overlay, so everything a session writes there is gone at power-off unless the medium has a persistence store; see Live persistence.

Configuration

How SDDM starts the session

SDDM reads /etc/sddm.conf.d/00-kdos.conf. Its [Wayland] group names the greeter’s compositor and the command a session is started with, and its [X11] group offers no X session at all:

[Wayland]
# plasma-wayland.conf's command. --inputmethod plasma-keyboard gives the greeter
# its on-screen keyboard, which KWin shows when the password field is touched
# and the footer's Virtual Keyboard button shows for a mouse: the button is a
# call to this KWin over the greeter's session bus, which turnstile's ksvc
# backend starts for the sddm account alone. No --xwayland: KWin starts no X
# server without it, so none runs before a user session starts one. --locale1
# takes the keyboard layouts from locale1, which kdos-settingsd serves, and
# with more than one the footer's layout button switches them over that bus.
CompositorCommand=kwin_wayland --no-global-shortcuts --no-lockscreen --inputmethod plasma-keyboard --locale1
# SDDM runs this with the session's Exec= line as its one argument, in place of
# its own wayland-session script: the wrapper reads the login shell's profile,
# checks the session bus and warms the boxes before it execs Plasma.
SessionCommand=/usr/local/bin/kdos-session-wrapper
SessionDir=/usr/share/wayland-sessions

[X11]
# No directory, so no X session can ever be offered.
SessionDir=

fs/etc/sddm.conf.d/00-kdos.conf, lines 46–64

SDDM runs kdos-session-wrapper as the user, after PAM has opened the session, with the Exec= line of plasma.desktop as its one argument. The wrapper re-runs itself as a login shell that reads no startup file, then reads that shell’s login files itself, so /etc/profile, /etc/profile.d and ~/.bash_profile reach Plasma and a profile script that exits is logged with its status; logs each stage of the login to syslog under kdos-session; waits out a previous logout’s ksvc stop if one is still running; checks that the session bus at $XDG_RUNTIME_DIR/bus answers and points DBUS_SESSION_BUS_ADDRESS at it, refusing to start the session when it does not, so the greeter comes back; settles the environment before anything reads it; and refuses an Exec= line whose first word names no program, from fs/usr/local/bin/kdos-session-wrapper:

XDG_CURRENT_DESKTOP=KDE
export XDG_CURRENT_DESKTOP
kdos_session_xdg_dirs
kdos_session_live_data
kdos_session_open
kdos_session_fcitx5_profile
unset QT_IM_MODULE QT_IM_MODULES GTK_IM_MODULE
unset TERM LINES COLUMNS

kdos_session_boxes

# Word-split as SDDM's wayland-session does, and never globbed.
set -f
# shellcheck disable=SC2068
set -- $@
command -v "$1" >/dev/null 2>&1 || refuse "the session command '$1' is not a program"
note info "login $$: starting $*"
trap - EXIT TERM HUP INT
exec "$@"

fs/usr/local/bin/kdos-session-wrapper, lines 266–284

kdos_session_xdg_dirs puts the KDOS defaults into XDG_CONFIG_DIRS (below); kdos_session_live_data, on the live medium alone, puts /usr/share/kdos/data-live in front of XDG_DATA_DIRS, whose Welcome Center entry starts the tour with --live-environment, so a tour reopened from the launcher keeps its live pages; the QT_IM_MODULE and GTK_IM_MODULE variables are cleared so Qt and GTK reach the input method through KWin, and TERM, LINES and COLUMNS are cleared because the session has no terminal. kdos_session_fcitx5_profile gives a home with no ~/.config/fcitx5/profile one that names the system keyboard layout, before KWin starts fcitx5 (see Input methods). kdos_session_boxes starts, in the background, the boxes named in ~/.config/kdos/favorites (see The pinned applications), so their first launch is not a cold start. Then startplasma-wayland runs. KDOS has no systemd user instance, so the session is always Plasma’s classic one, in which plasma_session starts kded6, ksmserver, plasmashell and the autostart entries itself; the KDOS default that says so, from fs/usr/share/kdos/xdg/startkderc:

#   How startplasma brings the session up.
#
# There is no systemd user instance on KDOS, so the session is always the
# classic one, in which plasma_session starts kded6, ksmserver, plasmashell
# and the autostart entries itself. With the key unset startplasma first asks
# the session bus for systemd's plasma-workspace.target before deciding the
# same; `false` skips the question.
# ---------------------------------

[General]
systemdBoot=false

fs/usr/share/kdos/xdg/startkderc, lines 8–18

Where the KDOS defaults live

Every KDOS default for a KDE program is a file in /usr/share/kdos/xdg/: kwinrc, kglobalshortcutsrc, kscreenlockerrc, powerdevilrc, plasmarc, breezerc, startkderc and the rest. The directory is the last entry of XDG_CONFIG_DIRS, after /etc/xdg, so KDE’s configuration cascade reads, for each key, the first of:

Order Directory Whose
1 ~/.config The person’s own: everything System Settings saves
2 ~/.config/kdedefaults What the global theme last applied
3 /usr/share/kdos/xdg-vm, /usr/share/kdos/xdg-live Overlays, each only where it applies: in a virtual machine, no idle dimming, timed lock or idle and lid suspend; on the live medium, no file index, no timed lock, no wallet and no update notice
4 /etc/xdg The machine’s administrator
5 /usr/share/kdos/xdg KDOS

So a file the administrator puts in /etc/xdg overrides the KDOS default key by key, and a person’s own setting overrides both. /etc/xdg/kdeglobals carries one key, the global theme, which the installer writes from the accent chosen at installation.

The order is set in two places, so a session started by SDDM and a shell started any other way agree: kdos_session_xdg_dirs in /usr/local/lib/kdos/session-common.sh, which also adds the two overlays, and every login shell’s profile, from fs/etc/profile.d/10-wayland.sh:

case ":${XDG_CONFIG_DIRS:-/etc/xdg}:" in
	*:/usr/share/kdos/xdg:*) ;;
	*) export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}:/usr/share/kdos/xdg" ;;
esac

fs/etc/profile.d/10-wayland.sh, lines 64–67

The environment every program inherits

/etc/profile.d/10-wayland.sh runs for every login shell, the session wrapper’s included. It fills in XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS for a shell no PAM session started (an su without -l), names the desktop and its Plasma release (KDE_SESSION_VERSION=6, which xdg-utils compares as a number) for a shell outside the session so files opened from a console open in the desktop’s applications, and chooses the toolkits’ back ends:

# Toolkit back ends. GTK and Qt are built with their Wayland and X11 back ends,
# and Wayland comes first; SDL is built with Wayland alone, so its driver
# names no fallback; Tk and Motif have only X11 and run under Xwayland.
# Qt takes a list and falls back to xcb (Xwayland) only when the Wayland
# plugin cannot start, which is a Qt 5 application built without one; a name
# on its own here would leave that application not starting at all. GDK_BACKEND
# is left unset: GDK already tries Wayland first, and a value here would
# override the GDK_BACKEND=x11 an X11-only application sets for itself.
export QT_QPA_PLATFORM="wayland;xcb"
export MOZ_ENABLE_WAYLAND=1
export SDL_VIDEODRIVER=wayland
export CLUTTER_BACKEND=wayland

# Native GTK and Qt applications on the host. GTK_USE_PORTAL=1 sends GTK 3's
# native file chooser and print dialog to the portals, so a GTK 3 application
# that uses them opens the KDE file dialog, and Firefox's file picker reads it
# too; GTK 4 uses the portals without it, and a program that builds GTK's own
# file dialog widget keeps GTK's. GTK 3 then reads its theme, fonts and the
# rest from the Settings portal, but loads colorreload-gtk-module, its only
# way to repaint on a colour change, from org.gtk.Settings: gtk3 is patched to
# open that service beside the portal, and kde-gtk-config to serve it although
# kded inherits the variable. Qt takes one platform theme name here, not a
# list, and each Qt major version searches only its own plugin directory: a Qt 6 application finds plasma-integration's
# `kde` theme and the colours of kdeglobals; a Qt 5 application finds the qt5ct
# plugin under `kde` (the qt5ct port adds the key) and reads the ~/.config/qt5ct
# files `kdos theme` writes from the KDE colour scheme. Without it, a Qt 5
# application paints Qt's built-in palette under every KDOS theme.
export GTK_USE_PORTAL=1
export QT_QPA_PLATFORMTHEME=kde

fs/etc/profile.d/10-wayland.sh, lines 82–110

/usr/share/kdos/xdg/plasma-workspace/env/kdos.sh is the environment script Plasma itself reads. startplasma sources every plasma-workspace/env/*.sh along XDG_CONFIG_DIRS, the person’s own ~/.config/plasma-workspace/env/ last, and takes every variable they leave set into the session:

# A passphrase asked for with no terminal to ask on — ssh-add from an
# autostart entry, git or ssh run from an application — is asked in
# ksshaskpass's dialog, whose answer the session's secret store can keep.
# SSH_ASKPASS_REQUIRE stays unset, so ssh and ssh-add run in Konsole still
# ask on its terminal: OpenSSH runs the dialog only when it has none. git's
# own prompts — an HTTPS user name and password — are the exception: git
# prefers SSH_ASKPASS to the terminal when GIT_ASKPASS and core.askPass are
# unset, so they come up in the dialog even in Konsole.
if [ -z "${SSH_ASKPASS:-}" ] && [ -x /usr/bin/ksshaskpass ]; then
	SSH_ASKPASS=/usr/bin/ksshaskpass
	export SSH_ASKPASS
fi

# Qt Quick draws its distance-field text, which Plasma's labels use, with
# subpixel antialiasing unless this says otherwise: fontconfig's rgba=none and
# kdeglobals' XftSubPixel never reach it, and every panel label, notification
# and the KSplash footer would carry coloured fringes that no widget does.
QSG_DISTANCEFIELD_ANTIALIASING=gray
export QSG_DISTANCEFIELD_ANTIALIASING

# The desktop every program asks about, for the mimeapps list
# (kde-mimeapps.list), the portal (kde-portals.conf) and OnlyShowIn=KDE.
# startplasma sets the same name after the scripts; set here, the scripts
# sourced after this one see it too.
XDG_CURRENT_DESKTOP=KDE
export XDG_CURRENT_DESKTOP

fs/usr/share/kdos/xdg/plasma-workspace/env/kdos.sh, lines 34–59

kdos-shortcuts.sh beside it copies the KDOS global shortcuts into a person’s ~/.config/kglobalshortcutsrc once each; see Shortcuts and window rules.

The per-user services

turnstile starts a user’s services at the first PAM login, the greeter’s or a console’s, and stops them at the last logout. An SSH login opens no PAM session, because OpenSSH is built without PAM, so it starts nothing and holds nothing open. Its configuration, from fs/etc/turnstile/turnstiled.conf:

## ██╗  ██╗██████╗  ██████╗ ███████╗
## ██║ ██╔╝██╔══██╗██╔═══██╗██╔════╝
## █████╔╝ ██║  ██║██║   ██║███████╗
## ██╔═██╗ ██║  ██║██║   ██║╚════██║
## ██║  ██╗██████╔╝╚██████╔╝███████║
## ╚═╝  ╚═╝╚═════╝  ╚═════╝ ╚══════╝
## ---------------------------------
##   KD's Homebrew Linux Distro
## ---------------------------------
##
## turnstiled's configuration on KDOS: per-user services and the runtime
## directory, from a user's first login to that user's last logout.
##
## One `key = value` per line. A value turnstiled does not accept is logged to
## syslog and the key keeps its built-in default; a misspelt KEY is skipped
## without a word, and the default it leaves can be the wrong one (the backend
## falls back to `dinit`, which is not on this system). turnstiled(8) and
## turnstiled.conf(5) are the reference.

debug = no
debug_stderr = no

# The user services are /etc/kdos/user-services, run under ksvc by the backend
# /usr/lib/turnstile/ksvc. There is one backend for every account: the backend
# itself starts nothing for a system account (the `sddm` greeter), so the
# greeter still gets its runtime directory through pam_turnstile. The one
# system account it serves is plasma-setup's, whose first-boot wizard runs in
# a whole Plasma session.
backend = ksvc

# THE ONE OWNER OF /run/user/<uid>. turnstile makes it at a user's first login
# and removes it after the last logout, once the services in it have stopped;
# elogind is built with its own runtime-directory code removed, because two
# owners would delete each other's directory — elogind's at its last session,
# under the user services and boxes still using it. kdos-appbox hands every box
# /run/user/<uid> and DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/<uid>/bus,
# so the path is fixed and is never moved.
manage_rundir = yes
rundir_path = /run/user/%u

# Exported into every login's PAM environment once the backend has the session
# bus answering at $XDG_RUNTIME_DIR/bus, so Plasma and every box share it;
# kdos-session-wrapper refuses to start Plasma on any other.
export_dbus_address = yes

# A user's services, boxes included, stop at the last logout unless
# /var/lib/elogind/linger/<user> exists. That is the file
# `loginctl enable-linger` writes, and turnstile is built to read it there.
# Lingering needs manage_rundir, since only the owner of the directory can
# promise not to remove it.
linger = maybe

# The seconds a login waits for the backend to report its services ready. The
# backend's own waits stop at ten; past fifteen turnstiled gives the login up,
# services and runtime directory with it.
login_timeout = 15

# root logs in to a runtime directory and no services: nothing in
# /etc/kdos/user-services is for root, and the system's services are rcS's.
root_session = no

fs/etc/turnstile/turnstiled.conf

backend = ksvc runs the scripts in /etc/kdos/user-services/ under the user’s own ksvc, each in name order: 10_dbus.sh (the session bus at $XDG_RUNTIME_DIR/bus), 15_ssh-agent.sh (the account’s ssh-agent), 20_pipewire.sh, 21_wireplumber.sh, 22_pipewire-pulse.sh, 25_mpd.sh, 30_timers.sh (the timers in /etc/kdos/user-services/timers.d/ and the user’s own) and 40_boxes.sh (which stops the user’s containers and podman’s pause process). A user service’s log is $XDG_RUNTIME_DIR/ksvc/kdos-svc.<name>.log. Every account from uid 1000 gets them, and plasma-setup; the greeter’s sddm account gets 10_dbus.sh alone, the bus its on-screen keyboard and layout buttons reach its KWin over; any other system account gets none.

The keyboard layout

The layout the login screen and every new session start with is the machine’s, in /etc/kdos/xkb.conf, which kdos-settingsd serves as org.freedesktop.locale1. The greeter’s KWin reads it before anybody types, and startplasma copies it into each session. Inside a session KWin and the lock screen read /etc/xdg/kxkbrc before that copy: the installer writes it, and kdos-settingsd rewrites it with the same layout on every locale1 layout change (plasma-setup’s on an OEM machine included) and removes it for an empty one. A person’s layout on the Keyboard page of System Settings, saved in ~/.config/kxkbrc, comes after both and wins. From fs/etc/kdos/xkb.conf:

# /etc/kdos/xkb.conf — the keyboard layout the login screen and every new
# session start with.
#
# kdos-settingsd serves these four values as org.freedesktop.locale1's
# X11Model, X11Layout, X11Variant and X11Options. The login screen's
# compositor (kwin_wayland --locale1) reads them before anybody can type, and
# startplasma copies them into each session as the XKB_DEFAULT_* variables.
# The installer and kdos-settingsd write the same layout to /etc/xdg/kxkbrc
# (an empty layout removes it), which the session and the lock screen read
# before those variables, so while that file names a layout a hand edit of
# this one reaches the login screen alone. A person's own layout in System
# Settings (~/.config/kxkbrc) outranks both.
#
# AN EMPTY XKBLAYOUT FOLLOWS THE CONSOLE: the layout is then the one nearest
# the console keymap in /etc/keymap, the file the installer writes. A layout
# written here is kept as written. plasma-setup's keyboard page writes it on
# a first boot; the Keyboard page of System Settings sets one person's layout
# and leaves this file and /etc/xdg/kxkbrc alone. Change it with
#
#     dbus-send --system --print-reply --dest=org.freedesktop.locale1 \
#         /org/freedesktop/locale1 org.freedesktop.locale1.SetX11Keyboard \
#         string:de string:pc105 string: string: boolean:true boolean:true
#
# rather than by hand: the daemon checks each value against xkeyboard-config,
# sets the nearest console keymap with it (the first `true`), rewrites
# /etc/xdg/kxkbrc and tells the login screen at once. A value here is the
# plain word XKB uses (letters, digits and `_+,:.-`), so the file is also
# valid shell.
XKBMODEL=
XKBLAYOUT=
XKBVARIANT=
XKBOPTIONS=

fs/etc/kdos/xkb.conf

Usage

Starting a session

Log in at the SDDM greeter, which offers one session, Plasma (Wayland). A machine set to log in by itself starts the session with no greeter at all; see Login and autologin.

From a console login on tty2, a second session can be started by hand. It runs with the environment of that login shell and is registered with elogind as the tty2 session:

startplasma-wayland

Ending the session

Log Out, Restart and Shut Down are in the Application Launcher’s Leave buttons and on Ctrl+Alt+Del, which opens the logout screen. At the end of every session Plasma runs the scripts in plasma-workspace/shutdown/ along XDG_CONFIG_DIRS. The KDOS ones run in name order: kdos-boxes.sh records the running boxes for the next login, kdos-speech.sh ends the speech server a screen reader started, unless another login of the user (a console or a second graphical login) is open, then kdos.sh stops every box that has run past its profile’s autostop. The user’s services keep running until the user’s last login ends.

From a terminal inside the session:

qdbus6 org.kde.Shutdown /Shutdown logout

Restarting part of a running session

kquitapp6 plasmashell; kstart plasmashell   # the panel and the desktop
kquitapp6 kded6; kstart kded6               # the background modules
qdbus6 org.kde.KWin /KWin replace           # the compositor; every window reconnects
service --user restart pipewire             # one of your own services
service --user list                         # all of your services

kstart detaches the program from the terminal, so it outlives the Konsole it was typed in; a plasmashell & is killed when that Konsole closes. A KWin that dies is started again by kwin_wayland_wrapper and the windows reconnect; plasmashell exits with it and the KDOS kded module starts it again a few seconds later, at most five times a minute (see How plasmashell is kept running). When KWin crashes more than ten times in a row, kwin_wayland_wrapper stops restarting it, the session ends, and SDDM shows the greeter again.

Setting a variable for every desktop program

  1. Make the directory: mkdir -p ~/.config/plasma-workspace/env.
  2. Write a script ending in .sh that exports the variable, for example ~/.config/plasma-workspace/env/editor.sh containing export EDITOR=micro.
  3. Log out and back in. startplasma sources the script after the KDOS ones, so its value wins.

A variable meant for login shells as well, consoles and SSH included, belongs in ~/.bash_profile instead; the session wrapper reads that file too.

Reaching a running session from tty2 or SSH

A console login of the same user shares the user’s services, so it reaches the session bus and everything on it. An SSH login has no runtime directory of its own: the login profile points it at the one a still-open login of the same user keeps, so it reaches the bus only while that login lasts, and loginctl shows no session for it:

echo "$DBUS_SESSION_BUS_ADDRESS"     # unix:path=/run/user/<uid>/bus
qdbus6 org.kde.KWin /KWin supportInformation | head
loginctl list-sessions               # every session elogind knows, and which is active

A graphical program started from there needs the session’s display: WAYLAND_DISPLAY=wayland-1 kate (KWin’s socket is the first free wayland-N from 1).

Reopening applications at login

Plasma saves the open applications when a session ends and restarts the ones that support session management at the next login. System Settings → Session → Desktop Session sets whether it does, and which applications it leaves out.

Changing the keyboard layout for the session

  1. System Settings → Keyboard → Layouts: add a layout and turn on Configure layouts. The change applies at once and is yours alone.
  2. For the machine’s own layout, the one the login screen uses, see Locale and console.

Tips

Troubleshooting

The greeter comes back right after a login. The session wrapper refused, or Plasma failed.

  1. Log in on tty2 (Ctrl+Alt+F2).
  2. tail -30 ~/.local/share/sddm/wayland-session.log. A line from kdos-session-wrapper names what it refused, for example that the session bus does not answer.
  3. service --user status dbus for the bus, and sudo grep kdos-session /var/log/messages for the refusal in syslog.

The desktop draws in Breeze’s colours, with upstream’s defaults. The session has no /usr/share/kdos/xdg in XDG_CONFIG_DIRS. Check it from Konsole: echo "$XDG_CONFIG_DIRS". A session started some way other than through SDDM or a login shell skips both places that add it.

Notifications, single-instance applications or a box’s portals do nothing. The program is on a private session bus rather than the user’s. echo "$DBUS_SESSION_BUS_ADDRESS" in it must read unix:path=/run/user/<uid>/bus.

A variable set in ~/.config/plasma-workspace/env is missing. The script must end in .sh and export the variable; an unset in it does not reach the session. Log out fully: the scripts are read only at the start of a session.

Known gaps

See also