Files
komorebi/nix/dev/krdp.nix
T
LGUG2Z 8b9cde08d0 build(nix): Plasma guests to develop against
The VM tests boot a machine, run a scenario and power it off. Trying a change by
hand needs a Plasma session that stays up, and on a Mac, one that renders on its
GPU.

nix/dev/plasma-vm.nix is a guest for QEMU on an Apple silicon Mac, headless or
with a Plasma session that logs in by itself, and nix/dev/plasma-utm.nix is that
session as a disk image for UTM, whose QEMU renders on the Mac's GPU. They are
nixosConfigurations of the flake, and install komorebi with services.komorebi
from the flake's packages. They carry no key, password or configuration of
anyone's: the console logs in by itself, ssh takes the keys a user puts in the
guest, and the RDP password is a file in the guest. plasma-guests-eval evaluates
the three on every system.

nix/dev/krdp.nix runs KRDP in the session, and the slow suite vm-rdp runs the
same unit in the session node: it waits for a password and listens once it has
one, FreeRDP's client is let in with the password and not with another, and the
picture the client gets on an X server of its own is the display. FreeRDP
decodes KRDP's H.264 with OpenH264 and shows nothing, so the guests' client is
built without it and decodes with FFmpeg. Keys over RDP stay unverified, since
no client can script them against KRDP; PLATFORM.md says so and what the suite
checks.

docs/dev/utm.md says how to build and run the guests, and what a builder has to
be.
2026-10-28 07:39:49 -07:00

66 lines
2.6 KiB
Nix

# KRDP, Plasma's RDP server, in the Plasma session of every user who logs in. The session guest
# of plasma-vm.nix enables it, and so does the VM suite `rdp`, which checks that a client can log
# in and get a picture of the desktop (docs/dev/PLATFORM.md says what it does not check).
#
# The password is not in the repository: the unit starts once the user has written one to
# ~/.config/komorebi-vm/rdp-password, and a client logs in with the user's name and that password.
{
config,
lib,
pkgs,
...
}:
let
startKrdp = pkgs.writeShellScript "krdp-start" ''
set -eu
dir=$HOME/.config/komorebi-vm
# krdpserver refuses to run without a TLS certificate and key (its --help promises a temporary
# one, but it only checks that the files exist), so make a throwaway self-signed pair
if [ ! -f "$dir/rdp.crt" ] || [ ! -f "$dir/rdp.key" ]; then
${pkgs.openssl}/bin/openssl req -x509 -newkey rsa:2048 -nodes -days 3650 -subj /CN=komorebi-vm \
-addext subjectAltName=DNS:localhost,IP:127.0.0.1 -keyout "$dir/rdp.key" -out "$dir/rdp.crt"
chmod 600 "$dir/rdp.key"
fi
# --plasma asks KWin for the screen and for input directly, with no portal prompt to click
exec ${pkgs.kdePackages.krdp}/bin/krdpserver --plasma --address 0.0.0.0 --port 3389 \
--certificate "$dir/rdp.crt" --certificate-key "$dir/rdp.key" \
--username "$USER" --password "$(cat "$dir/rdp-password")"
'';
in
{
options.komorebi.krdp.enable = lib.mkEnableOption "KRDP, an RDP server, in every Plasma session";
config = lib.mkIf config.komorebi.krdp.enable {
environment.systemPackages = [
pkgs.kdePackages.krdp
# A client, to try the server from inside the guest. FreeRDP decodes H.264 with OpenH264
# when it is built with it, and OpenH264 shows nothing of the video KRDP sends; without it,
# FreeRDP decodes with FFmpeg (the VM suite `rdp`, docs/dev/PLATFORM.md).
(pkgs.freerdp.override { openh264 = null; })
];
# krdp streams the screen through pipewire
services.pipewire = {
enable = true;
wireplumber.enable = true;
};
security.rtkit.enable = true;
networking.firewall.allowedTCPPorts = [ 3389 ];
systemd.user.services.krdp = {
description = "RDP into this Plasma session";
wantedBy = [ "plasma-workspace.target" ];
after = [ "plasma-core.target" ];
# with no password the unit is skipped, not failed: `systemctl --user start krdp` once the
# file is there
unitConfig.ConditionPathExists = "%h/.config/komorebi-vm/rdp-password";
serviceConfig = {
ExecStart = startKrdp;
Restart = "on-failure";
RestartSec = 3;
};
};
};
}