From 50672e10e87fa90f9ded5065aa4bc4ce0afaf730 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 25 Dec 2024 01:34:17 +0100 Subject: [WIP] Setup `deploy-rs` and add networking detection script --- scripts/deploy.sh | 3 +- scripts/mk_network_config.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100755 scripts/mk_network_config.sh (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 9d27e5a..00e9011 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,6 +11,7 @@ root="$(git rev-parse --show-toplevel)" nix run github:numtide/nixos-anywhere -- \ --flake ".#$host_name" \ --target-host "$ssh_url" \ - --generate-hardware-config nixos-facter "$root/hardware_config_$host_name.nix" + --generate-hardware-config nixos-generate-config "$root/hardware_config_$host_name.nix" \ + --generate-hardware-config nixos-facter "$root/hardware_config_$host_name.json" # vim: ft=sh diff --git a/scripts/mk_network_config.sh b/scripts/mk_network_config.sh new file mode 100755 index 0000000..d929530 --- /dev/null +++ b/scripts/mk_network_config.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +# Taken from: https://github.com/elitak/nixos-infect +set -e -o pipefail + +makeNetworkingConf() { + # XXX It'd be better if we used procfs for all this... + local IFS=$'\n' + eth0_name=$(ip address show | grep '^2:' | awk -F': ' '{print $2}') + eth0_ip4s=$(ip address show dev "$eth0_name" | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|') + eth0_ip6s=$(ip address show dev "$eth0_name" | grep 'inet6 ' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|' || true) + gateway=$(ip route show dev "$eth0_name" | grep default | sed -r 's|default via ([0-9.]+).*|\1|') + gateway6=$(ip -6 route show dev "$eth0_name" | grep default | sed -r 's|default via ([0-9a-f:]+).*|\1|' || true) + ether0=$(ip address show dev "$eth0_name" | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|') + + eth1_name=$(ip address show | grep '^3:' | awk -F': ' '{print $2}') || true + if [ -n "$eth1_name" ]; then + eth1_ip4s=$(ip address show dev "$eth1_name" | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|') + eth1_ip6s=$(ip address show dev "$eth1_name" | grep 'inet6 ' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|' || true) + ether1=$(ip address show dev "$eth1_name" | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|') + interfaces1=$( + cat <