1 { lib, pkgs, config, ... }:
3 cfg = config.services.zfs.autoReplication;
4 recursive = lib.optionalString cfg.recursive " --recursive";
5 followDelete = lib.optionalString cfg.followDelete " --follow-delete";
8 services.zfs.autoReplication = {
9 enable = lib.mkEnableOption "ZFS snapshot replication";
11 followDelete = lib.mkOption {
12 description = "Remove remote snapshots that don't have a local correspondent.";
14 type = lib.types.bool;
18 description = "Remote host where snapshots should be sent. `lz4` is expected to be installed on this host.";
19 example = "example.com";
23 identityFilePath = lib.mkOption {
24 description = "Path to SSH key used to login to host.";
25 example = "/home/username/.ssh/id_rsa";
26 type = lib.types.path;
29 localFilesystem = lib.mkOption {
30 description = "Local ZFS filesystem from which snapshots should be sent. Defaults to the attribute name.";
31 example = "pool/file/path";
35 remoteFilesystem = lib.mkOption {
36 description = "Remote ZFS filesystem where snapshots should be sent.";
37 example = "pool/file/path";
41 recursive = lib.mkOption {
42 description = "Recursively discover snapshots to send.";
44 type = lib.types.bool;
47 username = lib.mkOption {
48 description = "Username used by SSH to login to remote host.";
55 config = lib.mkIf cfg.enable {
56 environment.systemPackages = [
60 systemd.services.zfs-replication = {
62 "zfs-snapshot-daily.service"
63 "zfs-snapshot-frequent.service"
64 "zfs-snapshot-hourly.service"
65 "zfs-snapshot-monthly.service"
66 "zfs-snapshot-weekly.service"
68 description = "ZFS Snapshot Replication";
70 "https://github.com/alunduil/zfs-replicate"
72 restartIfChanged = false;
73 serviceConfig.ExecStart = "${pkgs.zfs-replicate}/bin/zfs-replicate${recursive} -l ${lib.escapeShellArg cfg.username} -i ${lib.escapeShellArg cfg.identityFilePath}${followDelete} ${lib.escapeShellArg cfg.host} ${lib.escapeShellArg cfg.remoteFilesystem} ${lib.escapeShellArg cfg.localFilesystem}";
75 "zfs-snapshot-daily.service"
76 "zfs-snapshot-frequent.service"
77 "zfs-snapshot-hourly.service"
78 "zfs-snapshot-monthly.service"
79 "zfs-snapshot-weekly.service"
85 maintainers = with lib.maintainers; [ alunduil ];