aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/build.sh
blob: b2e0e0673b0467bf784597fe25cc6f2ab7b3126b (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env sh

set -eu

root="$(git rev-parse --show-toplevel)"
wrong_arg=false
use_dirty=true
show_trace=false

for arg in "$@"; do
    case "$arg" in
    --dirty)
        use_dirty=true
        ;;
    --clean)
        use_dirty=false
        ;;
    --show-trace)
        show_trace=true
        ;;
    *)
        echo "arg '$arg' is not known."
        wrong_arg=true
        ;;
    esac
done

if [ "$wrong_arg" = true ]; then
    exit 2
fi

if [ "$use_dirty" = "false" ]; then
    tmp="$(mktemp -d -t "server_build_script_XXXXX")"
    trap 'rm -r "$tmp"' EXIT

    git archive --format=tar.gz HEAD | {
        cd "$tmp"
        tar -xz
    }

    cd "$tmp"
fi

for host in "server2" "server3"; do
    show_trace_arg=""
    if [ "$show_trace" = true ]; then
        show_trace_arg="--show-trace"
    fi

    nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --print-out-paths --option max-jobs 1 $show_trace_arg

    result_file="$root/result-$host"
    if [ -L "$result_file" ]; then
        rm "$result_file"
    fi
    nix-store --add-root "$result_file" --realise "$(readlink -f ./result)"
    rm ./result
done

# vim: ft=sh