#! /bin/sh
#
# usage: nixos-deploy HOST [TARGET] [SYSTEM]
#
set -euf

host=$1
target=${2-root@$host}
system=${3-$(nixos-build "$host")}

nix-copy-closure --gzip --to "$target" "$system"

copy-secrets "$host"

ssh ${NIX_SSHOPTS-} "$target" "$system/bin/switch-to-configuration" switch