`nix build .#punktfunk-web` has been broken since1e9957d9re-resolved web/bun.lock: the console's node_modules came from a fixed-output derivation whose single aggregate `outputHash` was last refreshed in4094f620, so every lockfile change silently invalidated it and the fix required a round-trip on a Linux nix box (build, read the `got:` hash, paste it back). The runner (sdk/bun.lock) had the same latent trap. Replace both FODs with bun2nix (github:nix-community/bun2nix, pinned to 2.1.2). `fetchBunDeps` turns a generated, committed `bun.nix` into bun's global install cache — ONE `fetchurl` per package, keyed by the integrity hash already in the lockfile — and the setup hook then runs a fully offline `bun install` in `bunRoot`. There is no aggregate hash left to go stale. The `@unom` scope needs no special handling: bun.lock records those tarballs' full git.unom.io URLs and the registry is read-public. `bun.nix` keeps itself in step: `bun2nix` is now a devDependency of both packages and regenerates the file on every `bun install` — web via `postinstall`, the SDK via `prepare`, because sdk/ is the published @punktfunk/host package and a postinstall would fire on consumers' installs. Both the flake input and the npm devDependency are pinned to the same exact version; `bun.nix` has no schema stability guarantee across bun2nix releases, so they move together (README documents this). Dropped along the way: the manual `cp -R ${deps}/node_modules` + `chmod -R u+w` + `patchShebangs web/node_modules` dance, since bun2nix patches shebangs inside the cache. `dontUseBunPatch` keeps the hook from running `patchShebangs .` over the whole repo checkout (it would rewrite scripts/web-init.sh, which we ship verbatim); `dontRunLifecycleScripts` preserves the old `--ignore-scripts` behaviour, so playwright still never tries to download browsers. Verified on a Linux nix box (Determinate Nix 3.21.5): `.#punktfunk-web` and `.#punktfunk-scripting` both build green, offline; the i18n guard reports its 421 compiled messages, the `Bun.serve` bundle guard passes, and `nix run .#punktfunk-scripting -- --list` discovers an installed plugin. `nix flake show --all-systems` evaluates every output. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit 4cfe7f05ee608868857be9e7eec079044448a965)
195 lines
6.3 KiB
Nix
195 lines
6.3 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;
|
|
};
|
|
in
|
|
{
|
|
packages = forAllSystems (
|
|
system:
|
|
let
|
|
pf = packagesFor system;
|
|
in
|
|
{
|
|
inherit (pf)
|
|
punktfunk-host
|
|
punktfunk-client
|
|
punktfunk-web
|
|
punktfunk-scripting
|
|
punktfunk-tray
|
|
;
|
|
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;
|
|
in
|
|
{
|
|
inherit (pf)
|
|
punktfunk-host
|
|
punktfunk-client
|
|
punktfunk-web
|
|
punktfunk-scripting
|
|
;
|
|
}
|
|
);
|
|
|
|
# `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
|
|
pkgs.vulkan-headers
|
|
];
|
|
# pf-ffvk bindgen (no /usr/include on NixOS); GPU driver libs at runtime for `cargo run`.
|
|
PF_FFVK_VULKAN_INCLUDE = "${pkgs.vulkan-headers}/include";
|
|
# 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;
|
|
};
|
|
}
|