about summary refs log tree commit diff
path: root/nixos/modules/tasks
diff options
context:
space:
mode:
authorTomáš Kuča <tomas@kuca.cz>2024-05-17 01:02:29 +0200
committerTomáš Kuča <tomas@kuca.cz>2024-05-17 01:02:29 +0200
commit71ce6b582b473982c66eadc91081b5601dda7819 (patch)
treebd6f554619a4d4e3a6eab0dd58dbe9477f3c8226 /nixos/modules/tasks
parentea77cefecb0ab07e61d6bde3e24c7ae6820b96d5 (diff)
downloadnixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar.gz
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar.bz2
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar.lz
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar.xz
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.tar.zst
nixlib-71ce6b582b473982c66eadc91081b5601dda7819.zip
nixos/network-interfaces: prevent failure when a network address already exists
The original code tests output of `ip addr add` command to detect if an
adress already exists. The error message was changed in the past and the
test no longer works.

The patch replaces `ip addr add` with `ip addr replace`. The new command
replaces an existing address or creates a new one if there isn't any.

fixes 306841
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r--nixos/modules/tasks/network-interfaces-scripted.nix6
1 files changed, 3 insertions, 3 deletions
diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix
index 2f2d282fbefb..bbf2d337aac6 100644
--- a/nixos/modules/tasks/network-interfaces-scripted.nix
+++ b/nixos/modules/tasks/network-interfaces-scripted.nix
@@ -203,10 +203,10 @@ let
                   ''
                     echo "${cidr}" >> $state
                     echo -n "adding address ${cidr}... "
-                    if out=$(ip addr add "${cidr}" dev "${i.name}" 2>&1); then
+                    if out=$(ip addr replace "${cidr}" dev "${i.name}" 2>&1); then
                       echo "done"
-                    elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
-                      echo "'ip addr add "${cidr}" dev "${i.name}"' failed: $out"
+                    else
+                      echo "'ip addr replace "${cidr}" dev "${i.name}"' failed: $out"
                       exit 1
                     fi
                   ''