forked from fediversity/fediversity
16 lines
1.1 KiB
Bash
Executable file
16 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -uex -o pipefail
|
|
declare domain hostname config initialUser
|
|
eval "$(jq -r '@sh "domain=\(.domain) hostname=\(.hostname) config=\(.config) initialUser=\(.initialUser)"')"
|
|
TARGET_HOST="${hostname}.abundos.eu"
|
|
TARGET="root@${TARGET_HOST}"
|
|
wrapper="$(mktemp -d)/wrapper.nix"
|
|
echo "(import $(readlink -f "./${config}.nix")).extendModules { specialArgs.terraform = { domain = \"${domain}\"; hostname = \"${hostname}\"; initialUser = builtins.fromJSON ''${initialUser}''; }; }" > "$wrapper"
|
|
NIXOS_SYSTEM=$(nix build --no-link --json --option show-trace true --file "$wrapper" "config.system.build.toplevel" | jq -r '.[].outputs.out')
|
|
sshOpts=(-p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no)
|
|
NIX_SSHOPTS="${sshOpts[*]}" nix copy -s --experimental-features nix-command --to "ssh://$TARGET" "$NIXOS_SYSTEM"
|
|
switchCommand="nix-env -p /nix/var/nix/profiles/system --set $(printf "%q" "$NIXOS_SYSTEM"); /nix/var/nix/profiles/system/bin/switch-to-configuration switch"
|
|
deploy_status=0
|
|
# shellcheck disable=SC2029
|
|
ssh "${sshOpts[@]}" "$TARGET" "$switchCommand" || deploy_status="$?"
|
|
exit "$deploy_status"
|