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