nixos/grafana: Add error handling to service script

Without this, the services starts even if files are missing or
prerequisite commands fail, which can lead to incorrect initial
state.

authored by talyz and committed by Raphael Megzari 41387135 98f07d6c

+13 -5
+13 -5
nixos/modules/services/monitoring/grafana.nix
··· 640 QT_QPA_PLATFORM = "offscreen"; 641 } // mapAttrs' (n: v: nameValuePair "GF_${n}" (toString v)) envOptions; 642 script = '' 643 ${optionalString (cfg.auth.google.clientSecretFile != null) '' 644 - export GF_AUTH_GOOGLE_CLIENT_SECRET="$(cat ${escapeShellArg cfg.auth.google.clientSecretFile})" 645 ''} 646 ${optionalString (cfg.database.passwordFile != null) '' 647 - export GF_DATABASE_PASSWORD="$(cat ${escapeShellArg cfg.database.passwordFile})" 648 ''} 649 ${optionalString (cfg.security.adminPasswordFile != null) '' 650 - export GF_SECURITY_ADMIN_PASSWORD="$(cat ${escapeShellArg cfg.security.adminPasswordFile})" 651 ''} 652 ${optionalString (cfg.security.secretKeyFile != null) '' 653 - export GF_SECURITY_SECRET_KEY="$(cat ${escapeShellArg cfg.security.secretKeyFile})" 654 ''} 655 ${optionalString (cfg.smtp.passwordFile != null) '' 656 - export GF_SMTP_PASSWORD="$(cat ${escapeShellArg cfg.smtp.passwordFile})" 657 ''} 658 ${optionalString cfg.provision.enable '' 659 export GF_PATHS_PROVISIONING=${provisionConfDir};
··· 640 QT_QPA_PLATFORM = "offscreen"; 641 } // mapAttrs' (n: v: nameValuePair "GF_${n}" (toString v)) envOptions; 642 script = '' 643 + set -o errexit -o pipefail -o nounset -o errtrace 644 + shopt -s inherit_errexit 645 + 646 ${optionalString (cfg.auth.google.clientSecretFile != null) '' 647 + GF_AUTH_GOOGLE_CLIENT_SECRET="$(<${escapeShellArg cfg.auth.google.clientSecretFile})" 648 + export GF_AUTH_GOOGLE_CLIENT_SECRET 649 ''} 650 ${optionalString (cfg.database.passwordFile != null) '' 651 + GF_DATABASE_PASSWORD="$(<${escapeShellArg cfg.database.passwordFile})" 652 + export GF_DATABASE_PASSWORD 653 ''} 654 ${optionalString (cfg.security.adminPasswordFile != null) '' 655 + GF_SECURITY_ADMIN_PASSWORD="$(<${escapeShellArg cfg.security.adminPasswordFile})" 656 + export GF_SECURITY_ADMIN_PASSWORD 657 ''} 658 ${optionalString (cfg.security.secretKeyFile != null) '' 659 + GF_SECURITY_SECRET_KEY="$(<${escapeShellArg cfg.security.secretKeyFile})" 660 + export GF_SECURITY_SECRET_KEY 661 ''} 662 ${optionalString (cfg.smtp.passwordFile != null) '' 663 + GF_SMTP_PASSWORD="$(<${escapeShellArg cfg.smtp.passwordFile})" 664 + export GF_SMTP_PASSWORD 665 ''} 666 ${optionalString cfg.provision.enable '' 667 export GF_PATHS_PROVISIONING=${provisionConfDir};