git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit41387135ddb01d84049d1931292cacabbde54a34 authortalyz <kim.lindberger@gmail.com> dateFri 4 Jun 2021, 18:19 (5 years ago) parent98f07d6
1 file changed+13−5
nixos/modules/services/monitoring/grafana.nix+13−5
nixos/modules/services/monitoring/grafana.nix+13−5
@@ -640,20 +640,28 @@ in {
640640 QT_QPA_PLATFORM = "offscreen";
641641 } // mapAttrs' (n: v: nameValuePair "GF_${n}" (toString v)) envOptions;
642642 script = ''
643+ set -o errexit -o pipefail -o nounset -o errtrace
644+ shopt -s inherit_errexit
645+
643646 ${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
645649 ''}
646650 ${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
648653 ''}
649654 ${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
651657 ''}
652658 ${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
654661 ''}
655662 ${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
657665 ''}
658666 ${optionalString cfg.provision.enable ''
659667 export GF_PATHS_PROVISIONING=${provisionConfDir};