1 { config, lib, pkgs, ... }:
6 cfg = config.services.litestream;
7 settingsFormat = pkgs.formats.yaml {};
10 options.services.litestream = {
11 enable = mkEnableOption (lib.mdDoc "litestream");
14 description = lib.mdDoc "Package to use.";
15 default = pkgs.litestream;
16 defaultText = literalExpression "pkgs.litestream";
21 description = lib.mdDoc ''
22 See the [documentation](https://litestream.io/reference/config/).
24 type = settingsFormat.type;
28 path = "/var/lib/db1";
31 url = "s3://mybkt.litestream.io/db1";
39 environmentFile = mkOption {
40 type = types.nullOr types.path;
42 example = "/run/secrets/litestream";
43 description = lib.mdDoc ''
44 Environment file as defined in {manpage}`systemd.exec(5)`.
46 Secrets may be passed to the service without adding them to the
47 world-readable Nix store, by specifying placeholder variables as
48 the option value in Nix and setting these variables accordingly in the
51 By default, Litestream will perform environment variable expansion
52 within the config file before reading it. Any references to ''$VAR or
53 ''${VAR} formatted variables will be replaced with their environment
54 variable values. If no value is set then it will be replaced with an
58 # Content of the environment file
59 LITESTREAM_ACCESS_KEY_ID=AKIAxxxxxxxxxxxxxxxx
60 LITESTREAM_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx
63 Note that this file needs to be available on the host on which
64 this exporter is running.
69 config = mkIf cfg.enable {
70 environment.systemPackages = [ cfg.package ];
73 source = settingsFormat.generate "litestream-config.yaml" cfg.settings;
77 systemd.services.litestream = {
78 description = "Litestream";
79 wantedBy = [ "multi-user.target" ];
80 after = [ "networking.target" ];
82 EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
83 ExecStart = "${cfg.package}/bin/litestream replicate";
90 users.users.litestream = {
91 description = "Litestream user";
95 users.groups.litestream = {};
98 meta.doc = ./default.md;