dotfiles/nixos/conf

68 lines
2.0 KiB
Plaintext
Raw Normal View History

2016-01-28 02:59:31 +01:00
#!/usr/bin/env bash
2021-11-15 12:59:44 +01:00
set -euo pipefail
cd "$( dirname "${BASH_SOURCE[0]}" )"
export NIX_PATH=
2020-05-21 17:39:38 +02:00
host=$1
2021-10-19 11:16:42 +02:00
COPY_USER=yorick
2021-11-15 12:59:44 +01:00
decrypt() {
if ! [ -e secrets.nix ]
then
git crypt unlock
fi
}
get_target_host() {
TARGET_HOST=$(nix eval --raw -f vpn.nix ips.$host)
TARGET_HOST=$(ssh $TARGET_HOST ip --json r get 1.1.1.1 | jq -r '.[0].prefsrc')
}
peek() {
echo $ "$@" > /dev/stderr
command "$@"
}
nix() {
decrypt
2021-11-15 21:08:11 +01:00
peek nix --extra-experimental-features nix-command "$@"
2021-11-15 12:59:44 +01:00
}
nix-build() {
decrypt
peek nix-build "$@"
}
2020-05-21 17:39:38 +02:00
case $2 in
2018-03-11 23:18:22 +01:00
copy-keys)
2021-10-19 11:16:42 +02:00
nix build -f ../. yorick.machine."$host".config.deployment.keys-copy --out-link copy-keys
2021-11-15 12:59:44 +01:00
get_target_host
peek ./copy-keys/bin/copy-keys "$TARGET_HOST"
2018-03-11 23:18:22 +01:00
# rm ./copy-keys
;;
ssh)
2021-11-15 12:59:44 +01:00
get_target_host
peek ssh root@"$TARGET_HOST"
2018-03-11 23:18:22 +01:00
;;
build)
2020-05-21 17:39:38 +02:00
nix build -f servers.nix "$host" --show-trace
2018-03-11 23:18:22 +01:00
;;
2018-03-11 23:30:05 +01:00
copy)
2021-11-15 12:59:44 +01:00
get_target_host
2021-10-19 11:16:42 +02:00
nix copy -f servers.nix "$host" --show-trace --to "ssh://$COPY_USER@$TARGET_HOST"
2020-05-21 17:39:38 +02:00
;;
test)
2021-11-15 12:59:44 +01:00
get_target_host
2020-05-21 17:39:38 +02:00
outPath=$(nix-build servers.nix -A "$host")
2021-10-19 11:16:42 +02:00
nix copy -f servers.nix "$host" --show-trace --to "ssh://$COPY_USER@$TARGET_HOST"
2021-11-15 12:59:44 +01:00
peek ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration test
2018-03-11 23:30:05 +01:00
;;
2018-03-11 23:18:22 +01:00
boot)
2021-11-15 12:59:44 +01:00
get_target_host
2020-05-21 17:39:38 +02:00
outPath=$(nix-build servers.nix -A "$host")
2021-10-19 11:16:42 +02:00
nix copy "$outPath" --show-trace --to "ssh://$COPY_USER@$TARGET_HOST"
2021-11-15 12:59:44 +01:00
peek ssh root@"$TARGET_HOST" nix-env -p "/nix/var/nix/profiles/system" --set "$outPath"
peek ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration boot
2018-03-11 23:18:22 +01:00
;;
switch)
2021-11-15 12:59:44 +01:00
get_target_host
2020-05-21 17:39:38 +02:00
outPath=$(nix-build servers.nix -A "$host")
2021-10-19 11:16:42 +02:00
nix copy "$outPath" --show-trace --to "ssh://$COPY_USER@$TARGET_HOST"
2021-11-15 12:59:44 +01:00
peek ssh root@"$TARGET_HOST" nix-env -p "/nix/var/nix/profiles/system" --set "$outPath"
peek ssh root@"$TARGET_HOST" $outPath/bin/switch-to-configuration switch
2018-03-11 23:18:22 +01:00
;;
2016-01-28 02:59:31 +01:00
esac