From 005382f7a36e571d3715c74f7f0891157490c7d6 Mon Sep 17 00:00:00 2001 From: Don Harper Date: Mon, 8 Jan 2024 07:13:35 -0600 Subject: [PATCH] new script to run nix-anywhere on a victim --- deploy-host | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 deploy-host diff --git a/deploy-host b/deploy-host new file mode 100755 index 0000000..0fccb9f --- /dev/null +++ b/deploy-host @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -o errexit +set -o errtrace +set -o nounset + +debug=echo + +if [ "x" == "x$2" ] +then + echo "usage: $0 " + 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}""