server-configs/deploy.sh
2024-08-08 14:16:04 +02:00

27 lines
1 KiB
Bash
Executable file

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p jq nixos-anywhere
set -ex
USERNAME="root"
IP="gerd.fricloud.dk"
NIXPKGS=$(jq -r '.nixpkgs.url' ./shared/sources/sources.json)
export NIX_PATH="nixpkgs=$NIXPKGS"
if [ "$1" == "initial-deploy" ]; then
echo "Initial deployment..."
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"
# -I "nixpkgs=$(jq -r '.nixpkgs.url' ./shared/sources/sources.json)" \
fi