Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #65407 from alunduil/add-zfs-replication

Add zfs replication

authored by Jörg Thalheim and committed by GitHub d02ead41 dc5584ad

+158
+90
nixos/modules/services/backup/zfs-replication.nix
···
··· 1 + { lib, pkgs, config, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.services.zfs.autoReplication; 7 + recursive = optionalString cfg.recursive " --recursive"; 8 + followDelete = optionalString cfg.followDelete " --follow-delete"; 9 + in { 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 correspondant."; 16 + default = true; 17 + type = types.bool; 18 + }; 19 + 20 + host = mkOption { 21 + description = "Remote host where snapshots should be sent."; 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 fileystem 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 + }
+22
pkgs/development/python-modules/stringcase/default.nix
···
··· 1 + { buildPythonPackage, fetchPypi, stdenv 2 + }: 3 + 4 + buildPythonPackage rec { 5 + pname = "stringcase"; 6 + version = "1.2.0"; 7 + 8 + src = fetchPypi { 9 + inherit pname version; 10 + sha256 = "023hv3gknblhf9lx5kmkcchzmbhkdhmsnknkv7lfy20rcs06k828"; 11 + }; 12 + 13 + # PyPi package does not include tests. 14 + doCheck = false; 15 + 16 + meta = with stdenv.lib; { 17 + homepage = https://github.com/okunishinishi/python-stringcase; 18 + description = "Convert string cases between camel case, pascal case, snake case etc…"; 19 + license = licenses.mit; 20 + maintainers = with maintainers; [ alunduil ]; 21 + }; 22 + }
+42
pkgs/tools/backup/zfs-replicate/default.nix
···
··· 1 + { buildPythonApplication, click, fetchPypi, hypothesis, mypy, pytest 2 + , pytestcov, pytestrunner, stdenv, stringcase 3 + }: 4 + 5 + buildPythonApplication rec { 6 + pname = "zfs-replicate"; 7 + version = "1.1.11"; 8 + 9 + src = fetchPypi { 10 + inherit pname version; 11 + sha256 = "0386xc6rw6bhzw2a08g90afb3snqhm1ikx65bjfh22ha69fwmga8"; 12 + }; 13 + 14 + checkInputs = [ 15 + hypothesis 16 + mypy 17 + pytest 18 + pytestcov 19 + ]; 20 + 21 + buildInputs = [ 22 + pytestrunner 23 + ]; 24 + 25 + propagatedBuildInputs = [ 26 + click 27 + stringcase 28 + ]; 29 + 30 + doCheck = true; 31 + 32 + checkPhase = '' 33 + pytest --doctest-modules 34 + ''; 35 + 36 + meta = with stdenv.lib; { 37 + homepage = https://github.com/alunduil/zfs-replicate; 38 + description = "ZFS Snapshot Replication"; 39 + license = licenses.bsd2; 40 + maintainers = with maintainers; [ alunduil ]; 41 + }; 42 + }
+2
pkgs/top-level/all-packages.nix
··· 24570 dapper = callPackage ../development/tools/dapper { }; 24571 24572 kube3d = callPackage ../applications/networking/cluster/kube3d {}; 24573 }
··· 24570 dapper = callPackage ../development/tools/dapper { }; 24571 24572 kube3d = callPackage ../applications/networking/cluster/kube3d {}; 24573 + 24574 + zfs-replicate = python3Packages.callPackage ../tools/backup/zfs-replicate { }; 24575 }
+2
pkgs/top-level/python-packages.nix
··· 6088 pydantic = callPackage ../development/python-modules/pydantic { }; 6089 6090 fastapi = callPackage ../development/python-modules/fastapi { }; 6091 }); 6092 6093 in fix' (extends overrides packages)
··· 6088 pydantic = callPackage ../development/python-modules/pydantic { }; 6089 6090 fastapi = callPackage ../development/python-modules/fastapi { }; 6091 + 6092 + stringcase = callPackage ../development/python-modules/stringcase { }; 6093 }); 6094 6095 in fix' (extends overrides packages)