THE CI GAP. `nix flake check` does not check `nixosModules`. It forces the value
and asserts it is a lambda taking an open attribute set — nothing more; nix's own
source carries `// FIXME: if we have a 'nixpkgs' input, use it to check the
module.` Measured: a flake whose module sets a nonexistent OPTION, references a
nonexistent `pkgs` attribute AND calls a nonexistent `lib` function passes clean,
printing `checking NixOS module 'nixosModules.default'... all checks passed!`.
nix.yml's header claimed that leg covered the module; it never did, for the
module's whole life — on a flake whose history is Nix regressions reaching main
invisibly.
Closed with `checks.<system>.nixos-module` (packaging/nix/module-check.nix): it
evaluates the module against real nixpkgs in four scenarios (desktop, appliance,
native-only, client-only) and asserts on the rendered systemd units. The
assertions are PURE NIX so instantiating the check runs them — which means the
eval-only `--no-build` leg CI already runs is sufficient, and no Rust is built.
Stub fake-derivation packages keep it independent of punktfunk-host/-client and
the from-source gamescope; crane and bun2nix are provably not needed (they are
`throw`s in the wiring test and it still instantiates).
17 checks, including regression guards for every divergence the sweep found and
for the KWin identification trap (host ExecStart must stay on the plain store
path, never a capability wrapper, while the encode worker points AT the wrapper).
Mutation-tested: 8 mutants, each re-introducing one real defect, all 8 rejected,
baseline green. The suite already earned it once — its first run failed a correct
module because systemd renders `After=` as one space-separated line, so those
assertions now read the evaluated lists instead of the text.
Also closed from the sweep:
* services.punktfunk.host.desktopSession (new, default false) — binds the host
to graphical-session.target, the declarative form of the
punktfunk-host-desktop-session.conf drop-in. Without it a Plasma/GNOME
restart leaves the host holding a Wayland socket and portal D-Bus connection
that died with the old compositor: it still listens, still answers, and every
session it then serves fails at capture. Off by default because an appliance
may never reach that target and would be left permanently stopped.
* scripting.autoStart now defaults ON, matching the deb postinst and RPM %post,
which both `systemctl --global enable` the runner. It was opt-in here on the
reasoning that the runner is inert until you add automation — which stopped
being true when the game-library scanners became plugins. A NixOS host came up
with an empty library and no obvious reason why. The module and README carried
the superseded rationale verbatim; both updated.
* A warning when the host is enabled and xdg.portal is not. A warning rather
than `xdg.portal.enable = mkDefault true`, because enabling the portal service
with no `extraPortals` backend is its own broken state and only the operator
knows which backend their compositor needs.
* punktfunk-gamescope gets a `build-gamescope` dispatch input. It is on the
critical path of every host build (`gamescopeHdr` defaults true) yet nothing
compiled it; it tracks nixpkgs' gamescope, so a flake.lock bump — not a change
of ours — is what breaks it, and the first to find out would be an operator
whose system rebuild fails.
All .nix files reformatted with the flake's own declared formatter
(nixfmt-rfc-style from the PINNED nixpkgs, not a channel's).
punktfunk on NixOS / Nix
First-class Nix support via the repo's flake.nix: reproducible builds of the streaming host
and the native Linux client, a NixOS module that wires up everything the RPM/deb do
(systemd user service, udev rules, kernel modules, sysctl tuning, firewall, input group), and a
dev shell with the pinned toolchain and every system library.
Platform:
x86_64-linuxonly (the host encodes with desktop NVENC; matches the RPM'sExclusiveArch: x86_64). NixOS 24.11 or newer for thehardware.graphicsoption.
What the flake provides
| Output | Contents |
|---|---|
packages.x86_64-linux.punktfunk-host |
punktfunk-host + punktfunk-tray (built with nvenc + vulkan-encode, like CI) |
packages.x86_64-linux.punktfunk-client |
punktfunk-client (GTK4 shell) + punktfunk-session (Vulkan streamer, without the Skia OSD — see caveats) |
packages.x86_64-linux.punktfunk-web |
the management web console (bun-built Nitro SSR bundle; SPAKE2 pairing + host status) |
packages.x86_64-linux.punktfunk-scripting |
the plugin/script runner (bun-bundled Effect SDK; supervises host automation) |
packages.x86_64-linux.default |
= punktfunk-host |
nixosModules.default |
services.punktfunk.host / .client / .web / .scripting |
devShells.x86_64-linux.default |
pinned Rust (from rust-toolchain.toml) + all build deps |
checks.x86_64-linux.nixos-module |
evaluates the NixOS module against real nixpkgs and asserts on the rendered systemd units |
apps / checks / formatter |
nix run, nix flake check, nix fmt |
One binary per GPU vendor: NVENC/CUDA entry points are dlopen'd at runtime, so the host runs on
NVIDIA (zero-copy dmabuf → CUDA → NVENC), AMD/Intel (raw Vulkan-Video HEVC / VAAPI), or software.
Quick start (no NixOS required)
# Build
nix build git+https://git.unom.io/unom/punktfunk#punktfunk-host
nix build git+https://git.unom.io/unom/punktfunk#punktfunk-client
# Run
nix run git+https://git.unom.io/unom/punktfunk#punktfunk-host -- serve --gamestream
nix run git+https://git.unom.io/unom/punktfunk#punktfunk-client
GPU drivers are resolved at runtime from /run/opengl-driver/lib. On non-NixOS distros use
nixGL so that path is populated (nixGL nix run …); on
NixOS the module (below) sets hardware.graphics.enable = true for you.
NixOS module
Add the flake and enable the host and/or client:
{
inputs.punktfunk.url = "git+https://git.unom.io/unom/punktfunk";
# (optional) share your nixpkgs: inputs.punktfunk.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, nixpkgs, punktfunk, ... }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
punktfunk.nixosModules.default
({ ... }: {
services.punktfunk.host = {
enable = true;
users = [ "alice" ]; # → added to the `input` group for virtual gamepads
openFirewall = true; # native + GameStream ports
settings = {
PUNKTFUNK_VIDEO_SOURCE = "virtual";
RUST_LOG = "info";
# PUNKTFUNK_444 = true; # booleans render as 1/0
};
};
# …and/or the client on the same or another box:
services.punktfunk.client = {
enable = true;
openFirewall = true; # UDP 5353 for mDNS discovery
};
})
];
};
};
}
Then, in your graphical session:
systemctl --user enable --now punktfunk-host
Options
services.punktfunk.host:
| Option | Default | Meaning |
|---|---|---|
enable |
false |
Install the host + wire udev/sysctl/kernel-modules/firewall and the user service. |
gamestream |
true |
serve --gamestream (Moonlight-compatible). false = native-only, more secure. |
autoStart |
false |
Add the user service to default.target (appliance mode — pair with lingering). |
desktopSession |
false |
Bind the host to graphical-session.target — turn this on for a machine somebody logs into (see below). |
users |
[ ] |
Users added to the input group (virtual gamepads). |
settings |
{ } |
host.env key/values (see ${package}/share/punktfunk-host/host.env.example). |
environmentFile |
null |
Extra EnvironmentFile for secrets (e.g. PUNKTFUNK_MGMT_TOKEN); loaded optionally. |
openFirewall |
false |
Open the inbound ports (see below). |
package |
flake's | Override the package. |
desktopSession — set it on a desktop, leave it off on an appliance. On a machine somebody logs
into, a compositor restart (a crash, a logout/login, "restart the shell") otherwise leaves the host
running while it holds a Wayland socket and a portal D-Bus connection that both died with the old
compositor. It cannot recover either in-process, and the failure is silent: the host still
listens, still answers, and every session it then serves fails at capture. desktopSession = true
adds PartOf=/WantedBy=graphical-session.target (in addition to default.target), so the host
restarts with the session. Leave it false for an appliance — a pinned PUNKTFUNK_COMPOSITOR, a
headless KWin or a gamescope box — which may never reach that target and would be left permanently
stopped. sway/Hyprland and anything else not under systemd session management never reach it
either; there, start the host from the compositor's config after systemctl --user import-environment.
Portals. The host reaches the desktop through xdg-desktop-portal on several backends (Mutter's
ScreenCast/RemoteDesktop, and the libei input path), so a hand-assembled machine wants
xdg.portal.enable = true plus the backend for its compositor
(xdg-desktop-portal-kde / -gnome / -hyprland / -wlr). The KDE and GNOME desktop-manager
modules already do this. The module emits a warning if the host is enabled and portals are not —
the KWin backend's own virtual output uses the privileged zkde_screencast protocol and needs no
portal, so KDE-only setups are unaffected in practice.
services.punktfunk.client: enable, openFirewall (UDP 5353), package.
services.punktfunk.web (the management console — on by default whenever the host is enabled,
mirroring the RPM's Recommends: punktfunk-web):
| Option | Default | Meaning |
|---|---|---|
enable |
host.enable |
Run the console as a systemd --user service on TCP 47992 (HTTPS). Set false for a console-less host. |
openFirewall |
host.openFirewall |
Open TCP 47992 so other devices on the LAN can reach it. |
autoStart |
host.autoStart |
Add the console user service to default.target (appliance mode). |
package |
flake's | Override the package. |
The console is auto-wired to the host on the same box: it reads the host's per-user
~/.config/punktfunk/{mgmt-token,cert.pem,key.pem} (written by serve), serves HTTPS with the
host's own identity cert, and proxies the loopback mgmt API with the bearer token injected
server-side (never sent to the browser). A login password is generated on first start — read it
with journalctl --user -u punktfunk-web-init (or ~/.config/punktfunk/web-password). Then open
https://<host-ip>:47992 and trust the self-signed host cert once. Enable it (with the host) via
systemctl --user enable --now punktfunk-web.
services.punktfunk.scripting (the plugin/script runner — installed and started with the host,
matching the deb/rpm, which systemctl --global enable it):
| Option | Default | Meaning |
|---|---|---|
enable |
host.enable |
Install the runner + define its systemd --user unit punktfunk-scripting. |
autoStart |
scripting.enable |
Add the unit to default.target. On by default — the game-library scanners are plugins, so a host without the runner has an empty library. |
package |
flake's | Override the package. |
The runner discovers loose scripts under ~/.config/punktfunk/scripts and installed
punktfunk-plugin-* packages under ~/.config/punktfunk/plugins, and supervises each as an Effect
fiber (SIGTERM shuts the tree down structurally so plugin finalizers run). A plugin auto-wires to
the host's mgmt token + identity cert.
It used to ship un-started here, on the reasoning that the runner is inert until you add
automation. That stopped being true when the library scanners became plugins — a host with the
runner off comes up with an empty library and no obvious reason why — so it now runs by default,
as it already did on every other channel. Opt out with scripting.autoStart = false, or per user
systemctl --user mask punktfunk-scripting (mask, not disable).
The runner is sandboxed exactly as the deb/rpm unit is (NoNewPrivileges, ProtectSystem=strict,
ReadWritePaths=%h /tmp, RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6) — with PrivateTmp
deliberately off, because plugins integrate with things that talk over /tmp. ProtectSystem
on a user unit needs unprivileged user namespaces; drop it with
systemctl --user edit punktfunk-scripting on a kernel that restricts them.
What the host module configures for you
Everything the RPM's %install + %post do, declaratively:
- systemd
--userservicepunktfunk-host→serve [--gamestream],EnvironmentFilefromsettings(+ optional secret file),Restart=on-failure. - udev rules (
60-punktfunk.rules):/dev/uinput+/dev/uhidgroup access and the vhci sysfs perms for the virtual Steam Deck. - kernel modules:
uinput,uhid,vhci-hcd(usbip transport so Steam Input adopts the virtual Deck). - sysctl:
net.core.{r,w}mem_max = 32 MB(high-bitrate UDP headroom;mkDefault). inputgroup membership forusers.hardware.graphics.enable = true(mkDefault) so/run/opengl-driver/libhas the driver libs the binariesdlopen.- firewall (when
openFirewall): native UDP 9777/5353 + TCP 47990; withgamestreamalso TCP 47984/47989/48010 + UDP 47998/47999/48000. The media data plane is an ephemeral, hole-punched UDP port — nothing fixed to open. - tray autostart entry (
--autostart; self-gates to users who actually run a host).
GPU drivers (out of scope of the module — set these yourself)
- NVIDIA:
hardware.nvidia+hardware.graphics.enable = true. NVENC/CUDA come from the driver at runtime (nothing pinned in the closure). - AMD/Intel:
hardware.graphics.enable = truewithextraPackages = [ vaapiVdpau … ]/intel-media-driverfor VAAPI encode; the host's raw Vulkan-Video HEVC path needs only Mesa.
Headless / appliance
Set autoStart = true, enable lingering, and — for a dedicated single-session appliance —
pin a backend in settings (pinning PUNKTFUNK_COMPOSITOR disables live-session auto-detection,
so leave it out on any box that switches between a desktop and Game Mode):
services.punktfunk.host = {
enable = true;
autoStart = true;
users = [ "streamer" ];
settings = { PUNKTFUNK_COMPOSITOR = "gamescope"; }; # appliance-only; omit to auto-detect
};
users.users.streamer.linger = true;
# For the gamescope/KWin backends extend the service PATH, e.g.:
# systemd.user.services.punktfunk-host.path = [ pkgs.gamescope ];
The ${package}/share/punktfunk-host/headless/ helpers (KDE/Sway session scripts, example
host.env files, the OpenAPI doc) are installed for reference.
Development
nix develop # pinned toolchain (rust-toolchain.toml) + all system libs
cargo build --release -p punktfunk-host -p punktfunk-client-linux -p punktfunk-client-session
# The tray gets its OWN invocation — co-building it with the host unifies the host's
# ashpd -> zbus/tokio onto the tray's zbus (which runs ksni's async-io executor, no tokio runtime),
# and the resulting binary panics at launch: "there is no reactor running, must be called from the
# context of a Tokio 1.x runtime". Same split the .deb / RPM / Arch packaging does.
cargo build --release -p punktfunk-tray
The shell exports an
LD_LIBRARY_PATH that includes /run/opengl-driver/lib so cargo run finds the GPU driver.
nix fmt formats the .nix files.
Notes & caveats
-
Build tool: crane. The lockfile carries
windows 0.62.2from both crates.io and a pinnedmicrosoft/windows-rsgit rev (the Windows client), whichrustPlatform.importCargoLockcan't vendor (collidingname-version); crane vendors per-source and fetches the git rev viabuiltins.fetchGit(no output hash to maintain). Those crates arecfg(windows)-gated — vendored, never compiled on Linux. -
First build compiles from scratch (no split dep cache — pyrowave-sys builds a CMake tree in its build.rs that a crane "dummy" source would drop) and has no public binary cache, so expect a long initial build.
nix developgives incremental rebuilds. -
The status tray is built in its own derivation, on purpose.
punktfunk-trayusesksni'sasync-iozbus executor with no tokio runtime (by design — seecrates/punktfunk-tray/Cargo.toml). Cargo unifies features across everything in onecargo build, so co-building the tray with the host would pull the host'sashpd → zbus/tokioonto the tray's sharedzbus, and the tray then panics at startup (there is no reactor running, must be called from the context of a Tokio 1.x runtime). Building it as a separate-p punktfunk-trayinvocation keeps itszbuson async-io; the host package copies the resulting binary into its$out. (The rpm/arch builds split it the same way. The .deb did not, despite its sibling comments claiming otherwise:deb.ymlco-built-p punktfunk-host -p punktfunk-tray, andbuild-deb.sh's own standalone build was skipped because the poisoned artifact already existed — so this shipped as a real crash-at-launch on Debian/Ubuntu, not a latent one. Fixed 2026-07-27: the workflow no longer co-builds it andbuild-deb.shnow rebuilds it unconditionally.) -
The bun packages (
punktfunk-web,punktfunk-scripting) use bun2nix. Theirnode_modulesis fetched onefetchurlper package, straight from the integrity hashes already in the lockfile, via a generated-and-committedbun.nix(web/bun.nix,sdk/bun.nix). There is no aggregate deps hash to bump — the previous design putbun installin a fixed-output derivation whose singleoutputHashsilently went stale on every lockfile change and broke the build.bun2nixis a devDependency of both packages and regeneratesbun.nixon everybun install(web'spostinstall; the SDK'sprepare, since sdk/ is the published@punktfunk/hostpackage and apostinstallwould then fire on consumers' installs). The@unomscope needs no special handling:web/bun.lockrecords those tarballs' fullhttps://git.unom.io/api/packages/unom/npm/…URLs and the registry is read-public (the same anonymous pull CI's rpm/deb builds do).⚠⚠ That devDependency hook is a convenience, NOT the guarantee —
bun.nixstill drifts. It fires only on a localbun installthat runs lifecycle scripts. It does not fire underbun install --ignore-scripts, which is what every bun install in CI uses; and it cannot fire on a merge or rebase, where git carries someone else'sbun.lockchange past abun.nixgenerated before it and reports no conflict. That is howweb/bun.nixshipped on main holdingbrace-expansion@5.0.7whileweb/bun.locksaid5.0.8— for 553 commits (2026-07-27 → 2026-08-05), withnix build .#punktfunk-webbroken the whole time, until an unrelated advisory bump happened to rerun a realbun installand closed it by accident.The enforcement point is
scripts/ci/check-bun-nix.sh(thebun-nixjob inci.yml, unfiltered so it sees the innocuous-looking commits drift arrives through). It regenerates eachbun.nixfrom its committedbun.lockand diffs. Fix any report with:scripts/ci/check-bun-nix.sh --fixNever regenerate with a bare
bunx bun2nix:bun.nixhas no schema stability across bun2nix versions, and an unpinnedbunxuses whatever is newest. The flake input (github:nix-community/bun2nix?ref=2.1.2) and the npm devDependency inweb/package.json+sdk/package.jsonmust name the same exact version — the script checks that too, and always generates with the pinned one. Move all three together, then rerun it with--fix.Everything past the deps fetch is offline (the console's codegen + vite build; the runner's
bun build --target=bunbundle). Both launchers execpkgs.bunfrom the store — unlike the deb/rpm, which vendor a bun binary because apt/dnf have none. -
Commit
flake.lock: it pins the input revisions (nixpkgs / crane / rust-overlay / bun2nix). It is generated on first eval and checked in. -
Session Skia OSD is off under Nix.
punktfunk-session's defaultuifeature draws its on-screen stats/console overlay withskia-safe, whose build downloads a prebuilt Skia from the rust-skia releases — which Nix's network-less build sandbox forbids, and a from-source Skia build pulls the whole gn/ninja/python toolchain plus network-fetched third-party. The feature is explicitly droppable ("same streaming, stats on stdout only"), so the Nix build compiles the session with--no-default-features --features pyrowave. Everything streams; only the session binary's optional on-glass stats overlay is absent, and the GTK shell (punktfunk-client) is skia-free and fully featured. Re-adding it means teaching skia-bindings to consume a prebuilt Skia offline (a fixed-output derivation of the rust-skia tarball) or a vendored from-source Skia build — a tracked follow-up.
Verified
Both packages build, install, and run on real Nix hardware (NixOS-equivalent: CachyOS + Nix,
RTX 5070 Ti, driver 610). punktfunk-host --version and punktfunk-session run; the driver
RUNPATH (/run/opengl-driver/lib) and the GTK GApps wrapper (GSettings schemas + pixbuf loaders)
are present. Fixes discovered during that bring-up: CMAKE_POLICY_VERSION_MINIMUM=3.5 (CMake ≥ 4),
system libopus (audiopus_sys), and the session Skia note above.