aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build.sh59
-rw-r--r--scripts/npins_to_unflake.jq34
-rwxr-xr-xscripts/unflake.sh18
-rwxr-xr-xscripts/why-depends56
4 files changed, 167 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
diff --git a/scripts/npins_to_unflake.jq b/scripts/npins_to_unflake.jq
new file mode 100644
index 00000000..80e6b5a3
--- /dev/null
+++ b/scripts/npins_to_unflake.jq
@@ -0,0 +1,34 @@
+def make_url(value):
+ value.repository as $repo |
+ if value.type == "Git" then
+ if $repo.type == "Git" then
+ "git+\($repo.url)?ref=\(value.branch)"
+ elif $repo.type == "GitHub" then
+ "github:\($repo.owner)/\($repo.repo)/\(value.branch)"
+ elif $repo.type == "Forgejo" then
+ "git+\($repo.server)/\($repo.owner)/\($repo.repo)?ref=\(value.branch)"
+ else
+ error("Invalid repository type: '\($repo.type)'")
+ end
+ elif value.type == "GitRelease" then
+ if $repo.type == "GitHub" then
+ "github:\($repo.owner)/\($repo.repo)/\(value.version)"
+ else
+ error("Invalid repository type: '\($repo.type)'")
+ end
+ elif value.type == "Channel" then
+ empty
+ else
+ error("Invalid value type: '\(value.type)'")
+ end
+ ;
+
+"{
+\(
+ .pins | to_entries | map(
+ " \"\(.key)\" = {
+ url = \"\(make_url(.value))\";
+ };"
+ ) | join("\n")
+ )
+}"
diff --git a/scripts/unflake.sh b/scripts/unflake.sh
new file mode 100755
index 00000000..b46df36e
--- /dev/null
+++ b/scripts/unflake.sh
@@ -0,0 +1,18 @@
+#! /usr/bin/env sh
+
+set -e
+
+# HACK(@bpeetz): unflake doesn't support npins version 8 yet, so we pretend to still use
+# version 7. <2026-06-13>
+NPINS_DIRECTORY="$(mktemp -t "npins_fake_dir_for_unflake_XXXXX" -d)"
+export NPINS_DIRECTORY
+
+mv npins/sources.json "$NPINS_DIRECTORY/"
+jq '.version = 7' <"$NPINS_DIRECTORY/sources.json" >npins/sources.json
+
+NIX_CONFIG="pure-eval = false" nix run -f https://codeberg.org/goldstein/unflake/archive/main.tar.gz unflake -- "$@"
+
+mv "$NPINS_DIRECTORY/sources.json" npins/sources.json
+rmdir "$NPINS_DIRECTORY"
+
+# vim: ft=sh
diff --git a/scripts/why-depends b/scripts/why-depends
new file mode 100755
index 00000000..ae1ac6f7
--- /dev/null
+++ b/scripts/why-depends
@@ -0,0 +1,56 @@
+#! /usr/bin/env sh
+
+main() {
+ use_running="$1"
+ host="$2"
+ package="$3"
+
+ if [ "$use_running" = "true" ]; then
+ base="/run/current-system"
+ else
+ base=".#nixosConfigurations.$host.config.system.build.toplevel"
+ fi
+
+ fd "[a-zA-Z0-9]{32}-$package" /nix/store --type directory --threads 1 --exec nix --option warn-dirty false why-depends "$base"
+}
+
+running=false
+host="$(hostname)"
+packages=""
+direct_packages=""
+
+while [ "$#" -ne 0 ]; do
+ case "$1" in
+ "--running")
+ running=true
+ ;;
+ "--host")
+ shift 1
+ host="$1"
+ ;;
+ "--direct")
+ shift 1
+ direct_packages="$direct_packages $1"
+ ;;
+ *)
+ # Treat everything else as a package to check
+ packages="$packages $1"
+ ;;
+ esac
+
+ shift 1
+done
+
+if [ -n "$packages" ]; then
+ for package in $packages; do
+ main "$running" "$host" "$package-"
+ done
+fi
+
+if [ -n "$direct_packages" ]; then
+ for package in $direct_packages; do
+ main "$running" "$host" "$package-[0-9]"
+ done
+fi
+
+# vim: ft=sh