2021-11-20 17:32:11 +01:00
|
|
|
# Configure restic backups to S3-compatible storage, in our case
|
|
|
|
# GleSYS object storage.
|
2021-09-16 20:47:25 +02:00
|
|
|
#
|
2021-11-20 17:32:11 +01:00
|
|
|
# Conventions:
|
|
|
|
# - restic's cache lives in /var/backup/restic/cache
|
|
|
|
# - repository password lives in /var/backup/restic/secret
|
|
|
|
# - object storage credentials in /var/backup/restic/glesys-key
|
2021-09-16 20:47:25 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.depot.restic;
|
2021-11-20 17:32:11 +01:00
|
|
|
description = "Restic backups to GleSYS";
|
2021-09-16 20:47:25 +02:00
|
|
|
mkStringOption = default: lib.mkOption {
|
|
|
|
inherit default;
|
2021-09-18 16:35:30 +02:00
|
|
|
type = lib.types.str;
|
2021-09-16 20:47:25 +02:00
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.depot.restic = {
|
|
|
|
enable = lib.mkEnableOption description;
|
2021-11-20 17:32:11 +01:00
|
|
|
bucketEndpoint = mkStringOption "objects.dc-sto1.glesys.net";
|
|
|
|
bucketName = mkStringOption "aged-resonance";
|
|
|
|
bucketCredentials = mkStringOption "/var/backup/restic/glesys-key";
|
|
|
|
repository = mkStringOption config.networking.hostName;
|
2021-09-16 20:47:25 +02:00
|
|
|
interval = mkStringOption "hourly";
|
|
|
|
|
|
|
|
paths = with lib; mkOption {
|
|
|
|
description = "Directories that should be backed up";
|
2021-09-18 16:35:30 +02:00
|
|
|
type = types.listOf types.str;
|
2021-09-16 20:47:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exclude = with lib; mkOption {
|
|
|
|
description = "Files that should be excluded from backups";
|
2021-09-18 16:35:30 +02:00
|
|
|
type = types.listOf types.str;
|
2021-09-16 20:47:25 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.restic = {
|
2021-11-20 17:32:11 +01:00
|
|
|
description = "Backups to GleSYS";
|
2021-09-16 20:47:25 +02:00
|
|
|
|
|
|
|
script = "${pkgs.restic}/bin/restic backup ${lib.concatStringsSep " " cfg.paths}";
|
|
|
|
|
|
|
|
environment = {
|
2021-11-20 17:32:11 +01:00
|
|
|
RESTIC_REPOSITORY = "s3:${cfg.bucketEndpoint}/${cfg.bucketName}/${cfg.repository}";
|
|
|
|
AWS_SHARED_CREDENTIALS_FILE = cfg.bucketCredentials;
|
2021-09-16 20:47:25 +02:00
|
|
|
RESTIC_PASSWORD_FILE = "/var/backup/restic/secret";
|
|
|
|
RESTIC_CACHE_DIR = "/var/backup/restic/cache";
|
|
|
|
|
|
|
|
RESTIC_EXCLUDE_FILE =
|
|
|
|
builtins.toFile "exclude-files" (lib.concatStringsSep "\n" cfg.exclude);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.restic = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
timerConfig.OnCalendar = cfg.interval;
|
|
|
|
};
|
2021-11-20 17:32:11 +01:00
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.restic ];
|
2021-09-16 20:47:25 +02:00
|
|
|
};
|
|
|
|
}
|