at master 1.5 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 cfg = config.services.zrepl; 9 format = pkgs.formats.yaml { }; 10 configFile = format.generate "zrepl.yml" cfg.settings; 11in 12{ 13 meta.maintainers = with lib.maintainers; [ cole-h ]; 14 15 options = { 16 services.zrepl = { 17 enable = lib.mkEnableOption "zrepl"; 18 19 package = lib.mkPackageOption pkgs "zrepl" { }; 20 21 settings = lib.mkOption { 22 default = { }; 23 description = '' 24 Configuration for zrepl. See <https://zrepl.github.io/configuration.html> 25 for more information. 26 ''; 27 type = lib.types.submodule { 28 freeformType = format.type; 29 }; 30 }; 31 }; 32 }; 33 34 ### Implementation ### 35 36 config = lib.mkIf cfg.enable { 37 environment.systemPackages = [ cfg.package ]; 38 39 # zrepl looks for its config in this location by default. This 40 # allows the use of e.g. `zrepl signal wakeup <job>` without having 41 # to specify the storepath of the config. 42 environment.etc."zrepl/zrepl.yml".source = configFile; 43 44 systemd.packages = [ cfg.package ]; 45 46 # Note that pkgs.zrepl copies and adapts the upstream systemd unit, and 47 # the fields defined here only override certain fields from that unit. 48 systemd.services.zrepl = { 49 requires = [ "local-fs.target" ]; 50 wantedBy = [ "zfs.target" ]; 51 after = [ "zfs.target" ]; 52 53 path = [ config.boot.zfs.package ]; 54 restartTriggers = [ configFile ]; 55 56 serviceConfig = { 57 Restart = "on-failure"; 58 }; 59 }; 60 }; 61}