blob: 62e8878e68e48d14de48282a3acdd11fead56026 (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/bin/sh
# -*- mode: sh; -*-
# nixup: Deploy a nix flake from the current directory to a remote host.
set -eu
# Make a quick check to see if there is a flake in the current directory
# with deploy-rs as an input.
if [ ! "$(find . -maxdepth 0 -name 'flake.nix')" ] &&
! grep -q 'deploy-rs' ./flake.nix; then
echo "Could not find a flake with 'deploy-rs' in the current directory" >&2
exit 1
fi
# By default build the configuration on the remote host.
BUILD_LOCAL=false
while getopts ":hl" arg; do
case "$arg" in
l) BUILD_LOCAL=true ;;
h) echo "Usage: nixup [-h] [-l] HOST" >&2
exit 1
;;
*) printf "Invalid option: -%s\nSee '-h' for usage\n" "$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ "$#" -ne 1 ]; then
echo "Please specify a host. See '-h' for usage" >&2
exit 1
fi
deploy_args=".#$1 -s --auto-rollback false"
if [ "$BUILD_LOCAL" != true ]; then
deploy_args="$deploy_args --remote-build"
fi
# Deploy the configuration.
deploy $deploy_args
# Copy the flake to the remote host.
rsync -ax --delete ./ "$1":/etc/nixos/
|