From fea693ba16616890770d69b847744186f6a21930 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 25 Mar 2017 21:48:17 +0100 Subject: [PATCH] Use stricter Bash settings in activation script For example, with these settings Bash will complain if uninitialized variables are used. Some code has been improved to run cleanly with these settings. --- home-manager/home-manager | 2 +- modules/activation-init.sh | 8 ++++---- modules/home-environment.nix | 3 ++- modules/programs/gnome-terminal.nix | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index a027a9f0..2344ff98 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -40,7 +40,7 @@ function doBuild() { extraArgs="$extraArgs -I $p" done - if [[ $VERBOSE ]]; then + if [[ -v VERBOSE ]]; then extraArgs="$extraArgs --show-trace" fi diff --git a/modules/activation-init.sh b/modules/activation-init.sh index d92dccb8..5ac5fdfe 100755 --- a/modules/activation-init.sh +++ b/modules/activation-init.sh @@ -30,20 +30,20 @@ setupVars echo "Starting home manager activation" -if [[ $VERBOSE ]]; then +if [[ -v VERBOSE ]]; then export VERBOSE_ECHO=echo export VERBOSE_ARG="--verbose" else export VERBOSE_ECHO=true - unset VERBOSE_ARG + export VERBOSE_ARG="" fi -if [[ $DRY_RUN ]] ; then +if [[ -v DRY_RUN ]] ; then $VERBOSE_ECHO "This is a dry run" export DRY_RUN_CMD=echo else $VERBOSE_ECHO "This is a live run" - unset DRY_RUN_CMD + export DRY_RUN_CMD="" fi $VERBOSE_ECHO "Activation variables:" diff --git a/modules/home-environment.nix b/modules/home-environment.nix index e492b8d5..cef70541 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -328,7 +328,8 @@ in sf = pkgs.writeText "activation-script" '' #!${pkgs.stdenv.shell} - set -e + set -eu + set -o pipefail ${builtins.readFile ./activation-init.sh} diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix index bbeab158..ccb6a57b 100644 --- a/modules/programs/gnome-terminal.nix +++ b/modules/programs/gnome-terminal.nix @@ -184,7 +184,7 @@ in in # The dconf service needs to be installed and prepared. stringAfter [ "installPackages" ] '' - if [[ $DRY_RUN ]]; then + if [[ -v DRY_RUN ]]; then echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${sf} else ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf}