85 lines
2.2 KiB
Nix
85 lines
2.2 KiB
Nix
{
|
|
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";
|
|
};
|
|
};
|
|
}
|