-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·34 lines (24 loc) · 1021 Bytes
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p nix-output-monitor
# Exit on any error
set -e
# Check for the correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <hostname> <ssh_user@ip>"
exit 1
fi
# Assign input arguments to variables
HOSTNAME=$1
SSH_DESTINATION=$2
# Build the system configuration
nom build .#nixosConfigurations."$HOSTNAME".config.system.build.toplevel
# Extract the store path from the result
STORE_PATH=$(readlink -f ./result)
# Copy the built system to the target machine
nix copy --substitute-on-destination --to ssh://"$SSH_DESTINATION" "$STORE_PATH"
# Switch to the new config
ssh "$SSH_DESTINATION" "sudo $STORE_PATH/bin/switch-to-configuration switch"
# Set the nix profile to the new system
ssh "$SSH_DESTINATION" "sudo nix-env --profile /nix/var/nix/profiles/system --set $STORE_PATH"
# I need this to get a new systemd-boot entry, I didn't think I would need this though
ssh "$SSH_DESTINATION" "sudo /run/current-system/bin/switch-to-configuration boot"