forked from Yuka/c3h-nixfiles
26 lines
837 B
Bash
Executable file
26 lines
837 B
Bash
Executable file
#!/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}"
|
|
host="${2:-nuc}"
|
|
target="${3:-$host.c3h}"
|
|
|
|
echo "deploying $host to $target"
|
|
sleep 1
|
|
|
|
sources=$(nix-build nix/sources-dir.nix --no-out-link)
|
|
|
|
set -x
|
|
system_drv=$(nix-instantiate "<nixpkgs/nixos>" -I $sources -I "nixos-config=$PWD/hosts/$host/configuration.nix" | head -n1)
|
|
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 && /nix/var/nix/profiles/system/bin/switch-to-configuration $mode"
|