# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "mdbus"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; }; }; outputs = { self, nixpkgs, ... }: let inherit (nixpkgs) lib; linuxSystems = builtins.filter ( system: (lib.systems.elaborate system).isLinux ) lib.systems.flakeExposed; # NixOS VM tests need a machine that can run the guest, so the live-bus # check is only offered where the build machine is the guest's architecture. vmSystems = builtins.filter (system: builtins.elem system linuxSystems) [ "aarch64-linux" "x86_64-linux" ]; makePackages = system: import nixpkgs { inherit system; # nixpkgs marks radicle-node insecure because traffic for *private* # repositories is neither encrypted nor authenticated between nodes. # mdbus is public on Radicle, so that does not apply here. config.permittedInsecurePackages = [ "radicle-node-1.10.3" ]; }; forAllSystems = lib.genAttrs linuxSystems; in { packages = forAllSystems ( system: let pkgs = makePackages system; in { # The test runner as a standalone binary, so it can be built on a # machine with no session bus and executed on one that has a bus. test-runner = pkgs.stdenv.mkDerivation { pname = "mdbus-test-runner"; version = "0.2.0"; src = ./.; nativeBuildInputs = [ pkgs.zig_0_17 ]; zigBuildFlags = [ "-Dinstall-test-runner=true" ]; # The unit tests need no bus and are worth running here; the # live-bus tests skip themselves and are covered by the VM check. doCheck = true; meta = { description = "mdbus unit and live-bus test runner"; mainProgram = "mdbus-tests"; license = lib.licenses.mit; platforms = lib.platforms.linux; }; }; } ); checks = forAllSystems ( system: let pkgs = makePackages system; in lib.optionalAttrs (builtins.elem system vmSystems) { # Boot a VM whose session bus really is dbus-broker and run the whole # test suite, live-bus tests included, against it. dbus-broker = pkgs.testers.runNixOSTest { name = "mdbus-dbus-broker"; nodes.machine = { # This is already the NixOS default, but the bus implementation # is the subject of the test, so it is stated rather than assumed. services.dbus.implementation = "broker"; users.users.tester = { isNormalUser = true; uid = 1000; # Bring the user session, and with it the user bus, up at boot # so the test does not have to log in to reach a session bus. linger = true; }; environment.systemPackages = [ self.packages.${system}.test-runner ]; }; testScript = '' import re machine.wait_for_unit("multi-user.target") machine.wait_for_unit("user@1000.service") machine.wait_for_file("/run/user/1000/bus") as_tester = "su tester -c 'XDG_RUNTIME_DIR=/run/user/1000 {}'" with subtest("the session bus is dbus-broker"): # `dbus.service` is an alias, so its canonical id names the # implementation actually behind the socket. Without this the # suite could quietly pass against dbus-daemon instead. unit = machine.succeed( as_tester.format( "systemctl --user show --property=Id --value dbus.service" ) ) assert unit.strip() == "dbus-broker.service", unit with subtest("the library passes its suite against the broker"): # `MONSTAR_DBUS_INTEGRATION=1` un-skips the live-bus tests. # The runner writes its report to stderr, and reports "All N # tests passed." only when nothing failed *and* nothing # skipped, which is what makes this a real check. output = machine.succeed( as_tester.format( "MONSTAR_DBUS_INTEGRATION=1 mdbus-tests 2>&1" ) ) print(output) assert re.search(r"All \d+ tests passed\.", output), output with subtest("a dbus-broker process served that session"): machine.succeed("pgrep -u tester -x dbus-broker") ''; }; } ); devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = self.devShells.${system}.zig_0_17; zig_0_17 = pkgs.mkShell { name = "mdbus"; nativeBuildInputs = [ # Uploads zig-out/docs to https://jeff.jcollie.page/mdbus/; the # workflow's docs job runs it out of this shell. pkgs.git-pages-cli pkgs.radicle-node pkgs.reuse pkgs.zig_0_17 ]; }; } ); }; }