about summary refs log tree commit diff stats
path: root/build.sh
blob: de4d536cc98de54e4da2e39639f68120ca658b02 (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
#!/usr/bin/env sh

# nixos-config - My current NixOS configuration
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of my nixos-config.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.

host="${1-tiamat}"
[ "$#" -gt 0 ] && shift 1

root="$(git rev-parse --show-toplevel)"

SYSTEM_OUT="$root/result-system"
HOME_OUT="$root/result-home-soispha"

check() {
    file="$1"
    if [ -s "$file" ]; then
        rm "$file"
    elif ! [ -e "$file" ]; then
        : "Ignore not existing files"
    else
        echo "ERROR: '$file' is not a symlink. Not removing it." 1>&2
        exit 1
    fi
}

build_system() {
    _val="$(nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --print-out-paths --no-link "$@")"
    exit_val="$?"

    if [ "$exit_val" -ne 0 ]; then
        echo "ERROR: Failed to build you system config for host: '$host'" 1>&2
        printf 1
    else
        printf "%s" "$_val"
    fi
}

system="$(build_system "$@")"
[ "$system" = "1" ] && exit 1

check "$SYSTEM_OUT"
ln --symbolic "$system" "$SYSTEM_OUT"

home="$(grep ExecStart= "$SYSTEM_OUT/etc/systemd/system/home-manager-soispha.service" | awk '{print $2}')"
check "$HOME_OUT"
ln --symbolic "$home" "$HOME_OUT"

# vim: ft=sh