1# Litestream {#module-services-litestream} 2 3[Litestream](https://litestream.io/) is a standalone streaming 4replication tool for SQLite. 5 6## Configuration {#module-services-litestream-configuration} 7 8Litestream service is managed by a dedicated user named `litestream` 9which needs permission to the database file. Here's an example config which gives 10required permissions to access [grafana database](#opt-services.grafana.settings.database.path): 11```nix 12{ pkgs, ... }: 13{ 14 users.users.litestream.extraGroups = [ "grafana" ]; 15 16 systemd.services.grafana.serviceConfig.ExecStartPost = "+" + pkgs.writeShellScript "grant-grafana-permissions" '' 17 timeout=10 18 19 while [ ! -f /var/lib/grafana/data/grafana.db ]; 20 do 21 if [ "$timeout" == 0 ]; then 22 echo "ERROR: Timeout while waiting for /var/lib/grafana/data/grafana.db." 23 exit 1 24 fi 25 26 sleep 1 27 28 ((timeout--)) 29 done 30 31 find /var/lib/grafana -type d -exec chmod -v 775 {} \; 32 find /var/lib/grafana -type f -exec chmod -v 660 {} \; 33 ''; 34 35 services.litestream = { 36 enable = true; 37 38 environmentFile = "/run/secrets/litestream"; 39 40 settings = { 41 dbs = [ 42 { 43 path = "/var/lib/grafana/data/grafana.db"; 44 replicas = [{ 45 url = "s3://mybkt.litestream.io/grafana"; 46 }]; 47 } 48 ]; 49 }; 50 }; 51} 52```