service/backup: add doInit option

This commit is contained in:
Felix Buehler 2023-02-11 21:44:10 +01:00
parent fee07c3a1c
commit 5bd3f8de0a

View file

@ -4,53 +4,53 @@ let
in in
{ {
options.my.services.backup = with lib; { options.my.services.backup = with lib; {
enable = mkEnableOption "Borgbackup Service"; enable = mkEnableOption (lib.mdDoc "Borgbackup Service");
passwordFile = mkOption { passwordFile = mkOption {
type = types.path; type = types.path;
description = "Password for the backup"; description = lib.mdDoc "Password for the backup";
example = "/run/secrets/password"; example = "/run/secrets/password";
}; };
sshHost = mkOption { sshHost = mkOption {
type = types.str; type = types.str;
description = "ssh-hostname for remote access"; description = lib.mdDoc "ssh-hostname for remote access";
default = "u181505-sub1.your-storagebox.de"; default = "u181505-sub1.your-storagebox.de";
example = "test.domain.com"; example = "test.domain.com";
}; };
sshUser = mkOption { sshUser = mkOption {
type = types.str; type = types.str;
description = "ssh-user for remote access"; description = lib.mdDoc "ssh-user for remote access";
default = "u181505-sub1"; default = "u181505-sub1";
example = "max"; example = "max";
}; };
sshPort = mkOption { sshPort = mkOption {
type = types.port; type = types.port;
description = "ssh-port for remote access"; description = lib.mdDoc "ssh-port for remote access";
default = 23; default = 23;
example = 22; example = 22;
}; };
sshKeyFile = mkOption { sshKeyFile = mkOption {
type = types.path; type = types.path;
description = "ssh-key for remote access"; description = lib.mdDoc "ssh-key for remote access";
example = "/run/secrets/ssh_key"; example = "/run/secrets/ssh_key";
}; };
OnFailureNotification = mkOption { OnFailureNotification = mkOption {
type = types.bool; type = types.bool;
description = "whether to show a warning to all users or not"; description = lib.mdDoc "whether to show a warning to all users or not";
default = false; default = false;
}; };
OnFailureMail = mkOption { OnFailureMail = mkOption {
type = types.nullOr (types.str); type = types.nullOr (types.str);
description = "Mail adress where to send the error report"; description = lib.mdDoc "Mail adress where to send the error report";
default = null; default = null;
example = "alarm@mail.com"; example = "alarm@mail.com";
}; };
paths = mkOption { paths = mkOption {
type = with types; listOf str; type = with types; listOf str;
description = "additional path(s) to back up"; description = lib.mdDoc "additional path(s) to back up";
default = [ "/" ]; default = [ "/" ];
example = [ example = [
"/home/user" "/home/user"
@ -58,13 +58,25 @@ in
}; };
exclude = mkOption { exclude = mkOption {
type = with types; listOf str; type = with types; listOf str;
description = "Exclude paths matching any of the given patterns. See `borg help patterns`"; description = lib.mdDoc "Exclude paths matching any of the given patterns. See `borg help patterns`";
default = [ ]; default = [ ];
example = [ example = [
"/home/*/.cache" "/home/*/.cache"
"/tmp" "/tmp"
]; ];
}; };
doInit = mkOption {
type = types.bool;
description = lib.mdDoc ''
Run {command}`borg init` if the
specified {option}`repo` does not exist.
You should set this to `false`
if the repository is located on an external drive
that might not always be mounted.
'';
default = false;
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@ -110,7 +122,7 @@ in
environment.BORG_RSH = "ssh -o 'StrictHostKeyChecking=no' -i ${cfg.sshKeyFile} -p ${toString cfg.sshPort}"; environment.BORG_RSH = "ssh -o 'StrictHostKeyChecking=no' -i ${cfg.sshKeyFile} -p ${toString cfg.sshPort}";
repo = "${cfg.sshUser}@${cfg.sshHost}:${config.networking.hostName}/"; repo = "${cfg.sshUser}@${cfg.sshHost}:${config.networking.hostName}/";
doInit = false; doInit = cfg.doInit;
compression = "auto,zstd"; compression = "auto,zstd";
postHook = '' postHook = ''