summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Ringer <jonringer117@gmail.com>2021-06-10 14:20:23 -0700
committerJonathan Ringer <jonringer117@gmail.com>2021-06-11 12:46:16 -0700
commitbf185eaa6935c4ab58f079a7a5c3e09ce5a123f9 (patch)
treefb297d3003c94309048e2fd3090993137b1d916a
parent2c31bc7f200b6a6db59787bd6ac6f9d48d69ed89 (diff)
downloadnixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar.gz
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar.bz2
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar.lz
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar.xz
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.tar.zst
nixpkgs-bf185eaa6935c4ab58f079a7a5c3e09ce5a123f9.zip
nixos-rebuild: add --use-substitutes option
-rw-r--r--nixos/doc/manual/man-nixos-rebuild.xml16
-rw-r--r--pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh12
2 files changed, 24 insertions, 4 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml
index 2e1069828c1..a129d31e1ed 100644
--- a/nixos/doc/manual/man-nixos-rebuild.xml
+++ b/nixos/doc/manual/man-nixos-rebuild.xml
@@ -537,6 +537,22 @@
 
    <varlistentry>
     <term>
+     <option>--use-substitutes</option>
+    </term>
+    <listitem>
+     <para>
+       When set, nixos-rebuild will add <option>--use-substitutes</option>
+       to each invocation of nix-copy-closure. This will only affect the
+       behavior of nixos-rebuild if <option>--target-host</option> or
+       <option>--build-host</option> is also set. This is useful when
+       the target-host connection to cache.nixos.org is faster than the
+       connection between hosts.
+     </para>
+    </listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term>
      <option>--use-remote-sudo</option>
     </term>
     <listitem>
diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
index 5522fa6a456..033bab8172e 100644
--- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
+++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
@@ -15,6 +15,7 @@ showSyntax() {
 
 # Parse the command line.
 origArgs=("$@")
+copyClosureFlags=()
 extraBuildFlags=()
 lockFlags=()
 flakeFlags=()
@@ -59,6 +60,9 @@ while [ "$#" -gt 0 ]; do
         upgrade=1
         upgrade_all=1
         ;;
+      -s|--use-substitutes)
+        copyClosureFlags+=("$i")
+        ;;
       --max-jobs|-j|--cores|-I|--builders)
         j="$1"; shift 1
         extraBuildFlags+=("$i" "$j")
@@ -156,11 +160,11 @@ targetHostCmd() {
 copyToTarget() {
     if ! [ "$targetHost" = "$buildHost" ]; then
         if [ -z "$targetHost" ]; then
-            NIX_SSHOPTS=$SSHOPTS nix-copy-closure --from "$buildHost" "$1"
+            NIX_SSHOPTS=$SSHOPTS nix-copy-closure "${copyClosureFlags[@]}" --from "$buildHost" "$1"
         elif [ -z "$buildHost" ]; then
-            NIX_SSHOPTS=$SSHOPTS nix-copy-closure --to "$targetHost" "$1"
+            NIX_SSHOPTS=$SSHOPTS nix-copy-closure "${copyClosureFlags[@]}" --to "$targetHost" "$1"
         else
-            buildHostCmd nix-copy-closure --to "$targetHost" "$1"
+            buildHostCmd nix-copy-closure "${copyClosureFlags[@]}" --to "$targetHost" "$1"
         fi
     fi
 }
@@ -419,7 +423,7 @@ if [[ -n $buildNix && -z $flake ]]; then
     if [ -a "$nixDrv" ]; then
         nix-store -r "$nixDrv"'!'"out" --add-root "$tmpDir/nix" --indirect >/dev/null
         if [ -n "$buildHost" ]; then
-            nix-copy-closure --to "$buildHost" "$nixDrv"
+            nix-copy-closure "${copyClosureFlags[@]}" --to "$buildHost" "$nixDrv"
             # The nix build produces multiple outputs, we add them all to the remote path
             for p in $(buildHostCmd nix-store -r "$(readlink "$nixDrv")" "${buildArgs[@]}"); do
                 remoteNix="$remoteNix${remoteNix:+:}$p/bin"