backup module fix, it now supports multiple folders
This commit is contained in:
parent
da94e520ee
commit
cf8a2f0b74
5 changed files with 145 additions and 122 deletions
85
modules/backup/default.nix
Normal file
85
modules/backup/default.nix
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
# Configuration
|
||||
options.services.backup = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options = {
|
||||
enable = lib.mkEnableOption "Whether to enable backups for this path or not.";
|
||||
|
||||
dest = lib.mkOption {
|
||||
type = lib.types.either lib.types.path lib.types.str;
|
||||
default = null;
|
||||
description = "A destination for the backup.";
|
||||
};
|
||||
|
||||
compression = {
|
||||
command = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "tar -caf \"$DST\" \"$SRC\"";
|
||||
description = "A bash command to compress backups. Defaults to an uncompressed tar archive.";
|
||||
};
|
||||
};
|
||||
|
||||
encryption = {
|
||||
command = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "A bash command to encrypt backups. Defaults to a clear archive (simple cat).";
|
||||
default = "cat \"$SRC\" > \"$DST\"";
|
||||
};
|
||||
key = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
description = "A key to encrypt backups.";
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
salvation = {
|
||||
command = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "A bash command to save the archive. Defaults to a copy from source to dest.";
|
||||
default = "cp \"$SRC\" \"$DST\"";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
config =
|
||||
let
|
||||
systemd_set = (
|
||||
lib.attrsets.mapAttrs (
|
||||
path: config:
|
||||
(import ./systemd-utils.nix {
|
||||
inherit path config;
|
||||
script = import ./shell-utils.nix {
|
||||
inherit path config pkgs;
|
||||
};
|
||||
})
|
||||
) config.services.backup
|
||||
);
|
||||
|
||||
merge =
|
||||
key:
|
||||
lib.pipe systemd_set [
|
||||
builtins.attrValues
|
||||
(map (cfg: cfg.${key}))
|
||||
lib.mkMerge
|
||||
];
|
||||
in
|
||||
{
|
||||
systemd = {
|
||||
timers = merge "timers";
|
||||
services = merge "services";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue