1{ 2 config, 3 lib, 4 pkgs, 5 options, 6 ... 7}: 8 9let 10 cfg = config.services.prometheus.exporters.pve; 11 inherit (lib) 12 mkOption 13 types 14 mkPackageOption 15 optionalString 16 optionalAttrs 17 ; 18 19 # pve exporter requires a config file so create an empty one if configFile is not provided 20 emptyConfigFile = pkgs.writeTextFile { 21 name = "pve.yml"; 22 text = "default:"; 23 }; 24 25 computedConfigFile = if cfg.configFile == null then emptyConfigFile else cfg.configFile; 26in 27{ 28 port = 9221; 29 extraOpts = { 30 package = mkPackageOption pkgs "prometheus-pve-exporter" { }; 31 32 environmentFile = mkOption { 33 type = with types; nullOr path; 34 default = null; 35 example = "/etc/prometheus-pve-exporter/pve.env"; 36 description = '' 37 Path to the service's environment file. This path can either be a computed path in /nix/store or a path in the local filesystem. 38 39 The environment file should NOT be stored in /nix/store as it contains passwords and/or keys in plain text. 40 41 Environment reference: <https://github.com/prometheus-pve/prometheus-pve-exporter#authentication> 42 ''; 43 }; 44 45 configFile = mkOption { 46 type = with types; nullOr path; 47 default = null; 48 example = "/etc/prometheus-pve-exporter/pve.yml"; 49 description = '' 50 Path to the service's config file. This path can either be a computed path in /nix/store or a path in the local filesystem. 51 52 The config file should NOT be stored in /nix/store as it will contain passwords and/or keys in plain text. 53 54 If both configFile and environmentFile are provided, the configFile option will be ignored. 55 56 Configuration reference: <https://github.com/prometheus-pve/prometheus-pve-exporter/#authentication> 57 ''; 58 }; 59 60 server = { 61 keyFile = mkOption { 62 type = with types; nullOr path; 63 default = null; 64 example = "/var/lib/prometheus-pve-exporter/privkey.key"; 65 description = '' 66 Path to a SSL private key file for the server 67 ''; 68 }; 69 70 certFile = mkOption { 71 type = with types; nullOr path; 72 default = null; 73 example = "/var/lib/prometheus-pve-exporter/full-chain.pem"; 74 description = '' 75 Path to a SSL certificate file for the server 76 ''; 77 }; 78 }; 79 80 collectors = { 81 status = mkOption { 82 type = types.bool; 83 default = true; 84 description = '' 85 Collect Node/VM/CT status 86 ''; 87 }; 88 version = mkOption { 89 type = types.bool; 90 default = true; 91 description = '' 92 Collect PVE version info 93 ''; 94 }; 95 node = mkOption { 96 type = types.bool; 97 default = true; 98 description = '' 99 Collect PVE node info 100 ''; 101 }; 102 cluster = mkOption { 103 type = types.bool; 104 default = true; 105 description = '' 106 Collect PVE cluster info 107 ''; 108 }; 109 resources = mkOption { 110 type = types.bool; 111 default = true; 112 description = '' 113 Collect PVE resources info 114 ''; 115 }; 116 config = mkOption { 117 type = types.bool; 118 default = true; 119 description = '' 120 Collect PVE onboot status 121 ''; 122 }; 123 replication = mkOption { 124 type = types.bool; 125 default = true; 126 description = '' 127 Collect PVE replication info 128 ''; 129 }; 130 }; 131 }; 132 serviceOpts = { 133 serviceConfig = { 134 DynamicUser = cfg.environmentFile == null; 135 LoadCredential = "configFile:${computedConfigFile}"; 136 ExecStart = '' 137 ${cfg.package}/bin/pve_exporter \ 138 --${optionalString (!cfg.collectors.status) "no-"}collector.status \ 139 --${optionalString (!cfg.collectors.version) "no-"}collector.version \ 140 --${optionalString (!cfg.collectors.node) "no-"}collector.node \ 141 --${optionalString (!cfg.collectors.cluster) "no-"}collector.cluster \ 142 --${optionalString (!cfg.collectors.resources) "no-"}collector.resources \ 143 --${optionalString (!cfg.collectors.config) "no-"}collector.config \ 144 --${optionalString (!cfg.collectors.replication) "no-"}collector.replication \ 145 ${optionalString (cfg.server.keyFile != null) "--server.keyfile ${cfg.server.keyFile}"} \ 146 ${optionalString (cfg.server.certFile != null) "--server.certfile ${cfg.server.certFile}"} \ 147 --config.file %d/configFile \ 148 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} 149 ''; 150 } 151 // optionalAttrs (cfg.environmentFile != null) { 152 EnvironmentFile = cfg.environmentFile; 153 }; 154 }; 155}