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 (lib.mdDoc "zrepl");
15
16 package = mkOption {
17 type = types.package;
18 default = pkgs.zrepl;
19 defaultText = literalExpression "pkgs.zrepl";
20 description = lib.mdDoc "Which package to use for zrepl";
21 };
22
23 settings = mkOption {
24 default = { };
25 description = lib.mdDoc ''
26 Configuration for zrepl. See <https://zrepl.github.io/configuration.html>
27 for more information.
28 '';
29 type = types.submodule {
30 freeformType = format.type;
31 };
32 };
33 };
34 };
35
36 ### Implementation ###
37
38 config = mkIf cfg.enable {
39 environment.systemPackages = [ cfg.package ];
40
41 # zrepl looks for its config in this location by default. This
42 # allows the use of e.g. `zrepl signal wakeup <job>` without having
43 # to specify the storepath of the config.
44 environment.etc."zrepl/zrepl.yml".source = configFile;
45
46 systemd.packages = [ cfg.package ];
47
48 # Note that pkgs.zrepl copies and adapts the upstream systemd unit, and
49 # the fields defined here only override certain fields from that unit.
50 systemd.services.zrepl = {
51 requires = [ "local-fs.target" ];
52 wantedBy = [ "zfs.target" ];
53 after = [ "zfs.target" ];
54
55 path = [ config.boot.zfs.package ];
56 restartTriggers = [ configFile ];
57
58 serviceConfig = {
59 Restart = "on-failure";
60 };
61 };
62 };
63}