at 24.11-pre 2.8 kB view raw
1{ lib, pkgs, config, ... }: 2 3with lib; 4 5let 6 cfg = config.services.zfs.autoReplication; 7 recursive = optionalString cfg.recursive " --recursive"; 8 followDelete = optionalString cfg.followDelete " --follow-delete"; 9in { 10 options = { 11 services.zfs.autoReplication = { 12 enable = mkEnableOption "ZFS snapshot replication"; 13 14 followDelete = mkOption { 15 description = "Remove remote snapshots that don't have a local correspondent."; 16 default = true; 17 type = types.bool; 18 }; 19 20 host = mkOption { 21 description = "Remote host where snapshots should be sent. `lz4` is expected to be installed on this host."; 22 example = "example.com"; 23 type = types.str; 24 }; 25 26 identityFilePath = mkOption { 27 description = "Path to SSH key used to login to host."; 28 example = "/home/username/.ssh/id_rsa"; 29 type = types.path; 30 }; 31 32 localFilesystem = mkOption { 33 description = "Local ZFS filesystem from which snapshots should be sent. Defaults to the attribute name."; 34 example = "pool/file/path"; 35 type = types.str; 36 }; 37 38 remoteFilesystem = mkOption { 39 description = "Remote ZFS filesystem where snapshots should be sent."; 40 example = "pool/file/path"; 41 type = types.str; 42 }; 43 44 recursive = mkOption { 45 description = "Recursively discover snapshots to send."; 46 default = true; 47 type = types.bool; 48 }; 49 50 username = mkOption { 51 description = "Username used by SSH to login to remote host."; 52 example = "username"; 53 type = types.str; 54 }; 55 }; 56 }; 57 58 config = lib.mkIf cfg.enable { 59 environment.systemPackages = [ 60 pkgs.lz4 61 ]; 62 63 systemd.services.zfs-replication = { 64 after = [ 65 "zfs-snapshot-daily.service" 66 "zfs-snapshot-frequent.service" 67 "zfs-snapshot-hourly.service" 68 "zfs-snapshot-monthly.service" 69 "zfs-snapshot-weekly.service" 70 ]; 71 description = "ZFS Snapshot Replication"; 72 documentation = [ 73 "https://github.com/alunduil/zfs-replicate" 74 ]; 75 restartIfChanged = false; 76 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}"; 77 wantedBy = [ 78 "zfs-snapshot-daily.service" 79 "zfs-snapshot-frequent.service" 80 "zfs-snapshot-hourly.service" 81 "zfs-snapshot-monthly.service" 82 "zfs-snapshot-weekly.service" 83 ]; 84 }; 85 }; 86 87 meta = { 88 maintainers = with lib.maintainers; [ alunduil ]; 89 }; 90}