NixOS-Configs/deploy-host
2024-09-17 16:36:39 -05:00

35 lines
932 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/duckland/nixos-anywhere
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
${debug} cd "${nixanywhere}"
${debug} ssh-keygen -R "${ip}"
${debug} nix run github:nix-community/nixos-anywhere -- --flake .#${host} root@"${ip}"
${debug} 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}""
${debug} rsync -av ~/.ssh ~/bin don@"${ip}":