feat: backup daedalus

This commit is contained in:
Lucy Hochkamp 2023-10-23 16:52:38 +02:00
parent b0871baea6
commit de33341053
No known key found for this signature in database
3 changed files with 69 additions and 35 deletions

View file

@ -5,33 +5,6 @@ let
settingsFormat = pkgs.formats.yaml { };
cfgType = with types; submodule {
freeformType = settingsFormat.type;
options.location = {
source_directories = mkOption {
type = listOf str;
description = mdDoc ''
List of source directories to backup (required). Globs and
tildes are expanded.
'';
example = [ "/home" "/etc" "/var/log/syslog*" ];
};
repositories = mkOption {
type = listOf str;
description = mdDoc ''
Paths to local or remote repositories (required). Tildes are
expanded. Multiple repositories are backed up to in
sequence. Borg placeholders can be used. See the output of
"borg help placeholders" for details. See ssh_command for
SSH options like identity file or port. If systemd service
is used, then add local repository paths in the systemd
service file to the ReadWritePaths list.
'';
example = [
"ssh://user@backupserver/./sourcehostname.borg"
"ssh://user@backupserver/./{fqdn}"
"/var/local/backups/local.borg"
];
};
};
};
cfgfile = settingsFormat.generate "config.yaml" cfg.settings;
in
@ -57,7 +30,11 @@ in
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.borgmatic ];
environment.systemPackages = [
#pkgs.borgmatic
pkgs.borgbackup
];
homebrew.brews = [ "borgmatic" ];
environment.etc = (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) //
mapAttrs'
@ -66,17 +43,30 @@ in
{ source = settingsFormat.generate "${name}.yaml" value; })
cfg.configurations;
launchd.agents.borgmatic = {
script = "borgmatic";
launchd.user.agents.borgmatic = {
script = ''
if (pmset -g batt | grep -q 'AC Power'); then
borgmatic
else
echo "On Battery Power, skipping backup"
fi
'';
path = [ "/opt/homebrew/bin" config.environment.systemPath ];
serviceConfig = {
StartInterval = 60 * 60; # run every hour
label = "xyz.ragon.borgmatic";
StandardOutPath = "/var/log/borgmatic.log";
StandardErrorPath = "/var/log/borgmatic.log.error";
NetworkState = true;
StandardErrorPath = "/var/log/borgmatic.log";
KeepAlive = true;
# NetworkState = true;
Nice = 1;
};
};
assertions = [
{
assertion = config.homebrew.enable;
message = "homebrew must be enabled for borgmatic to run";
}
];
};