···
188
-
# FIXME: shouldn't this be done in network-link?
189
-
echo "bringing up interface..."
190
-
ip link set "${i.name}" up
188
+
state="/run/nixos/network/addresses/${i.name}"
189
+
mkdir -p $(dirname "$state")
192
-
state="/run/nixos/network/addresses/${i.name}"
191
+
${flip concatMapStrings ips (ip:
193
+
cidr = "${ip.address}/${toString ip.prefixLength}";
196
+
echo "${cidr}" >> $state
197
+
echo -n "adding address ${cidr}... "
198
+
if out=$(ip addr add "${cidr}" dev "${i.name}" 2>&1); then
200
+
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
207
+
state="/run/nixos/network/routes/${i.name}"
mkdir -p $(dirname "$state")
196
-
'' + flip concatMapStrings (ips) (ip:
198
-
address = "${ip.address}/${toString ip.prefixLength}";
201
-
echo "${address}" >> $state
202
-
if out=$(ip addr add "${address}" dev "${i.name}" 2>&1); then
203
-
echo "added ip ${address}"
204
-
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
205
-
echo "failed to add ${address}"
210
+
${flip concatMapStrings (i.ipv4Routes ++ i.ipv6Routes) (route:
212
+
cidr = "${route.address}/${toString route.prefixLength}";
213
+
nextHop = optionalString (route.nextHop != null) ''via "${route.nextHop}"'';
216
+
echo "${cidr}" >> $state
217
+
echo -n "adding route ${cidr}... "
218
+
if out=$(ip route add "${cidr}" ${route.options} ${nextHop} dev "${i.name}" 2>&1); then
220
+
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
228
+
state="/run/nixos/network/routes/${i.name}"
229
+
while read cidr; do
230
+
echo -n "deleting route $cidr... "
231
+
ip route del "$cidr" dev "${i.name}" >/dev/null 2>&1 && echo "done" || echo "failed"
state="/run/nixos/network/addresses/${i.name}"
211
-
while read address; do
212
-
echo -n "deleting $address..."
213
-
ip addr del "$address" dev "${i.name}" >/dev/null 2>&1 || echo -n " Failed"
236
+
while read cidr; do
237
+
echo -n "deleting address $cidr... "
238
+
ip addr del "$cidr" dev "${i.name}" >/dev/null 2>&1 && echo "done" || echo "failed"