1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.restic;
20 repository = mkOption {
23 URI pointing to the repository to monitor.
25 example = "sftp:backup@192.168.1.100:/backups/example";
28 passwordFile = mkOption {
31 File containing the password to the repository.
33 example = "/etc/nixos/restic-password";
36 environmentFile = mkOption {
37 type = with types; nullOr path;
40 File containing the credentials to access the repository, in the
41 format of an EnvironmentFile as described by systemd.exec(5)
45 refreshInterval = mkOption {
46 type = types.ints.unsigned;
49 Refresh interval for the metrics in seconds.
50 Computing the metrics is an expensive task, keep this value as high as possible.
54 rcloneOptions = mkOption {
55 type = with types; attrsOf (oneOf [ str bool ]);
58 Options to pass to rclone to control its behavior.
59 See <https://rclone.org/docs/#options> for
60 available options. When specifying option names, strip the
61 leading `--`. To set a flag such as
62 `--drive-use-trash`, which does not take a value,
63 set the value to the Boolean `true`.
67 rcloneConfig = mkOption {
68 type = with types; attrsOf (oneOf [ str bool ]);
71 Configuration for the rclone remote being used for backup.
72 See the remote's specific options under rclone's docs at
73 <https://rclone.org/docs/>. When specifying
74 option names, use the "config" name specified in the docs.
75 For example, to set `--b2-hard-delete` for a B2
76 remote, use `hard_delete = true` in the
80 Secrets set in here will be world-readable in the Nix
81 store! Consider using the {option}`rcloneConfigFile`
82 option instead to specify secret values separately. Note that
83 options set here will override those set in the config file.
88 rcloneConfigFile = mkOption {
89 type = with types; nullOr path;
92 Path to the file containing rclone configuration. This file
93 must contain configuration for the remote specified in this backup
94 set and also must be readable by root.
97 Options set in `rcloneConfig` will override those set in this
106 export RESTIC_PASSWORD_FILE=$CREDENTIALS_DIRECTORY/RESTIC_PASSWORD_FILE
107 ${pkgs.prometheus-restic-exporter}/bin/restic-exporter.py \
108 ${concatStringsSep " \\\n " cfg.extraFlags}
111 EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
112 LoadCredential = [ "RESTIC_PASSWORD_FILE:${cfg.passwordFile}" ];
116 rcloneRemoteName = builtins.elemAt (splitString ":" cfg.repository) 1;
117 rcloneAttrToOpt = v: "RCLONE_" + toUpper (builtins.replaceStrings [ "-" ] [ "_" ] v);
118 rcloneAttrToConf = v: "RCLONE_CONFIG_" + toUpper (rcloneRemoteName + "_" + v);
119 toRcloneVal = v: if lib.isBool v then lib.boolToString v else v;
122 RESTIC_REPOSITORY = cfg.repository;
123 LISTEN_ADDRESS = cfg.listenAddress;
124 LISTEN_PORT = toString cfg.port;
125 REFRESH_INTERVAL = toString cfg.refreshInterval;
129 nameValuePair (rcloneAttrToOpt name) (toRcloneVal value)
132 // optionalAttrs (cfg.rcloneConfigFile != null) {
133 RCLONE_CONFIG = cfg.rcloneConfigFile;
137 nameValuePair (rcloneAttrToConf name) (toRcloneVal value)