Skip to content

Commit

Permalink
switch backup contract to new contract style (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: ibizaman <[email protected]>
  • Loading branch information
ibizaman and ibizaman authored Nov 26, 2024
1 parent ba1e60a commit 47dffd2
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 383 deletions.
111 changes: 75 additions & 36 deletions docs/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@
"contracts-backup-options-shb.contracts.backup.result.restoreScript": [
"contracts-backup.html#contracts-backup-options-shb.contracts.backup.result.restoreScript"
],
"contracts-backup-options-shb.contracts.backup.settings": [
"contracts-backup.html#contracts-backup-options-shb.contracts.backup.settings"
],
"contracts-databasebackup-options-shb.contracts.databasebackup": [
"contracts-databasebackup.html#contracts-databasebackup-options-shb.contracts.databasebackup"
],
Expand Down Expand Up @@ -851,23 +854,35 @@
"services-forgejo-options-shb.forgejo.backup": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup"
],
"services-forgejo-options-shb.forgejo.backup.excludePatterns": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.excludePatterns"
"services-forgejo-options-shb.forgejo.backup.request": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request"
],
"services-forgejo-options-shb.forgejo.backup.request.excludePatterns": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.excludePatterns"
],
"services-forgejo-options-shb.forgejo.backup.request.hooks": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.hooks"
],
"services-forgejo-options-shb.forgejo.backup.request.hooks.afterBackup": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.hooks.afterBackup"
],
"services-forgejo-options-shb.forgejo.backup.hooks": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.hooks"
"services-forgejo-options-shb.forgejo.backup.request.hooks.beforeBackup": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.hooks.beforeBackup"
],
"services-forgejo-options-shb.forgejo.backup.hooks.afterBackup": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.hooks.afterBackup"
"services-forgejo-options-shb.forgejo.backup.request.sourceDirectories": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.sourceDirectories"
],
"services-forgejo-options-shb.forgejo.backup.hooks.beforeBackup": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.hooks.beforeBackup"
"services-forgejo-options-shb.forgejo.backup.request.user": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.request.user"
],
"services-forgejo-options-shb.forgejo.backup.sourceDirectories": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.sourceDirectories"
"services-forgejo-options-shb.forgejo.backup.result": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.result"
],
"services-forgejo-options-shb.forgejo.backup.user": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.user"
"services-forgejo-options-shb.forgejo.backup.result.backupService": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.result.backupService"
],
"services-forgejo-options-shb.forgejo.backup.result.restoreScript": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.backup.result.restoreScript"
],
"services-forgejo-options-shb.forgejo.databasePassword": [
"services-forgejo.html#services-forgejo-options-shb.forgejo.databasePassword"
Expand Down Expand Up @@ -1325,23 +1340,35 @@
"services-nextcloudserver-options-shb.nextcloud.backup": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup"
],
"services-nextcloudserver-options-shb.nextcloud.backup.excludePatterns": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.excludePatterns"
"services-nextcloudserver-options-shb.nextcloud.backup.request": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request"
],
"services-nextcloudserver-options-shb.nextcloud.backup.request.excludePatterns": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.excludePatterns"
],
"services-nextcloudserver-options-shb.nextcloud.backup.request.hooks": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.hooks"
],
"services-nextcloudserver-options-shb.nextcloud.backup.hooks": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.hooks"
"services-nextcloudserver-options-shb.nextcloud.backup.request.hooks.afterBackup": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.hooks.afterBackup"
],
"services-nextcloudserver-options-shb.nextcloud.backup.hooks.afterBackup": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.hooks.afterBackup"
"services-nextcloudserver-options-shb.nextcloud.backup.request.hooks.beforeBackup": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.hooks.beforeBackup"
],
"services-nextcloudserver-options-shb.nextcloud.backup.hooks.beforeBackup": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.hooks.beforeBackup"
"services-nextcloudserver-options-shb.nextcloud.backup.request.sourceDirectories": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.sourceDirectories"
],
"services-nextcloudserver-options-shb.nextcloud.backup.sourceDirectories": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.sourceDirectories"
"services-nextcloudserver-options-shb.nextcloud.backup.request.user": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.request.user"
],
"services-nextcloudserver-options-shb.nextcloud.backup.user": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.user"
"services-nextcloudserver-options-shb.nextcloud.backup.result": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.result"
],
"services-nextcloudserver-options-shb.nextcloud.backup.result.backupService": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.result.backupService"
],
"services-nextcloudserver-options-shb.nextcloud.backup.result.restoreScript": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.backup.result.restoreScript"
],
"services-nextcloudserver-options-shb.nextcloud.dataDir": [
"services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.dataDir"
Expand Down Expand Up @@ -1475,23 +1502,35 @@
"services-vaultwarden-options-shb.vaultwarden.backup": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup"
],
"services-vaultwarden-options-shb.vaultwarden.backup.excludePatterns": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.excludePatterns"
"services-vaultwarden-options-shb.vaultwarden.backup.request": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request"
],
"services-vaultwarden-options-shb.vaultwarden.backup.request.excludePatterns": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.excludePatterns"
],
"services-vaultwarden-options-shb.vaultwarden.backup.request.hooks": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.hooks"
],
"services-vaultwarden-options-shb.vaultwarden.backup.request.hooks.afterBackup": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.hooks.afterBackup"
],
"services-vaultwarden-options-shb.vaultwarden.backup.request.hooks.beforeBackup": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.hooks.beforeBackup"
],
"services-vaultwarden-options-shb.vaultwarden.backup.hooks": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.hooks"
"services-vaultwarden-options-shb.vaultwarden.backup.request.sourceDirectories": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.sourceDirectories"
],
"services-vaultwarden-options-shb.vaultwarden.backup.hooks.afterBackup": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.hooks.afterBackup"
"services-vaultwarden-options-shb.vaultwarden.backup.request.user": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.request.user"
],
"services-vaultwarden-options-shb.vaultwarden.backup.hooks.beforeBackup": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.hooks.beforeBackup"
"services-vaultwarden-options-shb.vaultwarden.backup.result": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.result"
],
"services-vaultwarden-options-shb.vaultwarden.backup.sourceDirectories": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.sourceDirectories"
"services-vaultwarden-options-shb.vaultwarden.backup.result.backupService": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.result.backupService"
],
"services-vaultwarden-options-shb.vaultwarden.backup.user": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.user"
"services-vaultwarden-options-shb.vaultwarden.backup.result.restoreScript": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.backup.result.restoreScript"
],
"services-vaultwarden-options-shb.vaultwarden.databasePassword": [
"services-vaultwarden.html#services-vaultwarden-options-shb.vaultwarden.databasePassword"
Expand Down
4 changes: 3 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs, lib }:
let
inherit (builtins) isAttrs hasAttr;
inherit (lib) concatMapStringsSep concatStringsSep mapAttrsToList;
inherit (lib) any concatMapStringsSep concatStringsSep mapAttrsToList;
in
rec {
# Replace secrets in a file.
Expand Down Expand Up @@ -292,4 +292,6 @@ rec {
"${concatStringsSep "_" secret.path}:${secret.${sourceField}}";
in
map genLoadCredentials allSecrets;

anyNotNull = any (x: x != null);
}
34 changes: 11 additions & 23 deletions modules/blocks/ldap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,19 @@ in
};

