2022-10-16 03:18:58 +00:00
|
|
|
{ config, pkgs, lib, ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2022-12-21 21:18:03 +00:00
|
|
|
backup.s3 = {
|
2022-10-16 03:18:58 +00:00
|
|
|
endpoint = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "S3 endpoint for backups";
|
2022-12-21 21:18:03 +00:00
|
|
|
default = null;
|
2022-10-16 03:18:58 +00:00
|
|
|
};
|
|
|
|
bucket = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "S3 bucket for backups";
|
2022-12-21 21:18:03 +00:00
|
|
|
default = null;
|
2022-10-16 03:18:58 +00:00
|
|
|
};
|
|
|
|
accessKeyId = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "S3 access key ID for backups";
|
2022-12-21 21:18:03 +00:00
|
|
|
default = null;
|
2022-10-16 03:18:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
2022-10-16 03:47:21 +00:00
|
|
|
users.groups.backup = { };
|
|
|
|
|
2022-10-16 03:18:58 +00:00
|
|
|
secrets.backup = {
|
|
|
|
source = ../../private/backup.age;
|
|
|
|
dest = "${config.secretsDirectory}/backup";
|
2022-10-16 03:47:21 +00:00
|
|
|
group = "backup";
|
|
|
|
permissions = "0440";
|
2022-10-16 03:18:58 +00:00
|
|
|
};
|
|
|
|
|
2022-10-16 19:06:56 +00:00
|
|
|
users.users.litestream.extraGroups = [ "backup" ];
|
|
|
|
|
|
|
|
services.litestream = {
|
|
|
|
enable = true;
|
|
|
|
environmentFile = config.secrets.backup.dest;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Wait for secret to exist
|
|
|
|
systemd.services.litestream = {
|
|
|
|
after = [ "backup-secret.service" ];
|
|
|
|
requires = [ "backup-secret.service" ];
|
|
|
|
environment.AWS_ACCESS_KEY_ID = config.backupS3.accessKeyId;
|
|
|
|
};
|
|
|
|
|
2022-10-16 03:18:58 +00:00
|
|
|
# # Backup library to object storage
|
|
|
|
# services.restic.backups.calibre = {
|
|
|
|
# user = "calibre-web";
|
|
|
|
# repository =
|
|
|
|
# "s3://${config.backupS3.endpoint}/${config.backupS3.bucket}/calibre";
|
|
|
|
# paths = [
|
|
|
|
# "/var/books"
|
|
|
|
# "/var/lib/calibre-web/app.db"
|
|
|
|
# "/var/lib/calibre-web/gdrive.db"
|
|
|
|
# ];
|
|
|
|
# initialize = true;
|
|
|
|
# timerConfig = { OnCalendar = "00:05:00"; };
|
|
|
|
# environmentFile = backupS3File;
|
|
|
|
# };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|