Files
punktfunk/flake.nix
T
enricobuehler f8cde0adaf feat(nix): actually check the NixOS module in CI, and close the sweep's open issues
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).
2026-08-10 19:57:10 +02:00

214 lines
7.5 KiB
Nix

{
description = "punktfunk — low-latency desktop/game streaming host + native Linux client";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
# The bun packages' node_modules (punktfunk-web, punktfunk-scripting): one fetchurl per package,
# straight out of `bun.lock`'s integrity hashes — no hand-maintained aggregate deps hash to bump.
# PIN THE TAG. `bun.nix` has no schema stability guarantee across bun2nix versions, so this ref
# must move together with the `bun2nix` devDependency in web/package.json + sdk/package.json
# (which regenerates the file on every `bun install`). See packaging/nix/README.md.
bun2nix = {
url = "github:nix-community/bun2nix?ref=2.1.2";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crane,
rust-overlay,
bun2nix,
}:
let
# Linux/x86_64 only — the host encodes with desktop NVENC and CI publishes no aarch64 leg
# (mirrors the RPM's `ExclusiveArch: x86_64`). Add a system here once there's an arm64 build.
systems = [ "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
# The workspace version is the single source of truth (crates/*/Cargo.toml inherit it).
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
pkgsFor =
system:
import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
# Pin cargo/rustc EXACTLY to rust-toolchain.toml (channel 1.96.0 + rustfmt/clippy) so a Nix
# build, a dev shell and CI all use the identical toolchain — the repo is deliberate about
# this (see rust-toolchain.toml's header on rustfmt format-drift).
toolchainFor = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLibFor = pkgs: (crane.mkLib pkgs).overrideToolchain toolchainFor;
packagesFor =
system:
let
pkgs = pkgsFor system;
in
pkgs.callPackage ./packaging/nix/packages.nix {
craneLib = craneLibFor pkgs;
src = self;
inherit version;
# `.hook` + `.fetchBunDeps` (bun2nix v2 API) — see packages.nix.
bun2nix = bun2nix.packages.${system}.default;
}
// {
# gamescope + our `pipewire-hdr` patches, so the gamescope backend can stream HDR.
# Kept OUT of packages.nix (a Rust/crane file) — it is a C++ meson override with a
# disjoint dependency set — and out of `checks` below, because it rebuilds gamescope
# from source and would make `nix flake check` an hour long.
punktfunk-gamescope = pkgs.callPackage ./packaging/nix/gamescope.nix {
patchDir = ./packaging/gamescope/patches;
};
};
in
{
packages = forAllSystems (
system:
let
pf = packagesFor system;
in
{
inherit (pf)
punktfunk-host
punktfunk-client
punktfunk-web
punktfunk-scripting
punktfunk-tray
punktfunk-gamescope
;
default = pf.punktfunk-host;
}
);
# `nix run .#punktfunk-host -- serve` / `nix run .#punktfunk-client`.
apps = forAllSystems (
system:
let
pf = packagesFor system;
in
{
punktfunk-host = {
type = "app";
program = "${pf.punktfunk-host}/bin/punktfunk-host";
};
punktfunk-client = {
type = "app";
program = "${pf.punktfunk-client}/bin/punktfunk-client";
};
# `nix run .#punktfunk-web` — the console (auto-wire the mgmt token / cert via env or the
# NixOS module; see packaging/nix/README.md).
punktfunk-web = {
type = "app";
program = "${pf.punktfunk-web}/bin/punktfunk-web-server";
};
# `nix run .#punktfunk-scripting -- --list` — the plugin/script runner.
punktfunk-scripting = {
type = "app";
program = "${pf.punktfunk-scripting}/bin/punktfunk-scripting";
};
default = self.apps.${system}.punktfunk-host;
}
);
# `nix flake check` builds every package.
checks = forAllSystems (
system:
let
pf = packagesFor system;
pkgs = pkgsFor system;
in
{
inherit (pf)
punktfunk-host
punktfunk-client
punktfunk-web
punktfunk-scripting
;
# The NixOS module, actually evaluated. `nix flake check` does NOT do this for
# `nixosModules` — it only forces the value and asserts it is a lambda taking an open
# attribute set, so a module with a nonexistent option, a nonexistent `pkgs` attribute
# and a nonexistent `lib` function passes clean (measured). Routing the module through a
# `checks` entry instead means the eval-only CI leg has to instantiate it, and every
# assertion in module-check.nix is pure Nix so instantiation is enough to run them.
nixos-module = pkgs.callPackage ./packaging/nix/module-check.nix {
inherit nixpkgs system;
module = import ./packaging/nix/nixos-module.nix;
};
}
);
# `nix develop` — the pinned toolchain plus every system lib the workspace links, wired so
# `cargo build` (all crates, host + client) works out of the box.
devShells = forAllSystems (
system:
let
pkgs = pkgsFor system;
toolchain = toolchainFor pkgs;
gbm = pkgs.libgbm or pkgs.mesa;
in
{
default = pkgs.mkShell {
strictDeps = false;
nativeBuildInputs = [
toolchain
pkgs.rust-analyzer
pkgs.pkg-config
pkgs.cmake
pkgs.nasm
pkgs.perl
pkgs.rustPlatform.bindgenHook
];
buildInputs = [
# host
pkgs.ffmpeg
pkgs.pipewire
pkgs.libopus
pkgs.wayland
pkgs.libxkbcommon
pkgs.libGL
gbm
pkgs.vulkan-loader
# client
pkgs.sdl3
pkgs.gtk4
pkgs.libadwaita
pkgs.glib
pkgs.librsvg
pkgs.gsettings-desktop-schemas
pkgs.adwaita-icon-theme
];
# CMake ≥ 4 rejects the pre-3.5 minimums some vendored C libs (libopus) still declare.
CMAKE_POLICY_VERSION_MINIMUM = "3.5";
LD_LIBRARY_PATH = "/run/opengl-driver/lib:${
pkgs.lib.makeLibraryPath [
pkgs.vulkan-loader
pkgs.libGL
gbm
]
}";
};
}
);
formatter = forAllSystems (system: (pkgsFor system).nixfmt-rfc-style);
# NixOS integration — see packaging/nix/nixos-module.nix and packaging/nix/README.md.
# imports = [ punktfunk.nixosModules.default ];
# services.punktfunk.host.enable = true;
nixosModules.default = import ./packaging/nix/nixos-module.nix self;
nixosModules.punktfunk = self.nixosModules.default;
};
}