diff --git a/modules/blocks/ldap.nix b/modules/blocks/ldap.nix index 48f9ca8..6bee35b 100644 --- a/modules/blocks/ldap.nix +++ b/modules/blocks/ldap.nix @@ -95,7 +95,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -104,10 +104,11 @@ in ``` shb.restic.instances."lldap" = { - enable = true; - - # Options specific to Restic. - } // config.shb.lldap.backup; + request = config.shb.lldap.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/blocks/postgresql.nix b/modules/blocks/postgresql.nix index 54927da..e98cb44 100644 --- a/modules/blocks/postgresql.nix +++ b/modules/blocks/postgresql.nix @@ -60,10 +60,11 @@ in ``` shb.restic.instances."postgresql" = { - enable = true; - - # Options specific to Restic. - } // config.shb.postgresl.backup; + request = config.shb.postgresl.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/blocks/restic/docs/default.md b/modules/blocks/restic/docs/default.md index 6fb9479..44ec5cf 100644 --- a/modules/blocks/restic/docs/default.md +++ b/modules/blocks/restic/docs/default.md @@ -22,30 +22,34 @@ We assume that the folder is used by the `myservice` service and is owned by a u ```nix shb.restic.instances.myservice = { - enable = true; + request = { + user = "myservice"; - user = "myservice"; + sourceDirectories = [ + "/var/lib/myfolder" + ]; + }; - passphraseFile = ""; + settings = { + enable = true; - repositories = [{ - path = "/srv/backups/myservice"; - timerConfig = { - OnCalendar = "00:00:00"; - RandomizedDelaySec = "3h"; + passphraseFile = ""; + + repository = { + path = "/srv/backups/myservice"; + timerConfig = { + OnCalendar = "00:00:00"; + RandomizedDelaySec = "3h"; + }; }; - }]; - sourceDirectories = [ - "/var/lib/myfolder" - ]; - - retention = { - keep_within = "1d"; - keep_hourly = 24; - keep_daily = 7; - keep_weekly = 4; - keep_monthly = 6; + retention = { + keep_within = "1d"; + keep_hourly = 24; + keep_daily = 7; + keep_weekly = 4; + keep_monthly = 6; + }; }; }; ``` @@ -59,7 +63,7 @@ This assumes you have access to such a remote S3 store, for example by using [Ba ```diff shb.backup.instances.myservice = { - repositories = [{ + repository = { - path = "/srv/pool1/backups/myfolder"; + path = "s3:s3.us-west-000.backblazeb2.com/backups/myfolder"; timerConfig = { @@ -71,7 +75,7 @@ This assumes you have access to such a remote S3 store, for example by using [Ba + AWS_ACCESS_KEY_ID.source=""; + AWS_SECRET_ACCESS_KEY.source=""; + }; - }]; + }; } ``` @@ -84,15 +88,13 @@ The code to backup to Backblaze with secrets stored in Sops would look like so: ```nix shb.restic.instances.myfolder.passphraseFile = config.sops.secrets."myservice/backup/passphrase".path; -shb.restic.instances.myfolder.repositories = [ - { - path = "s3:s3.us-west-000.backblazeb2.com/"; - secrets = { - AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id".path; - AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key".path; - }; - } -]; +shb.restic.instances.myfolder.repository = { + path = "s3:s3.us-west-000.backblazeb2.com/"; + secrets = { + AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id".path; + AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key".path; + }; +}; sops.secrets."myservice/backup/passphrase" = { sopsFile = ./secrets.yaml; @@ -231,7 +233,7 @@ Discovering those is easy thanks to tab-completion. One can then restore a backup with: ```bash -restic-myfolder1_srv_pool1_backups restore latest -t / +restic-myfolder1_srv_pool1_backups restore latest ``` ### Troubleshooting {#blocks-restic-maintenance-troubleshooting} diff --git a/modules/contracts/backup/docs/default.md b/modules/contracts/backup/docs/default.md index 559f6c7..2c0650a 100644 --- a/modules/contracts/backup/docs/default.md +++ b/modules/contracts/backup/docs/default.md @@ -6,8 +6,6 @@ at a regular schedule. It is a contract between a service that has files to be backed up and a service that backs up files. -All options in this contract should be set by the former. -The latter will then use the values of those options to know what to backup. ## Contract Reference {#backup-contract-options} @@ -33,7 +31,7 @@ Here is an example module defining such a `backup` option: { options = { myservice.backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; readOnly = true; default = { user = "myservice"; diff --git a/modules/contracts/backup/dummyModule.nix b/modules/contracts/backup/dummyModule.nix index 8a7d3a8..7297a52 100644 --- a/modules/contracts/backup/dummyModule.nix +++ b/modules/contracts/backup/dummyModule.nix @@ -5,6 +5,6 @@ in { options.shb.contracts.backup = lib.mkOption { description = "Contract for backups."; - type = contracts.backup; + type = contracts.backup.request; }; } diff --git a/modules/services/arr.nix b/modules/services/arr.nix index 2f59987..ca17b31 100644 --- a/modules/services/arr.nix +++ b/modules/services/arr.nix @@ -316,7 +316,7 @@ let }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -325,10 +325,11 @@ let ``` shb.restic.instances."${name}" = { - enable = true; - - # Options specific to Restic. - } // config.shb.${name}.backup; + request = config.shb.${name}.backup; + settings = { + enable = true; + }; + } ``` ''; readOnly = true; diff --git a/modules/services/audiobookshelf.nix b/modules/services/audiobookshelf.nix index ffa06f5..46428bc 100644 --- a/modules/services/audiobookshelf.nix +++ b/modules/services/audiobookshelf.nix @@ -83,7 +83,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -92,10 +92,11 @@ in ``` shb.restic.instances."audiobookshelf" = { - enable = true; - - # Options specific to Restic. - } // config.shb.audiobookshelf.backup; + request = config.shb.audiobookshelf.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/deluge.nix b/modules/services/deluge.nix index 4244e78..e3fa12d 100644 --- a/modules/services/deluge.nix +++ b/modules/services/deluge.nix @@ -234,7 +234,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -243,10 +243,11 @@ in ``` shb.restic.instances."vaultwarden" = { - enable = true; - - # Options specific to Restic. - } // config.shb.vaultwarden.backup; + request = config.shb.vaultwarden.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/forgejo.nix b/modules/services/forgejo.nix index f78fb54..50fafb6 100644 --- a/modules/services/forgejo.nix +++ b/modules/services/forgejo.nix @@ -218,7 +218,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -227,10 +227,11 @@ in ``` shb.restic.instances."forgejo" = { - enable = true; - - # Options specific to Restic. - } // config.shb.forgejo.backup; + request = config.shb.forgejo.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/forgejo/docs/default.md b/modules/services/forgejo/docs/default.md index aa070c3..8ad3ffc 100644 --- a/modules/services/forgejo/docs/default.md +++ b/modules/services/forgejo/docs/default.md @@ -213,8 +213,11 @@ twice with a future secrets SHB block. Backing up Forgejo using the [Restic block](blocks-restic.html) is done like so: ```nix -shb.restic.instances."forgejo" = config.shb.forgejo.backup // { - enable = true; +shb.restic.instances."forgejo" = { + request = config.shb.forgejo.backup; + settings = { + enable = true; + }; }; ``` diff --git a/modules/services/grocy.nix b/modules/services/grocy.nix index 92a5908..e1dc3bb 100644 --- a/modules/services/grocy.nix +++ b/modules/services/grocy.nix @@ -63,7 +63,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -72,10 +72,11 @@ in ``` shb.restic.instances."grocy" = { - enable = true; - - # Options specific to Restic. - } // config.shb.grocy.backup; + request = config.shb.grocy.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/hledger.nix b/modules/services/hledger.nix index 3c7521d..ee4c3c9 100644 --- a/modules/services/hledger.nix +++ b/modules/services/hledger.nix @@ -55,7 +55,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -64,10 +64,11 @@ in ``` shb.restic.instances."hledger" = { - enable = true; - - # Options specific to Restic. - } // config.shb.hledger.backup; + request = config.shb.hledger.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/home-assistant.nix b/modules/services/home-assistant.nix index d2cdc98..979a845 100644 --- a/modules/services/home-assistant.nix +++ b/modules/services/home-assistant.nix @@ -137,7 +137,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -146,10 +146,11 @@ in ``` shb.restic.instances."home-assistant" = { - enable = true; - - # Options specific to Restic. - } // config.shb.home-assistant.backup; + request = config.shb.home-assistant.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/jellyfin.nix b/modules/services/jellyfin.nix index c537d17..506340c 100644 --- a/modules/services/jellyfin.nix +++ b/modules/services/jellyfin.nix @@ -139,7 +139,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -148,10 +148,11 @@ in ``` shb.restic.instances."jellyfin" = { - enable = true; - - # Options specific to Restic. - } // config.shb.jellyfin.backup; + request = config.shb.jellyfin.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/nextcloud-server.nix b/modules/services/nextcloud-server.nix index c224ca6..e662513 100644 --- a/modules/services/nextcloud-server.nix +++ b/modules/services/nextcloud-server.nix @@ -498,7 +498,7 @@ in backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -507,10 +507,11 @@ in ``` shb.restic.instances."nextcloud" = { - enable = true; - - # Options specific to Restic. - } // config.shb.nextcloud.backup; + request = config.shb.nextcloud.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/nextcloud-server/docs/default.md b/modules/services/nextcloud-server/docs/default.md index a89a84d..8422684 100644 --- a/modules/services/nextcloud-server/docs/default.md +++ b/modules/services/nextcloud-server/docs/default.md @@ -281,8 +281,11 @@ shb.nextcloud.postgresSettings = { Backing up Nextcloud using the [Restic block](blocks-restic.html) is done like so: ```nix -shb.restic.instances."nextcloud" = config.shb.nextcloud.backup // { - enable = true; +shb.restic.instances."nextcloud" = { + request = config.shb.nextcloud.backup; + settings = { + enable = true; + }; }; ``` diff --git a/modules/services/vaultwarden.nix b/modules/services/vaultwarden.nix index 32d3573..710a9e6 100644 --- a/modules/services/vaultwarden.nix +++ b/modules/services/vaultwarden.nix @@ -115,7 +115,7 @@ in }; backup = lib.mkOption { - type = contracts.backup; + type = contracts.backup.request; description = '' Backup configuration. This is an output option. @@ -124,10 +124,11 @@ in ``` shb.restic.instances."vaultwarden" = { - enable = true; - - # Options specific to Restic. - } // config.shb.vaultwarden.backup; + request = config.shb.vaultwarden.backup; + settings = { + enable = true; + }; + }; ``` ''; readOnly = true; diff --git a/modules/services/vaultwarden/docs/default.md b/modules/services/vaultwarden/docs/default.md index f2b130e..4ad4a4f 100644 --- a/modules/services/vaultwarden/docs/default.md +++ b/modules/services/vaultwarden/docs/default.md @@ -97,8 +97,11 @@ shb.zfs.datasets."postgresql".path = "/var/lib/postgresql"; Backing up Vaultwarden using the [Restic block](blocks-restic.html) is done like so: ```nix -shb.restic.instances."vaultwarden" = config.shb.vaultwarden.backup // { - enable = true; +shb.restic.instances."vaultwarden" = { + request = config.shb.vaultwarden.backup; + settings = { + enable = true; + }; }; ``` diff --git a/test/services/vaultwarden.nix b/test/services/vaultwarden.nix index 0439054..ebe89c0 100644 --- a/test/services/vaultwarden.nix +++ b/test/services/vaultwarden.nix @@ -93,18 +93,19 @@ let imports = [ ../../modules/blocks/restic.nix ]; - shb.restic.instances."testinstance" = config.shb.vaultwarden.backup // { - enable = true; - passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase"); - repositories = [ - { + shb.restic.instances."testinstance" = { + request = config.shb.vaultwarden.backup; + settings = { + enable = true; + passphraseFile = toString (pkgs.writeText "passphrase" "PassPhrase"); + repository = { path = "/opt/repos/A"; timerConfig = { OnCalendar = "00:00:00"; RandomizedDelaySec = "5h"; }; - } - ]; + }; + }; }; }; in