# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "MPRIS for Zig: a media player on the session bus"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; }; zon2nix = { url = "github:jcollie/zon2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; # The two NixOS releases the virtual machine test runs on, for their # dbus-broker, playerctl and GLib. 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"; }; }; outputs = { self, nixpkgs, zon2nix, nixos-stable, nixos-unstable, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; 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-mpris"; nativeBuildInputs = [ (wrappedZon2nix pkgs) # A private session bus to test against, and a peer to talk to # the service with: `dbus-run-session`, and `gdbus`. pkgs.dbus pkgs.glib pkgs.playerctl pkgs.git-pages-cli pkgs.pinact pkgs.reuse pkgs.zig_0_17 ] # `zig build coverage`. ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.kcov ]; # dbus-run-session reads /etc/dbus-1/session.conf unless told # otherwise, and a CI job's container has no /etc/dbus-1: the # package's own configuration, for `--config-file`. DBUS_SESSION_CONF = "${pkgs.dbus}/share/dbus-1/session.conf"; }; } ); packages = forAllSystems ( system: let pkgs = makePackages system; in rec { zig-mpris = pkgs.callPackage ./package.nix { }; default = zig-mpris; # 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 package, whose build runs the unit tests, on every system; and on # Linux the example player on a desktop user's dbus-broker session bus, # driven by playerctl and gdbus, once for each NixOS release above. checks = forAllSystems ( system: let pkgs = makePackages system; example = pkgs.callPackage ./package.nix { }; test = nixos: (import nixos { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/broker.nix { inherit example; } ); in { zig-mpris = example; } // lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { broker-stable = test nixos-stable; broker-unstable = test nixos-unstable; } ); formatter = forAllSystems (system: (makePackages system).nixfmt-tree); }; }