mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2026-04-14 13:19:09 +02:00
feat[server]: storage migration finished
This commit is contained in:
parent
c6539ed484
commit
3422a39da5
94 changed files with 1963 additions and 1626 deletions
|
|
@ -1,65 +1,88 @@
|
|||
{ lib, pkgs, config, ... }:
|
||||
let
|
||||
inherit (config.swarselsystems) sopsFile;
|
||||
|
||||
targets = config.swarselsystems.server.restic.targets;
|
||||
in
|
||||
{
|
||||
options.swarselmodules.server.restic = lib.mkEnableOption "enable restic backups on server";
|
||||
options.swarselsystems.server.restic = {
|
||||
bucketName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
paths = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
};
|
||||
withPostgres = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
targets = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
bucketName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
repository = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
paths = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
};
|
||||
withPostgres = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.swarselmodules.server.restic {
|
||||
|
||||
sops = {
|
||||
secrets = {
|
||||
resticpw = { inherit sopsFile; };
|
||||
resticaccesskey = { inherit sopsFile; };
|
||||
resticsecretaccesskey = { inherit sopsFile; };
|
||||
};
|
||||
templates = {
|
||||
"restic-env".content = ''
|
||||
AWS_ACCESS_KEY_ID=${config.sops.placeholder.resticaccesskey}
|
||||
AWS_SECRET_ACCESS_KEY=${config.sops.placeholder.resticsecretaccesskey}
|
||||
'';
|
||||
};
|
||||
secrets =
|
||||
lib.mkMerge (lib.mapAttrsToList
|
||||
(name: _: {
|
||||
"resticpw-${name}" = { inherit sopsFile; };
|
||||
"resticaccesskey-${name}" = { inherit sopsFile; };
|
||||
"resticsecretaccesskey-${name}" = { inherit sopsFile; };
|
||||
})
|
||||
targets);
|
||||
|
||||
templates =
|
||||
lib.mkMerge (lib.mapAttrsToList
|
||||
(name: _: {
|
||||
"restic-env-${name}".content = ''
|
||||
AWS_ACCESS_KEY_ID=${config.sops.placeholder."resticaccesskey-${name}"}
|
||||
AWS_SECRET_ACCESS_KEY=${config.sops.placeholder."resticsecretaccesskey-${name}"}
|
||||
'';
|
||||
})
|
||||
targets);
|
||||
};
|
||||
|
||||
services.restic =
|
||||
let
|
||||
inherit (config.repo.secrets.local) resticRepo;
|
||||
in
|
||||
{
|
||||
backups = {
|
||||
"${config.swarselsystems.server.restic.bucketName}" = {
|
||||
environmentFile = config.sops.templates."restic-env".path;
|
||||
passwordFile = config.sops.secrets.resticpw.path;
|
||||
inherit (config.swarselsystems.server.restic) paths;
|
||||
services.restic.backups =
|
||||
lib.mapAttrs'
|
||||
(name: target:
|
||||
lib.nameValuePair target.bucketName {
|
||||
environmentFile =
|
||||
config.sops.templates."restic-env-${name}".path;
|
||||
|
||||
passwordFile =
|
||||
config.sops.secrets."resticpw-${name}".path;
|
||||
|
||||
inherit (target) paths repository;
|
||||
|
||||
pruneOpts = [
|
||||
"--keep-daily 3"
|
||||
"--keep-weekly 2"
|
||||
"--keep-monthly 3"
|
||||
"--keep-yearly 100"
|
||||
];
|
||||
|
||||
backupPrepareCommand = ''
|
||||
${pkgs.restic}/bin/restic prune
|
||||
'';
|
||||
repository = "${resticRepo}";
|
||||
|
||||
initialize = true;
|
||||
|
||||
timerConfig = {
|
||||
OnCalendar = "03:00";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
)
|
||||
targets;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue