1 { config, lib, pkgs, ... }:
3 cfg = config.services.litestream;
4 settingsFormat = pkgs.formats.yaml {};
7 options.services.litestream = {
8 enable = lib.mkEnableOption "litestream";
10 package = lib.mkPackageOption pkgs "litestream" { };
12 settings = lib.mkOption {
14 See the [documentation](https://litestream.io/reference/config/).
16 type = settingsFormat.type;
20 path = "/var/lib/db1";
23 url = "s3://mybkt.litestream.io/db1";
31 environmentFile = lib.mkOption {
32 type = lib.types.nullOr lib.types.path;
34 example = "/run/secrets/litestream";
36 Environment file as defined in {manpage}`systemd.exec(5)`.
38 Secrets may be passed to the service without adding them to the
39 world-readable Nix store, by specifying placeholder variables as
40 the option value in Nix and setting these variables accordingly in the
43 By default, Litestream will perform environment variable expansion
44 within the config file before reading it. Any references to ''$VAR or
45 ''${VAR} formatted variables will be replaced with their environment
46 variable values. If no value is set then it will be replaced with an
50 # Content of the environment file
51 LITESTREAM_ACCESS_KEY_ID=AKIAxxxxxxxxxxxxxxxx
52 LITESTREAM_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx
55 Note that this file needs to be available on the host on which
56 this exporter is running.
61 config = lib.mkIf cfg.enable {
62 environment.systemPackages = [ cfg.package ];
65 source = settingsFormat.generate "litestream-config.yaml" cfg.settings;
69 systemd.services.litestream = {
70 description = "Litestream";
71 wantedBy = [ "multi-user.target" ];
72 after = [ "networking.target" ];
74 EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
75 ExecStart = "${cfg.package}/bin/litestream replicate";
82 users.users.litestream = {
83 description = "Litestream user";
87 users.groups.litestream = {};
90 meta.doc = ./default.md;