Skip to content

Instantly share code, notes, and snippets.

@dsd
Created August 26, 2025 07:31
Show Gist options
  • Select an option

  • Save dsd/3096a4ff05b59e1106c5d8b99b483006 to your computer and use it in GitHub Desktop.

Select an option

Save dsd/3096a4ff05b59e1106c5d8b99b483006 to your computer and use it in GitHub Desktop.
systemd service to launch mutter in root session (by Gemini AI)
[Unit]
Description=Mutter Wayland Compositor with Root Shell
# This service should start after logind is ready and devices are settled.
After=systemd-logind.service systemd-udev-settle.service
[Service]
# Run the service as the root user.
User=root
# Add root to the 'video' and 'input' groups for direct hardware access.
SupplementaryGroups=video input
# This is the key step to create a login session.
# It tells systemd to use the 'login' PAM service, which will
# use pam_systemd.so to register a proper session with logind.
PAMName=login
# systemd will automatically create /run/user/0 for the root user (UID 0)
# and clean it up when the service stops. This is crucial.
RuntimeDirectory=user/0
# This sets the environment variable that tells Wayland apps where to find
# essential runtime files (like the Wayland socket).
Environment=XDG_RUNTIME_DIR=/run/user/0
# The command to execute. Let's break it down:
# 1. dbus-run-session: Starts a private D-Bus message bus, which Mutter needs.
# 2. mutter --display-server: Starts Mutter as the primary compositor.
# 3. -- /usr/bin/foot: Specifies the program to run inside Mutter.
# 'foot' is a lightweight Wayland terminal. You can replace it with
# another terminal like 'gnome-terminal' if you have it installed.
ExecStart=/usr/bin/dbus-run-session -- /usr/bin/mutter --display-server -- /usr/bin/foot
# Attach this service's input and output to a specific virtual terminal.
# We use tty2 to avoid conflicts with the default console, which is often on tty1.
TTYPath=/dev/tty2
StandardInput=tty
StandardOutput=tty
StandardError=journal
# Automatically restart the service if it ever fails.
Restart=always
RestartSec=1
[Install]
# This ensures the service is started as part of the default graphical session.
WantedBy=graphical.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment