diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml
index 7dab5c69dfb5..1fd3a1c56648 100644
--- a/nixos/doc/manual/man-nixos-rebuild.xml
+++ b/nixos/doc/manual/man-nixos-rebuild.xml
@@ -52,10 +52,18 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -334,9 +342,23 @@
+
+
+
-
- Fetch the latest version of NixOS from the NixOS channel.
+
+ Update the root user's channel named nixos
+ before rebuilding the system.
+
+
+ In addition to the nixos channel, the root
+ user's channels which have a file named
+ .update-on-nixos-rebuild in their base
+ directory will also be updated.
+
+
+ Passing updates all of the root
+ user's channels.
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 909e8b229c8a..08813d17ff99 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -23,6 +23,7 @@ buildNix=1
fast=
rollback=
upgrade=
+upgrade_all=
repair=
profile=/nix/var/nix/profiles/system
buildHost=
@@ -55,6 +56,10 @@ while [ "$#" -gt 0 ]; do
--upgrade)
upgrade=1
;;
+ --upgrade-all)
+ upgrade=1
+ upgrade_all=1
+ ;;
--repair)
repair=1
extraBuildFlags+=("$i")
@@ -223,15 +228,22 @@ if [ "$action" = switch -o "$action" = boot -o "$action" = test ]; then
fi
-# If ‘--upgrade’ is given, run ‘nix-channel --update nixos’.
+# If ‘--upgrade’ or `--upgrade-all` is given,
+# run ‘nix-channel --update nixos’.
if [[ -n $upgrade && -z $_NIXOS_REBUILD_REEXEC && -z $flake ]]; then
- nix-channel --update nixos
+ # If --upgrade-all is passed, or there are other channels that
+ # contain a file called ".update-on-nixos-rebuild", update them as
+ # well. Also upgrade the nixos channel.
- # If there are other channels that contain a file called
- # ".update-on-nixos-rebuild", update them as well.
for channelpath in /nix/var/nix/profiles/per-user/root/channels/*; do
- if [ -e "$channelpath/.update-on-nixos-rebuild" ]; then
- nix-channel --update "$(basename "$channelpath")"
+ channel_name=$(basename "$channelpath")
+
+ if [[ "$channel_name" == "nixos" ]]; then
+ nix-channel --update "$channel_name"
+ elif [ -e "$channelpath/.update-on-nixos-rebuild" ]; then
+ nix-channel --update "$channel_name"
+ elif [[ -n $upgrade_all ]] ; then
+ nix-channel --update "$channel_name"
fi
done
fi