aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/npins_to_unflake.jq34
-rwxr-xr-xscripts/unflake.sh21
-rwxr-xr-xscripts/why-depends61
3 files changed, 102 insertions, 14 deletions
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..2404260a
--- /dev/null
+++ b/scripts/unflake.sh
@@ -0,0 +1,21 @@
+#! /usr/bin/env sh
+
+set -e
+
+# HACK(@bpeetz): unflake doesn't support npins version 8 yet, so we pretend to still use
+# version 7.
+# Essentially, we are abusing the fact that `npins` will look at `NPINS_DIRECTORY` while
+# unflake doesn't.
+# <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
index 1afe9150..ae1ac6f7 100755
--- a/scripts/why-depends
+++ b/scripts/why-depends
@@ -1,23 +1,56 @@
#! /usr/bin/env sh
-search_string="$1-"
-shift 1
+main() {
+ use_running="$1"
+ host="$2"
+ package="$3"
-if [ "$1" != "" ]; then
- # Add the version
- search_string="${search_string}${1}$"
- shift 1
-fi
+ 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
-if [ "$1" = "--running" ]; then
shift 1
- base="/run/current-system"
-else
- host="$(hostname)"
- base=".#nixosConfigurations.$host.config.system.build.toplevel"
-fi
+done
+if [ -n "$packages" ]; then
+ for package in $packages; do
+ main "$running" "$host" "$package-"
+ done
+fi
-fd "$search_string" /nix/store --type directory --threads 1 --exec nix why-depends "$@" "$base"
+if [ -n "$direct_packages" ]; then
+ for package in $direct_packages; do
+ main "$running" "$host" "$package-[0-9]"
+ done
+fi
# vim: ft=sh