server-configs/deploy.sh

30 lines
1.2 KiB
Bash
Raw Normal View History

2024-08-08 12:16:04 +00:00
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p jq nixos-anywhere
set -ex
USERNAME="root"
IP="gerd.fricloud.dk"
2024-08-14 10:22:33 +00:00
NIXPKGS=$(nix build --impure --json --expr '(import ./shared/sources).nixpkgs' | jq -r '.[].outputs.out')
NIXPKGS=$(nix eval --impure --json --expr '(import ./shared/sources/default.nix).nixpkgs.outPath' | jq -r)
2024-08-08 12:16:04 +00:00
export NIX_PATH="nixpkgs=$NIXPKGS"
if [ "$1" == "initial-deploy" ]; then
echo "Initial deployment..."
echo "Removed exit below if you really want... "
exit
2024-08-08 12:16:04 +00:00
NIX_TOP_LEVEL_PATH=$(nix build --impure -I nixos-config=./machines/gerd.nix --json --expr "(import <nixpkgs/nixos> {}).config.system.build.toplevel" | jq -r '.[].outputs.out')
NIX_DISKO_SCRIPT=$(nix build --impure -I nixos-config=./machines/gerd.nix --json --expr "(import <nixpkgs/nixos> {}).config.system.build.diskoScript" | jq -r '.[].outputs.out')
nixos-anywhere --store-paths "$NIX_DISKO_SCRIPT" "$NIX_TOP_LEVEL_PATH" "$USERNAME@$IP"
else
echo "Deploying..."
REBUILD_ACTION="switch"
if [ -n "$1" ]; then
REBUILD_ACTION="$1"
fi
nixos-rebuild \
-I nixos-config=./machines/gerd.nix \
"$REBUILD_ACTION" --target-host "$USERNAME@$IP"
fi