1 { pkgs, config, lib, ... }:
4 cfg = config.services.snmpd;
5 configFile = if cfg.configText != "" then
6 pkgs.writeText "snmpd.cfg" ''
10 options.services.snmpd = {
11 enable = lib.mkEnableOption "snmpd";
13 package = lib.mkPackageOption pkgs "net-snmp" {};
15 listenAddress = lib.mkOption {
19 The address to listen on for SNMP and AgentX messages.
21 example = "127.0.0.1";
25 type = lib.types.port;
28 The port to listen on for SNMP and AgentX messages.
32 openFirewall = lib.mkOption {
33 type = lib.types.bool;
36 Open port in firewall for snmpd.
40 configText = lib.mkOption {
41 type = lib.types.lines;
44 The contents of the snmpd.conf. If the {option}`configFile` option
45 is set, this value will be ignored.
47 Note that the contents of this option will be added to the Nix
48 store as world-readable plain text, {option}`configFile` can be used in
49 addition to a secret management tool to protect sensitive data.
53 configFile = lib.mkOption {
54 type = lib.types.path;
56 defaultText = lib.literalMD "The value of {option}`configText`.";
58 Path to the snmpd.conf file. By default, if {option}`configText` is set,
59 a config file will be automatically generated.
65 config = lib.mkIf cfg.enable {
66 systemd.services."snmpd" = {
67 description = "Simple Network Management Protocol (SNMP) daemon.";
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
72 ExecStart = "${lib.getExe' cfg.package "snmpd"} -f -Lo -c ${cfg.configFile} ${cfg.listenAddress}:${toString cfg.port}";
76 networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [
81 meta.maintainers = [ lib.maintainers.eliandoran ];