9 cfg = config.services.snmpd;
11 if cfg.configText != "" then
12 pkgs.writeText "snmpd.cfg" ''
19 options.services.snmpd = {
20 enable = lib.mkEnableOption "snmpd";
22 package = lib.mkPackageOption pkgs "net-snmp" { };
24 listenAddress = lib.mkOption {
28 The address to listen on for SNMP and AgentX messages.
30 example = "127.0.0.1";
34 type = lib.types.port;
37 The port to listen on for SNMP and AgentX messages.
41 openFirewall = lib.mkOption {
42 type = lib.types.bool;
45 Open port in firewall for snmpd.
49 configText = lib.mkOption {
50 type = lib.types.lines;
53 The contents of the snmpd.conf. If the {option}`configFile` option
54 is set, this value will be ignored.
56 Note that the contents of this option will be added to the Nix
57 store as world-readable plain text, {option}`configFile` can be used in
58 addition to a secret management tool to protect sensitive data.
62 configFile = lib.mkOption {
63 type = lib.types.path;
65 defaultText = lib.literalMD "The value of {option}`configText`.";
67 Path to the snmpd.conf file. By default, if {option}`configText` is set,
68 a config file will be automatically generated.
74 config = lib.mkIf cfg.enable {
75 systemd.services."snmpd" = {
76 description = "Simple Network Management Protocol (SNMP) daemon.";
77 after = [ "network.target" ];
78 wantedBy = [ "multi-user.target" ];
81 ExecStart = "${lib.getExe' cfg.package "snmpd"} -f -Lo -c ${cfg.configFile} ${cfg.listenAddress}:${toString cfg.port}";
85 networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [
90 meta.maintainers = [ lib.maintainers.eliandoran ];