10 cfg = config.services.prometheus.exporters.restic;
27 repository = mkOption {
28 type = with lib.types; nullOr str;
31 URI pointing to the repository to monitor.
33 example = "sftp:backup@192.168.1.100:/backups/example";
36 repositoryFile = mkOption {
37 type = with lib.types; nullOr path;
40 Path to the file containing the URI for the repository to monitor.
44 passwordFile = mkOption {
47 File containing the password to the repository.
49 example = "/etc/nixos/restic-password";
52 environmentFile = mkOption {
53 type = with types; nullOr path;
56 File containing the credentials to access the repository, in the
57 format of an EnvironmentFile as described by systemd.exec(5)
61 refreshInterval = mkOption {
62 type = types.ints.unsigned;
65 Refresh interval for the metrics in seconds.
66 Computing the metrics is an expensive task, keep this value as high as possible.
70 rcloneOptions = mkOption {
79 Options to pass to rclone to control its behavior.
80 See <https://rclone.org/docs/#options> for
81 available options. When specifying option names, strip the
82 leading `--`. To set a flag such as
83 `--drive-use-trash`, which does not take a value,
84 set the value to the Boolean `true`.
88 rcloneConfig = mkOption {
97 Configuration for the rclone remote being used for backup.
98 See the remote's specific options under rclone's docs at
99 <https://rclone.org/docs/>. When specifying
100 option names, use the "config" name specified in the docs.
101 For example, to set `--b2-hard-delete` for a B2
102 remote, use `hard_delete = true` in the
106 Secrets set in here will be world-readable in the Nix
107 store! Consider using the {option}`rcloneConfigFile`
108 option instead to specify secret values separately. Note that
109 options set here will override those set in the config file.
114 rcloneConfigFile = mkOption {
115 type = with types; nullOr path;
118 Path to the file containing rclone configuration. This file
119 must contain configuration for the remote specified in this backup
120 set and also must be readable by root.
123 Options set in `rcloneConfig` will override those set in this
132 export RESTIC_REPOSITORY=${
133 if cfg.repositoryFile != null then
134 "$(cat $CREDENTIALS_DIRECTORY/RESTIC_REPOSITORY)"
138 export RESTIC_PASSWORD_FILE=$CREDENTIALS_DIRECTORY/RESTIC_PASSWORD_FILE
139 ${pkgs.prometheus-restic-exporter}/bin/restic-exporter.py \
140 ${concatStringsSep " \\\n " cfg.extraFlags}
143 EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
145 "RESTIC_PASSWORD_FILE:${cfg.passwordFile}"
146 ] ++ optional (cfg.repositoryFile != null) [ "RESTIC_REPOSITORY:${cfg.repositoryFile}" ];
150 rcloneRemoteName = builtins.elemAt (splitString ":" cfg.repository) 1;
151 rcloneAttrToOpt = v: "RCLONE_" + toUpper (builtins.replaceStrings [ "-" ] [ "_" ] v);
152 rcloneAttrToConf = v: "RCLONE_CONFIG_" + toUpper (rcloneRemoteName + "_" + v);
153 toRcloneVal = v: if lib.isBool v then lib.boolToString v else v;
156 LISTEN_ADDRESS = cfg.listenAddress;
157 LISTEN_PORT = toString cfg.port;
158 REFRESH_INTERVAL = toString cfg.refreshInterval;
161 name: value: nameValuePair (rcloneAttrToOpt name) (toRcloneVal value)
163 // optionalAttrs (cfg.rcloneConfigFile != null) {
164 RCLONE_CONFIG = cfg.rcloneConfigFile;
167 name: value: nameValuePair (rcloneAttrToConf name) (toRcloneVal value)