55 lines
1.8 KiB
Plaintext
55 lines
1.8 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
set -xeuo pipefail
|
||
|
if ! [ -e secrets.nix ]
|
||
|
then
|
||
|
git crypt unlock
|
||
|
fi
|
||
|
export NIX_PATH=yori-nix=$PWD
|
||
|
host=$1
|
||
|
TARGET_HOST=$(nix eval --raw -f vpn.nix ips.$host)
|
||
|
#TARGET_HOST=192.168.178.1
|
||
|
case $2 in
|
||
|
copy-keys)
|
||
|
nix build -f servers.nix "$host".config.deployment.keys-copy --out-link copy-keys
|
||
|
./copy-keys/bin/copy-keys "$TARGET_HOST"
|
||
|
# rm ./copy-keys
|
||
|
;;
|
||
|
exec)
|
||
|
CHANNEL=$(jq -r ".$2.pkgs"<servers.json)
|
||
|
channel_url=$(get_channel "$CHANNEL")
|
||
|
export NIX_PATH="$channel_url:nixos-config=$PWD/logical/$2.nix:$NIX_PATH"
|
||
|
"${@:3}"
|
||
|
;;
|
||
|
ssh)
|
||
|
ssh root@"$TARGET_HOST"
|
||
|
;;
|
||
|
repl)
|
||
|
exec "$0" exec "$2" nix repl '<nixpkgs>' '<nixpkgs/nixos>'
|
||
|
;;
|
||
|
build)
|
||
|
nix build -f servers.nix "$host" --show-trace
|
||
|
;;
|
||
|
copy)
|
||
|
nix copy -f servers.nix "$host" --show-trace --to "ssh://$TARGET_HOST"
|
||
|
;;
|
||
|
test)
|
||
|
outPath=$(nix-build servers.nix -A "$host")
|
||
|
nix copy -f servers.nix "$host" --show-trace --to "ssh://$TARGET_HOST"
|
||
|
ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration test
|
||
|
;;
|
||
|
boot)
|
||
|
outPath=$(nix-build servers.nix -A "$host")
|
||
|
nix copy "$outPath" --show-trace --to "ssh://$TARGET_HOST"
|
||
|
ssh root@"$TARGET_HOST" nix-env -p "/nix/var/nix/profiles/system" --set "$outPath"
|
||
|
ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration boot
|
||
|
;;
|
||
|
switch)
|
||
|
outPath=$(nix-build servers.nix -A "$host")
|
||
|
nix copy "$outPath" --show-trace --to "ssh://$TARGET_HOST"
|
||
|
ssh root@"$TARGET_HOST" nix-env -p "/nix/var/nix/profiles/system" --set "$outPath"
|
||
|
ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration switch
|
||
|
;;
|
||
|
|
||
|
|
||
|
esac
|