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 = 17 "+" 18 + pkgs.writeShellScript "grant-grafana-permissions" '' 19 timeout=10 20 21 while [ ! -f /var/lib/grafana/data/grafana.db ]; 22 do 23 if [ "$timeout" == 0 ]; then 24 echo "ERROR: Timeout while waiting for /var/lib/grafana/data/grafana.db." 25 exit 1 26 fi 27 28 sleep 1 29 30 ((timeout--)) 31 done 32 33 find /var/lib/grafana -type d -exec chmod -v 775 {} \; 34 find /var/lib/grafana -type f -exec chmod -v 660 {} \; 35 ''; 36 37 services.litestream = { 38 enable = true; 39 40 environmentFile = "/run/secrets/litestream"; 41 42 settings = { 43 dbs = [ 44 { 45 path = "/var/lib/grafana/data/grafana.db"; 46 replicas = [ { url = "s3://mybkt.litestream.io/grafana"; } ]; 47 } 48 ]; 49 }; 50 }; 51} 52```