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

Fix some nixos-rebuild lints #147449

Merged
merged 3 commits into from
Nov 29, 2021
Merged
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
28 changes: 14 additions & 14 deletions pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! @runtimeShell@
# shellcheck shell=bash

if [ -x "@runtimeShell@" ]; then export SHELL="@runtimeShell@"; fi;

Expand Down Expand Up @@ -132,7 +133,7 @@ if [[ -n "$SUDO_USER" || -n $remoteSudo ]]; then
maybeSudo=(sudo --preserve-env="$preservedSudoVars" --)
fi

if [ -z "$buildHost" -a -n "$targetHost" ]; then
if [[ -z "$buildHost" && -n "$targetHost" ]]; then
buildHost="$targetHost"
fi
if [ "$targetHost" = localhost ]; then
Expand Down Expand Up @@ -217,8 +218,7 @@ nixBuild() {
}

nixFlakeBuild() {
if [[ -z "$buildHost" && -z "$targetHost" ]] &&
! [ "$action" = switch -o "$action" = boot ]
if [[ -z "$buildHost" && -z "$targetHost" && "$action" != switch && "$action" != boot ]]
then
nix "${flakeFlags[@]}" build "$@"
readlink -f ./result
Expand Down Expand Up @@ -273,7 +273,7 @@ if [ -z "$action" ]; then showSyntax; fi
# executed, so it's safe to run nixos-rebuild against a potentially
# untrusted tree.
canRun=
if [ "$action" = switch -o "$action" = boot -o "$action" = test ]; then
if [[ "$action" = switch || "$action" = boot || "$action" = test ]]; then
canRun=1
fi

Expand Down Expand Up @@ -377,7 +377,7 @@ trap cleanup EXIT

# First build Nix, since NixOS may require a newer version than the
# current one.
if [ -n "$rollback" -o "$action" = dry-build ]; then
if [[ -n "$rollback" || "$action" = dry-build ]]; then
buildNix=
fi

Expand Down Expand Up @@ -411,7 +411,7 @@ if [[ -n $buildNix && -z $flake ]]; then
if ! nixStorePath="$(nix-instantiate --eval '<nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix>' -A "$(nixSystem)" | sed -e 's/^"//' -e 's/"$//')"; then
nixStorePath="$(prebuiltNix "$(uname -m)")"
fi
if ! nix-store -r $nixStorePath --add-root $tmpDir/nix --indirect \
if ! nix-store -r "$nixStorePath" --add-root "${tmpDir}/nix" --indirect \
--option extra-binary-caches https://cache.nixos.org/; then
echo "warning: don't know how to get latest Nix" >&2
fi
Expand Down Expand Up @@ -464,15 +464,15 @@ fi
# current directory (for "build" and "test").
if [ -z "$rollback" ]; then
echo "building the system configuration..." >&2
if [ "$action" = switch -o "$action" = boot ]; then
if [[ "$action" = switch || "$action" = boot ]]; then
if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"
else
pathToConfig="$(nixFlakeBuild "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}")"
fi
copyToTarget "$pathToConfig"
targetHostCmd nix-env -p "$profile" --set "$pathToConfig"
elif [ "$action" = test -o "$action" = build -o "$action" = dry-build -o "$action" = dry-activate ]; then
elif [[ "$action" = test || "$action" = build || "$action" = dry-build || "$action" = dry-activate ]]; then
if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")"
else
Expand All @@ -494,14 +494,14 @@ if [ -z "$rollback" ]; then
showSyntax
fi
# Copy build to target host if we haven't already done it
if ! [ "$action" = switch -o "$action" = boot ]; then
if ! [[ "$action" = switch || "$action" = boot ]]; then
copyToTarget "$pathToConfig"
fi
else # [ -n "$rollback" ]
if [ "$action" = switch -o "$action" = boot ]; then
if [[ "$action" = switch || "$action" = boot ]]; then
targetHostCmd nix-env --rollback -p "$profile"
pathToConfig="$profile"
elif [ "$action" = test -o "$action" = build ]; then
elif [[ "$action" = test || "$action" = build ]]; then
systemNumber=$(
targetHostCmd nix-env -p "$profile" --list-generations |
sed -n '/current/ {g; p;}; s/ *\([0-9]*\).*/\1/; h'
Expand All @@ -518,17 +518,17 @@ fi

# If we're not just building, then make the new configuration the boot
# default and/or activate it now.
if [ "$action" = switch -o "$action" = boot -o "$action" = test -o "$action" = dry-activate ]; then
if [[ "$action" = switch || "$action" = boot || "$action" = test || "$action" = dry-activate ]]; then
if ! targetHostCmd "$pathToConfig/bin/switch-to-configuration" "$action"; then
echo "warning: error(s) occurred while switching to the new configuration" >&2
exit 1
fi
fi


if [ "$action" = build-vm -o "$action" = build-vm-with-bootloader ]; then
if [[ "$action" = build-vm || "$action" = build-vm-with-bootloader ]]; then
cat >&2 <<EOF

Done. The virtual machine can be started by running $(echo $pathToConfig/bin/run-*-vm)
Done. The virtual machine can be started by running $(echo "${pathToConfig}/bin/"run-*-vm)
EOF
fi