2020-04-24 23:36:52 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.zfs.autoReplication;
|
|
|
|
recursive = optionalString cfg.recursive " --recursive";
|
|
|
|
followDelete = optionalString cfg.followDelete " --follow-delete";
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.zfs.autoReplication = {
|
|
|
|
enable = mkEnableOption "ZFS snapshot replication.";
|
|
|
|
|
|
|
|
followDelete = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Remove remote snapshots that don't have a local correspondant.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Remote host where snapshots should be sent. `lz4` is expected to be installed on this host.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "example.com";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
identityFilePath = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path to SSH key used to login to host.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "/home/username/.ssh/id_rsa";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
localFilesystem = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Local ZFS fileystem from which snapshots should be sent. Defaults to the attribute name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "pool/file/path";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
remoteFilesystem = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Remote ZFS filesystem where snapshots should be sent.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "pool/file/path";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
recursive = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Recursively discover snapshots to send.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Username used by SSH to login to remote host.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "username";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.lz4
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.zfs-replication = {
|
|
|
|
after = [
|
|
|
|
"zfs-snapshot-daily.service"
|
|
|
|
"zfs-snapshot-frequent.service"
|
|
|
|
"zfs-snapshot-hourly.service"
|
|
|
|
"zfs-snapshot-monthly.service"
|
|
|
|
"zfs-snapshot-weekly.service"
|
|
|
|
];
|
|
|
|
description = "ZFS Snapshot Replication";
|
|
|
|
documentation = [
|
|
|
|
"https://github.com/alunduil/zfs-replicate"
|
|
|
|
];
|
|
|
|
restartIfChanged = false;
|
|
|
|
serviceConfig.ExecStart = "${pkgs.zfs-replicate}/bin/zfs-replicate${recursive} -l ${escapeShellArg cfg.username} -i ${escapeShellArg cfg.identityFilePath}${followDelete} ${escapeShellArg cfg.host} ${escapeShellArg cfg.remoteFilesystem} ${escapeShellArg cfg.localFilesystem}";
|
|
|
|
wantedBy = [
|
|
|
|
"zfs-snapshot-daily.service"
|
|
|
|
"zfs-snapshot-frequent.service"
|
|
|
|
"zfs-snapshot-hourly.service"
|
|
|
|
"zfs-snapshot-monthly.service"
|
|
|
|
"zfs-snapshot-weekly.service"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ alunduil ];
|
|
|
|
};
|
|
|
|
}
|