2021-08-21 16:47:21 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
|
|
if ! command -v nix-build &> /dev/null
|
|
|
|
then
|
|
|
|
echo "Nix installation could not be found. Please follow the instructions linked below."
|
|
|
|
echo "https://nixos.org/manual/nix/unstable/installation/installing-binary.html#multi-user-installation"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
mode="${1:-switch}"
|
2021-10-22 22:26:39 +00:00
|
|
|
host="${2:-nuc}"
|
2021-10-24 18:54:29 +00:00
|
|
|
target="${3:-c3h@$host.c3h}"
|
|
|
|
|
|
|
|
if ! [ -d "hosts/$host" ]
|
|
|
|
then
|
|
|
|
echo "Host $host does not exist. Choose from:"
|
|
|
|
ls hosts
|
|
|
|
exit
|
|
|
|
fi
|
2021-10-22 22:26:39 +00:00
|
|
|
|
|
|
|
echo "deploying $host to $target"
|
|
|
|
sleep 1
|
2021-08-21 16:47:21 +00:00
|
|
|
|
2021-10-24 18:54:29 +00:00
|
|
|
tmp=$(mktemp -d)
|
|
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
|
|
sources="$tmp/sources"
|
|
|
|
cp -r $(nix-build nix/sources-dir.nix --no-out-link) $tmp/sources
|
2021-08-21 16:47:21 +00:00
|
|
|
|
|
|
|
set -x
|
2021-10-24 18:54:29 +00:00
|
|
|
system_drv=$(nix-instantiate "<nixpkgs/nixos>" -A config.system.build.toplevel -I $sources -I "nixos-config=$PWD/hosts/$host/configuration.nix")
|
2021-10-22 22:26:39 +00:00
|
|
|
nix-copy-closure --to $target $system_drv
|
|
|
|
system=$(ssh $target "nix-store --realise $system_drv")
|
|
|
|
ssh $target "sudo nix-env -p /nix/var/nix/profiles/system -i $system && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $mode"
|