backup = lib.mkOption {
type = contracts.backup.request;
description = ''
Backup configuration. This is an output option.
Use it to initialize a block implementing the "backup" contract.
For example, with the restic block:
```
shb.restic.instances."lldap" = {
request = config.shb.lldap.backup;
settings = {
enable = true;
};
};
```
Backup configuration.
'';
readOnly = true;
default = {
# TODO: is there a workaround that avoid needing to use root?
# root because otherwise we cannot access the private StateDiretory
user = "root";
# /private because the systemd service uses DynamicUser=true
sourceDirectories = [
"/var/lib/private/lldap"
];
type = lib.types.submodule {
options = contracts.backup.mkRequester {
# TODO: is there a workaround that avoid needing to use root?
# root because otherwise we cannot access the private StateDiretory
user = "root";
# /private because the systemd service uses DynamicUser=true
sourceDirectories = [
"/var/lib/private/lldap"
];
};
};
};
};
Expand Down
36 changes: 6 additions & 30 deletions modules/blocks/restic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,7 @@ in
description = "Files to backup following the [backup contract](./contracts-backup.html).";
default = {};
type = attrsOf (submodule ({ name, config, ... }: {
options = {
request = mkOption {
description = ''
Request part of the backup contract.
Accepts values from a requester.
'';

type = contracts.backup.request;
};

options = contracts.backup.mkProvider {
settings = mkOption {
description = ''
Settings specific to the Restic provider.
Expand All @@ -132,26 +122,12 @@ in
};
};

result = mkOption {
description = ''
Result part of the backup contract.
resultCfg = {
restoreScript = fullName name config.settings.repository;
restoreScriptText = "${fullName "<name>" { path = "path/to/repository"; }}";

Contains the output of the Restic provider.
'';
default = {
restoreScript = fullName name config.settings.repository;
backupService = "${fullName name config.settings.repository}.service";
};
defaultText = {
restoreScriptText = "${fullName "<name>" { path = "path/to/repository"; }}";
backupServiceText = "${fullName "<name>" { path = "path/to/repository"; }}.service";
};
type = contracts.backup.result {
restoreScript = fullName name config.settings.repository;
backupService = "${fullName name config.settings.repository}.service";
restoreScriptText = "${fullName "<name>" { path = "path/to/repository"; }}";
backupServiceText = "${fullName "<name>" { path = "path/to/repository"; }}.service";
};
backupService = "${fullName name config.settings.repository}.service";
backupServiceText = "${fullName "<name>" { path = "path/to/repository"; }}.service";
};
};
}));
Expand Down
Loading

0 comments on commit 47dffd2

Please sign in to comment.