# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "A Sendspin client for Zig"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; }; zon2nix = { url = "github:jcollie/zon2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; # A Music Assistant to be a player of, in the virtual machine tests: its # client and the helper that sets a server up, and the music to play. zig-musicassistant = { url = "git+https://git.jcollie.dev/jeff/zig-musicassistant.git"; inputs.nixpkgs.follows = "nixpkgs"; inputs.zon2nix.follows = "zon2nix"; inputs.nixos-stable.follows = "nixos-stable"; inputs.nixos-unstable.follows = "nixos-unstable"; }; # The two NixOS releases whose Music Assistant the tests run against: # between them, the aiosendspin before sealed connections and the one # after. nixos-stable = { url = "https://channels.nixos.org/nixos-26.05/nixexprs.tar.xz"; }; nixos-unstable = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # The Sendspin conformance harness, the sendspin-go, sendspin-cpp, # sendspin-rs, sendspin-js, sendspin-dotnet and sendspin-jvm whose # adapters it builds, and sendspin-cli for the audio fixture: see # tests/nixos/conformance-harness.nix. conformance = { url = "github:Sendspin/conformance"; flake = false; }; sendspin-go = { url = "github:Sendspin/sendspin-go"; flake = false; }; sendspin-cli = { url = "github:Sendspin/sendspin-cli"; flake = false; }; sendspin-cpp = { url = "github:Sendspin/sendspin-cpp"; flake = false; }; sendspin-rs = { url = "github:Sendspin/sendspin-rs"; flake = false; }; sendspin-js = { url = "github:Sendspin/sendspin-js"; flake = false; }; # The 9.x line, which the harness's adapter is written for: 10.0, on # main but not yet released, replaced the API it calls. sendspin-dotnet = { url = "github:Sendspin/sendspin-dotnet/v9.3.3"; flake = false; }; sendspin-jvm = { url = "github:Sendspin/sendspin-jvm"; flake = false; }; }; outputs = { self, nixpkgs, zon2nix, zig-musicassistant, nixos-stable, nixos-unstable, conformance, sendspin-go, sendspin-cli, sendspin-cpp, sendspin-rs, sendspin-js, sendspin-dotnet, sendspin-jvm, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; conformanceHarness = pkgs: pkgs.callPackage ./tests/nixos/conformance-harness.nix { zig-sendspin = pkgs.callPackage ./package.nix { }; inherit conformance sendspin-go sendspin-cli sendspin-cpp sendspin-rs sendspin-js sendspin-dotnet sendspin-jvm ; }; forAllSystems = lib.genAttrs lib.systems.flakeExposed; # zon2nix shells out to `zig env`, and without a Zig on PATH it prints # "unable to execute zig, is it in your PATH?" and stops having written # nothing -- which leaves the previous build.zig.zon.nix in place looking # untouched rather than obviously broken. Wrap it so the Zig it finds is # this project's. wrappedZon2nix = pkgs: pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${pkgs.stdenv.hostPlatform.system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ pkgs.zig_0_17 ]} ''; }; in { devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-sendspin"; nativeBuildInputs = [ (wrappedZon2nix pkgs) pkgs.git-pages-cli pkgs.pinact pkgs.reuse pkgs.zig_0_17 ]; }; } ); packages = forAllSystems ( system: let pkgs = makePackages system; in rec { zig-sendspin = pkgs.callPackage ./package.nix { }; default = zig-sendspin; # The Zig dependency farm on its own, so a job that runs `zig build` # for something other than the package -- the documentation, say -- # can hand it straight to `--system`. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; } # The conformance matrix, to run by hand without a virtual machine: # `nix run .#conformance-harness -- --results-dir results`. // lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { conformance-harness = conformanceHarness pkgs; } ); # The package, whose build runs the unit tests, on every system; and on # Linux this library as a player of a real Music Assistant, once for # each NixOS release above: sealed against the one whose aiosendspin # seals, and falling back to unsealed against the one before. checks = forAllSystems ( system: let pkgs = makePackages system; probe = pkgs.callPackage ./package.nix { }; test = nixos: sealed: (import nixos { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/sendspin.nix { inherit probe sealed; ma-integration = zig-musicassistant.packages.${system}.default; music = zig-musicassistant.packages.${system}.test-music; inherit (zig-musicassistant.lib) testHelpers; } ); in { zig-sendspin = probe; } // lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { music-assistant-stable = test nixos-stable false; music-assistant-unstable = test nixos-unstable true; # aiosendspin's own server pairing with the probe: the unstable # release, whose aiosendspin (9.1) pairs. pairing = (import nixos-unstable { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/pairing.nix { inherit probe; } ); # aiosendspin's own client pairing with zig-sendspin's server. pair-server = (import nixos-unstable { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/pair-server.nix { zig-sendspin = probe; } ); # Finding players and servers by mDNS: through Avahi, and without # it, against aiosendspin's own server and listening client. discovery = (import nixos-unstable { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/discovery.nix { zig-sendspin = probe; } ); # The Sendspin conformance matrix, with zig-sendspin as client and server. conformance = pkgs.testers.runNixOSTest ( import ./tests/nixos/conformance.nix { harness = conformanceHarness pkgs; } ); } ); formatter = forAllSystems (system: (makePackages system).nixfmt-tree); }; }