Something went wrong. Try again.
An SNMP manager library and command line tools for Zig, covering versions 1, 2c and 3.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT
{ description = "zig-snmp";
inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # Not the `zon2nix` in nixpkgs, which is Jari Vetoniemi's original and # takes different options. zon2nix = { url = "github:jcollie/zon2nix"; inputs = { nixpkgs.follows = "nixpkgs"; }; }; };
outputs = { nixpkgs, zon2nix, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; forAllSystems = lib.genAttrs lib.systems.flakeExposed; # The virtual machine tests are NixOS ones, so they exist only where # NixOS does. Without this `nix flake check` tries to evaluate them for # Darwin and fails before it has run anything. forLinuxSystems = lib.genAttrs ( lib.filter (system: lib.hasSuffix "-linux" system) lib.systems.flakeExposed ); in { packages = forAllSystems ( system: let pkgs = makePackages system; in rec { zig-snmp = pkgs.callPackage ./package.nix { }; default = zig-snmp; # The Zig dependencies on their own, so that a workflow job can # build something other than the package -- the documentation -- # without a network the sandbox does not have. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; } );
# The virtual machine tests, which are here rather than in `zig build # test` because what they test cannot be reached from a test binary: the # NixOS module's own snmpd, and a trap receiver on port 162, which needs # privilege. `nix flake check` is what runs them, by hand and in the # workflow alike -- the ephemeral runners can boot a guest. # # Most of the oracle work is *not* here: snmpd runs perfectly well as an # unprivileged process on a loopback high port, so `tests/oracle.zig` # drives a real agent from an ordinary test and only what genuinely # needs a machine is left for this. checks = forLinuxSystems ( system: let pkgs = makePackages system; zig-snmp = pkgs.callPackage ./package.nix { }; test = file: pkgs.testers.runNixOSTest (import file { inherit zig-snmp; }); in { inherit zig-snmp; netsnmp = test ./tests/nixos/netsnmp.nix; } );
devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-snmp"; nativeBuildInputs = [ pkgs.zig_0_17 pkgs.git-pages-cli pkgs.pinact pkgs.reuse
# The other implementation to test against: `snmpget` and # friends for asking a real agent, and `snmpd` for being one. # `tests/oracle.zig` spawns it on a loopback high port, which # needs no privilege. pkgs.net-snmp
# Regenerates `build.zig.zon.nix`, which is what lets a Nix # build with no network fetch what `build.zig.zon` names. It # shells out to `zig env`, so it is wrapped with the Zig this # project builds with rather than whatever is on the caller's # PATH -- without one it prints "unable to execute zig" and # leaves the previous file in place looking untouched. (pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ pkgs.zig_0_17 ]} ''; }) ]; }; } ); };}