updates to deploy-host

This commit is contained in:
Don Harper 2024-09-18 16:37:37 -05:00
parent c5a7131ced
commit 427ee38d7a
2 changed files with 25 additions and 14 deletions

View file

@ -4,7 +4,7 @@ set -o errexit
set -o errtrace set -o errtrace
# set -o nounset # set -o nounset
debug=echo # debug=echo
if [ "x" == "x$2" ] if [ "x" == "x$2" ]
then then
@ -14,22 +14,32 @@ fi
nixanywhere=~/nixos/nixos-anywhere nixanywhere=~/nixos/nixos-anywhere
nixsrc=~/nixos nixsrc=~/nixos
ip="${1}" ip=${1}
host="${2}" host=${2}
if [ ! -f "${nixsrc}/hosts/${host}/default.nix" ] if [ ! -f ${nixsrc}/hosts/${host}/default.nix ]
then then
echo "Please set up ${nixsrc}/hosts/${host}/default.nix before running" echo "Please set up ${nixsrc}/hosts/${host}/default.nix before running"
exit 1 exit 1
fi fi
${debug} cd "${nixanywhere}" cd ${nixanywhere}
${debug} ssh-keygen -R "${ip}" ssh-keygen -R ${ip}
${debug} nix run github:nix-community/nixos-anywhere -- --flake .#${host} root@"${ip}" nix run github:nix-community/nixos-anywhere -- --flake .#${host} root@${ip}
${debug} cd "${nixsrc}" cd ${nixsrc}
${debug} ssh-keygen -R "${ip}" sleep 5
${debug} ssh root@"${ip}" nixos-generate-config until ping -c1 ${ip}
${debug} scp root@"${ip}":/etc/nixos/hardware-configuration.nix hosts/${host}/hardware-configuration.nix do
${debug} git add hosts/${host}/hardware-configuration.nix sleep 5
${debug} nixos-rebuild switch --flake .#${host} --target-host "root@"${ip}"" done
${debug} rsync -av ~/.ssh ~/bin don@"${ip}": ssh-keygen -R ${ip}
ssh -o StrictHostKeyChecking=accept-new root@${ip} nixos-generate-config
scp root@${ip}:/etc/nixos/hardware-configuration.nix hosts/${host}/hardware-configuration.nix
git add hosts/${host}/hardware-configuration.nix
nixos-rebuild switch --flake .#${host} --target-host root@${ip}
sleep 5
until ping -c1 ${ip}
do
sleep 5
done
rsync -av ~/.ssh ~/bin don@${ip}:

View file

@ -59,6 +59,7 @@
"vm.swappiness" = 10; "vm.swappiness" = 10;
}; };
}; };
};
services.openssh.enable = true; services.openssh.enable = true;