1 import ./make-test-python.nix ({ pkgs, ...} : {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ jwygoda ];
9 { services.litestream = {
14 path = "/var/lib/grafana/data/grafana.db";
16 url = "sftp://foo:bar@127.0.0.1:22/home/foo/grafana";
22 systemd.services.grafana.serviceConfig.ExecStartPost = "+" + pkgs.writeShellScript "grant-grafana-permissions" ''
25 while [ ! -f /var/lib/grafana/data/grafana.db ];
27 if [ "$timeout" == 0 ]; then
28 echo "ERROR: Timeout while waiting for /var/lib/grafana/data/grafana.db."
37 find /var/lib/grafana -type d -exec chmod -v 775 {} \;
38 find /var/lib/grafana -type f -exec chmod -v 660 {} \;
43 listenAddresses = [ { addr = "127.0.0.1"; port = 22; } ];
50 admin_password = "admin";
54 http_addr = "localhost";
60 path = "/var/lib/grafana/data/grafana.db";
69 users.users.litestream.extraGroups = [ "grafana" ];
74 machine.wait_until_succeeds("test -d /home/foo/grafana")
75 machine.wait_for_open_port(3000)
77 curl -sSfN -X PUT -H "Content-Type: application/json" -d '{
78 "oldPassword": "admin",
79 "newPassword": "newpass",
80 "confirmNew": "newpass"
81 }' http://admin:admin@127.0.0.1:3000/api/user/password
83 # https://litestream.io/guides/systemd/#simulating-a-disaster
84 machine.systemctl("stop litestream.service")
86 "rm -f /var/lib/grafana/data/grafana.db "
87 "/var/lib/grafana/data/grafana.db-shm "
88 "/var/lib/grafana/data/grafana.db-wal"
91 "litestream restore /var/lib/grafana/data/grafana.db "
92 "&& chown grafana:grafana /var/lib/grafana/data/grafana.db "
93 "&& chmod 660 /var/lib/grafana/data/grafana.db"
95 machine.systemctl("restart grafana.service")
96 machine.wait_for_open_port(3000)
98 "curl -sSfN -u admin:newpass http://127.0.0.1:3000/api/org/users | grep admin\@localhost"