about summary refs log tree commit diff stats
path: root/scripts/build.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-30 16:16:59 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-30 16:16:59 +0100
commit191b13a95500ae8a023ac816e7ff0319b3796a9c (patch)
tree4cbc75738a86abc43fd1c2add0c3baa17dee2330 /scripts/build.sh
parentmodules/{common,steam,nixpkgs}: Disable Steam (diff)
downloadnixos-config-191b13a95500ae8a023ac816e7ff0319b3796a9c.zip
scripts/why-depends: Init
Diffstat (limited to 'scripts/build.sh')
-rwxr-xr-xscripts/build.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100755
index 00000000..f3661978
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,59 @@
+#!/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-$(hostname)}"
+[ "$#" -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
+        rm "$file" || {
+            : "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 --option max-jobs 1 "$@")"
+    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"
+
+nvd diff /run/current-system "$SYSTEM_OUT"
+
+# vim: ft=sh