Merge pull request #312317 from tom-kuca/replace-existing-network-addresses

nixos/network-interfaces: prevent failure when a network address already exists
This commit is contained in:
Michele Guerini Rocco 2024-06-03 15:30:13 +02:00 committed by GitHub
commit 9e97770a19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -203,10 +203,10 @@ let
'' ''
echo "${cidr}" >> $state echo "${cidr}" >> $state
echo -n "adding address ${cidr}... " 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" echo "done"
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then else
echo "'ip addr add "${cidr}" dev "${i.name}"' failed: $out" echo "'ip addr replace "${cidr}" dev "${i.name}"' failed: $out"
exit 1 exit 1
fi fi
'' ''