Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: set -u everywhere #72347

Merged
merged 13 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nixos/doc/manual/release-notes/rl-2003.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@
<link linkend="opt-networking.interfaces">networking.interfaces.&lt;name&gt;.…</link> options.
</para>
</listitem>
<listitem>
<para>
The stdenv now runs all bash with <literal>set -u</literal>, to catch the use of undefined variables.
Before, it itself used <literal>set -u</literal> but was careful to unset it so other packages' code ran as before.
Now, all bash code is held to the same high standard, and the rather complex stateful manipulation of the options can be discarded.
</para>
</listitem>
</itemizedlist>
</section>

Expand Down
7 changes: 0 additions & 7 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,13 @@ stdenv.mkDerivation {

installPhase =
''
set -u

mkdir -p $out/bin $out/nix-support

wrap() {
local dst="$1"
local wrapper="$2"
export prog="$3"
set +u
substituteAll "$wrapper" "$out/bin/$dst"
set -u
chmod +x "$out/bin/$dst"
}
''
Expand Down Expand Up @@ -163,8 +159,6 @@ stdenv.mkDerivation {
[[ -e "$underlying" ]] || continue
wrap ${targetPrefix}$variant ${./ld-wrapper.sh} $underlying
done

set +u
'';

emulation = let
Expand Down Expand Up @@ -307,7 +301,6 @@ stdenv.mkDerivation {
''

+ ''
set +u
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
Expand Down
8 changes: 4 additions & 4 deletions pkgs/build-support/build-dotnet-package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ attrsOrig @
configurePhase = ''
runHook preConfigure

[ -z "$dontPlacateNuget" ] && placate-nuget.sh
[ -z "$dontPlacatePaket" ] && placate-paket.sh
[ -z "$dontPatchFSharpTargets" ] && patch-fsharp-targets.sh
[ -z "''${dontPlacateNuget-}" ] && placate-nuget.sh
[ -z "''${dontPlacatePaket-}" ] && placate-paket.sh
[ -z "''${dontPatchFSharpTargets-}" ] && patch-fsharp-targets.sh

runHook postConfigure
'';
Expand Down Expand Up @@ -69,7 +69,7 @@ attrsOrig @

cp -rv ${arrayToShell outputFiles} "''${outputFilesArray[@]}" "$target"

if [ -z "$dontRemoveDuplicatedDlls" ]
if [ -z "''${dontRemoveDuplicatedDlls-}" ]
then
pushd "$out"
remove-duplicated-dlls.sh
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/audit-tmpdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# the moment that would produce too many spurious errors (e.g. debug
# info or assertion messages that refer to $TMPDIR).

fixupOutputHooks+=('if [ -z "$noAuditTmpdir" -a -e "$prefix" ]; then auditTmpdir "$prefix"; fi')
fixupOutputHooks+=('if [[ -z "${noAuditTmpdir-}" && -e "$prefix" ]]; then auditTmpdir "$prefix"; fi')

auditTmpdir() {
local dir="$1"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/auto-patchelf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ autoPatchelf() {
# behaviour as fixupOutputHooks because the setup hook for patchelf is run in
# fixupOutput and the postFixup hook runs later.
postFixupHooks+=('
if [ -z "$dontAutoPatchelf" ]; then
if [ -z "${dontAutoPatchelf-}" ]; then
autoPatchelf -- $(for output in $outputs; do
[ -e "${!output}" ] || continue
echo "${!output}"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/compress-man-pages.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi')
fixupOutputHooks+=('if [ -z "${dontGzipMan-}" ]; then compressManPages "$prefix"; fi')

compressManPages() {
local dir="$1"
Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/setup-hooks/find-xml-catalogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ addXMLCatalogs () {
done
}

if [ -z "$libxmlHookDone" ]; then
if [ -z "${libxmlHookDone-}" ]; then
libxmlHookDone=1

# Set up XML_CATALOG_FILES. An empty initial value prevents
# xmllint and xsltproc from looking in /etc/xml/catalog.
export XML_CATALOG_FILES
export XML_CATALOG_FILES=''
if [ -z "$XML_CATALOG_FILES" ]; then XML_CATALOG_FILES=" "; fi
addEnvHooks "$hostOffset" addXMLCatalogs
fi
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/move-lib64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
fixupOutputHooks+=(_moveLib64)

_moveLib64() {
if [ "$dontMoveLib64" = 1 ]; then return; fi
if [ "${dontMoveLib64-}" = 1 ]; then return; fi
if [ ! -e "$prefix/lib64" -o -L "$prefix/lib64" ]; then return; fi
echo "moving $prefix/lib64/* to $prefix/lib"
mkdir -p $prefix/lib
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/move-sbin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fixupOutputHooks+=(_moveSbin)

_moveSbin() {
if [ "$dontMoveSbin" = 1 ]; then return; fi
if [ "${dontMoveSbin-}" = 1 ]; then return; fi
if [ ! -e "$prefix/sbin" -o -L "$prefix/sbin" ]; then return; fi
echo "moving $prefix/sbin/* to $prefix/bin"
mkdir -p $prefix/bin
Expand Down
6 changes: 3 additions & 3 deletions pkgs/build-support/setup-hooks/multiple-outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ _assignFirst() {
local varName="$1"
local REMOVE=REMOVE # slightly hacky - we allow REMOVE (i.e. not a variable name)
shift
while [ $# -ge 1 ]; do
if [ -n "${!1}" ]; then eval "${varName}"="$1"; return; fi
while (( $# )); do
if [ -n "${!1-}" ]; then eval "${varName}"="$1"; return; fi
shift
done
echo "Error: _assignFirst found no valid variant!"
Expand All @@ -19,7 +19,7 @@ _assignFirst() {

# Same as _assignFirst, but only if "$1" = ""
_overrideFirst() {
if [ -z "${!1}" ]; then
if [ -z "${!1-}" ]; then
_assignFirst "$@"
fi
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/patch-shebangs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ patchShebangs() {
}

patchShebangsAuto () {
if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then
if [ -z "${dontPatchShebangs-}" -a -e "$prefix" ]; then

# Dev output will end up being run on the build platform. An
# example case of this is sdl2-config. Otherwise, we can just
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/prune-libtool-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
fixupOutputHooks+=(_pruneLibtoolFiles)

_pruneLibtoolFiles() {
if [ "$dontPruneLibtoolFiles" ] || [ ! -e "$prefix" ]; then
if [ "${dontPruneLibtoolFiles-}" ] || [ ! -e "$prefix" ]; then
return
fi

Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/setup-hooks/strip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _doStrip() {
local -ra stripCmds=(STRIP TARGET_STRIP)

# Optimization
if [[ "$STRIP" == "$TARGET_STRIP" ]]; then
if [[ "${STRIP-}" == "${TARGET_STRIP-}" ]]; then
dontStripTarget+=1
fi

Expand All @@ -20,7 +20,7 @@ _doStrip() {
local -n stripCmd="${stripCmds[$i]}"

# `dontStrip` disables them all
if [[ "$dontStrip" || "$flag" ]] || ! type -f "$stripCmd" 2>/dev/null
if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null
then continue; fi

stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
preConfigurePhases+=" updateAutotoolsGnuConfigScriptsPhase"

updateAutotoolsGnuConfigScriptsPhase() {
if [ -n "$dontUpdateAutotoolsGnuConfigScripts" ]; then return; fi
if [ -n "${dontUpdateAutotoolsGnuConfigScripts-}" ]; then return; fi

for script in config.sub config.guess; do
for f in $(find . -type f -name "$script"); do
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/wrap-gapps-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wrapGApp() {
wrapProgram "$program" "${gappsWrapperArgs[@]}" "$@"
}

# Note: $gappsWrapperArgs still gets defined even if $dontWrapGApps is set.
# Note: $gappsWrapperArgs still gets defined even if ${dontWrapGApps-} is set.
wrapGAppsHook() {
# guard against running multiple times (e.g. due to propagation)
[ -z "$wrapGAppsHookHasRun" ] || return 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let cpuName = stdenv.hostPlatform.parsed.cpu.name;

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let result = stdenv.mkDerivation rec {

# Set JAVA_HOME automatically.
cat <<EOF >> "$out/nix-support/setup-hook"
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/graalvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ in rec {
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat <<EOF > $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';
postFixup = openjdk.postFixup or null;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/graalvm/enterprise-edition.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat <<EOF > $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/11.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ let
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat <<EOF > $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out/lib/openjdk; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/8.nix
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ let
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat <<EOF > $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out/lib/openjdk; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/darwin/11.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/darwin/8.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/openjdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ let
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat <<EOF > $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out/lib/openjdk; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/oraclejdk/jdk-linux-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ let result = stdenv.mkDerivation rec {

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/rust/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Fix 'failed to open: /homeless-shelter/.cargo/.package-cache' in rust 1.36.
if [[ -z $IN_NIX_SHELL && -z $CARGO_HOME ]]; then
if [[ -z ${IN_NIX_SHELL-} && -z ${CARGO_HOME-} ]]; then
export CARGO_HOME=$TMPDIR
fi
2 changes: 1 addition & 1 deletion pkgs/development/compilers/zulu/8.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ in stdenv.mkDerivation {

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/zulu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ in stdenv.mkDerivation {

# Set JAVA_HOME automatically.
cat <<EOF >> $out/nix-support/setup-hook
if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flitBuildPhase () {
echo "Finished executing flitBuildPhase"
}

if [ -z "$dontUseFlitBuild" ] && [ -z "$buildPhase" ]; then
if [ -z "${dontUseFlitBuild-}" ] && [ -z "${buildPhase-}" ]; then
echo "Using flitBuildPhase"
buildPhase=flitBuildPhase
fi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipShellHook() {
echo "Finished executing pipShellHook"
}

if [ -z "$dontUsePipBuild" ] && [ -z "$buildPhase" ]; then
if [ -z "${dontUsePipBuild-}" ] && [ -z "${buildPhase-}" ]; then
echo "Using pipBuildPhase"
buildPhase=pipBuildPhase
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pipInstallPhase() {
echo "Finished executing pipInstallPhase"
}

if [ -z "$dontUsePipInstall" ] && [ -z "$installPhase" ]; then
if [ -z "${dontUsePipInstall-}" ] && [ -z "${installPhase-}" ]; then
echo "Using pipInstallPhase"
installPhase=pipInstallPhase
fi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function pytestCheckPhase() {
echo "Finished executing pytestCheckPhase"
}

if [ -z "$dontUsePytestCheck" ] && [ -z "$installCheckPhase" ]; then
if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using pytestCheckPhase"
preDistPhases+=" pytestCheckPhase"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pythonCatchConflictsPhase() {
@pythonInterpreter@ @catchConflicts@
}

if [ -z "$dontUsePythonCatchConflicts" ]; then
if [ -z "${dontUsePythonCatchConflicts-}" ]; then
preDistPhases+=" pythonCatchConflictsPhase"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pythonImportsCheckPhase () {
fi
}

if [ -z "$dontUsePythonImportsCheck" ]; then
if [ -z "${dontUsePythonImportsCheck-}" ]; then
echo "Using pythonImportsCheckPhase"
preDistPhases+=" pythonImportsCheckPhase"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pythonRemoveBinBytecodePhase () {
fi
}

if [ -z "$dontUsePythonRemoveBinBytecode" ]; then
if [ -z "${dontUsePythonRemoveBinBytecode-}" ]; then
preDistPhases+=" pythonRemoveBinBytecodePhase"
fi
Loading