NixOS-Configs/deploy-host
2024-01-08 07:13:35 -06:00

34 lines
867 B
Bash
Executable file

#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
debug=echo
if [ "x" == "x$2" ]
then
echo "usage: $0 <ip> <host>"
exit 1
fi
nixanywhere=~/src/nixos/nixos-anywhere-examples
nixsrc=~/src/nixos/duckland
ip="${1}"
host="${2}"
if [ ! -f "${nixsrc}/hosts/${host}/default.nix" ]
then
echo "Please set up ${nixsrc}/hosts/${host}/default.nix before running"
exit 1
fi
cd "${nixanywhere}"
${debug} ssh-keygen -R "${ip}"
${debug} nix run github:nix-community/nixos-anywhere -- --flake .#${host} root@"${ip}"
cd "${nixsrc}"
${debug} ssh-keygen -R "${ip}"
${debug} ssh root@"${ip}" nixos-generate-config
${debug} scp root@"${ip}":/etc/nixos/hardware-configuration.nix hosts/${host}/hardware-configuration.nix
${debug} git add hosts/${host}/hardware-configuration.nix
${debug} nixos-rebuild switch --flake .#${host} --target-host "root@"${ip}""