Fedora KDE in nspawn container

not working perfectly, but working

Introduction

I kind of have a love-hate relationship with KDE:

  • love: community, openness, the fact they listen to their users, Qt
  • hate: buggy as hell, unpolished and ugly, priorities are all messed up, not product oriented, but feelings oriented, no vision

What do I mean by “feelings oriented”? God forbid they would do something sane that would piss-off 10 people, so everything gets dragged on, forever.

Years after Gnome decides things and implements them, KDE follows.

It’s like that browsers meme…

What are we? Browsers!

Examples:

  • sddm, years after they will implement plasma display manager
  • overview

But still, they are something that looks like Windows so it eased me into migration.

Anyway, I run Gnome because it just works and gets out of the way. From time to time I want to try out KDE, so to do that I used to use VMs, but there is always a lag…

Containerized system

Enter systemd-nspawn.

Unlike VMs, there is no (important) overhead. By doing the right things, we can render directly to gnome. Kind of “plasma in a window”.

In a more technical explanation:

  • we make a container where we install full fedora with kde
  • this container will interact with host system through a window
  • within a window is the plasma desktop

Steps:

Assuming host is fedora, in my case version 43…

Host

dnf install -y systemd-container

# Create a directory for the container
mkdir -p /var/lib/machines/fedora-kde

# Bootstrap a minimal Fedora system
dnf -y \
  --installroot=/var/lib/machines/fedora-kde \
  --releasever=43 \
  --use-host-config \
  install \
    dnf \
    fedora-release \
    iputils \
    less \
    ncurses \
    passwd \
    systemd \
    systemd-networkd \
    systemd-resolved \
    util-linux \
    vim-default-editor

# set the password
systemd-nspawn -D /var/lib/machines/fedora-kde passwd

# install kde
sudo dnf -y \
  --installroot=/var/lib/machines/fedora-kde \
  --releasever=43 \
  --use-host-config \
  --setopt=install_weak_deps=False \
  install \
    plasma-desktop \
    konsole \
    dolphin \
    plasma-nm \
    kwayland-integration

To make machinectl work with correct parameters, we need to make a file in /etc/systemd/nspawn/fedora-kde.nspawn. Name of .nspawn file must match to the directory in /var/lib/machines/<this>.

[Exec]
Boot=yes
PrivateUsers=no
Environment=WAYLAND_DISPLAY=wayland-0
Environment=XDG_RUNTIME_DIR=/run/user/1000
Environment=QT_QPA_PLATFORM=wayland
Environment=QT_WAYLAND_SHELL_INTEGRATION=xdg-shell
Environment=GDK_BACKEND=wayland

[Files]
Bind=/run/user/1000
Bind=/dev/dri

[Network]
VirtualEthernet=yes

Container

To start a container we should use machinectl, but at this point of time we have to do this as root

machinectl start fedora-kde
machinectl shell fedora-kde

# Create the group first
groupadd -g 1000 myuser

# Create the user linked to that group with UID 1000
useradd -u 1000 -g 1000 -m -s /bin/bash myuser

machinectl reboot fedora-kde

Once this has been set up, we fall back to user on host and log in into the machine using myuser:

machinectl shell myuser@fedora-kde

Once in, the following commands are executed within the container:

# in the shell (default size)
export XDG_RUNTIME_DIR=/run/user/1000
export WAYLAND_DISPLAY=wayland-0
export QT_QPA_PLATFORM=wayland

kwin_wayland --wayland-display $WAYLAND_DISPLAY \
    --exit-with-session /usr/bin/startplasma-wayland


# in the shell (full screen)
export XDG_RUNTIME_DIR=/run/user/1000
export WAYLAND_DISPLAY=wayland-0
export QT_QPA_PLATFORM=wayland

kwin_wayland --wayland-display $WAYLAND_DISPLAY \
    --width 3840 \
    --height 2160 \
    --fullscreen true \
    --exit-with-session /usr/bin/startplasma-wayland

Conclusion

Not everything works perfectly, but it works. I think user mappings might be better and whatnot, network setup was not documented, but overall it’s fine.

If someone tries this, have fun.