Files
komorebi/nix/dev/krdp.nix
T
LGUG2Z 041dd35224 build(nix): the demo guest
A person who wants to see komorebi tile windows should not have to configure a
machine first. `run-kde-x86_64` and `run-kde-aarch64` are the session guest with
a demo on it: the NixOS module configures komorebi from a typed `config` (eight
workspaces, borders, animation) and the sample skhd bindings, and at login the
guest opens two Konsole windows, Kate and Dolphin, which komorebi tiles, and a
cheat sheet window that it leaves alone, with the key bindings, `komorebic`
commands to try, what KWin draws with, and the output of `komorebic check`.

The closure is the same for everyone. No password or key is in it: the host
shares a directory, which the guest mounts at /run/run-kde, and a unit copies
the RDP password and the ssh public key from it, since the files can belong to a
user of the host who is not the guest user. krdp.nix reads the password from the
file that `komorebi.krdp.passwordFile` names when it exists. The display device,
the port forwards, the memory and whether to insist on KVM are left to the
environment of the runner, so that one closure and one disk run with a software
virtio-vga or with a virtio-vga-gl that renders on the host GPU. The module is a
separate file that does not import plasma-vm.nix, so that a VM suite can put it
on the session node.

plasma-guests-eval asserts the same of the demo guests.
2026-10-28 13:27:11 -07:00

98 lines
3.8 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.
# A guest whose password comes from outside, as the demo guest's does (run-kde.nix), names a file
# of the guest in `passwordFile`, which the unit reads in place of that one when it is there.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.komorebi.krdp;
startKrdp = pkgs.writeShellScript "krdp-start" ''
set -eu
dir=$HOME/.config/komorebi-vm
password_file=$dir/rdp-password
${lib.optionalString (cfg.passwordFile != null) ''
if [ -r ${lib.escapeShellArg cfg.passwordFile} ]; then
password_file=${lib.escapeShellArg cfg.passwordFile}
fi
''}
mkdir -p "$dir"
# 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 "$password_file")"
'';
in
{
options.komorebi.krdp = {
enable = lib.mkEnableOption "KRDP, an RDP server, in every Plasma session";
passwordFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/run/run-kde-guest/rdp-password";
description = ''
The path, in the guest, of a file with the password a client logs in with. It is a path in
the running guest and not a file of the Nix store, so that no password is part of the
system. The unit reads it in place of `~/.config/komorebi-vm/rdp-password` when it exists,
and starts when either exists.
'';
};
};
config = lib.mkIf cfg.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 =
if cfg.passwordFile == null then
"%h/.config/komorebi-vm/rdp-password"
else
[
"|%h/.config/komorebi-vm/rdp-password"
"|${cfg.passwordFile}"
];
serviceConfig = {
ExecStart = startKrdp;
Restart = "on-failure";
RestartSec = 3;
};
};
};
}