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