diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-05-28 21:45:41 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-05-28 21:55:04 +0200 |
| commit | 34fed7039acad89642f9f27a3796f1cf959e5d73 (patch) | |
| tree | 5a533155b1bd7e028147d382b734f96304b6c5fd /scripts/why-depends | |
| parent | update.sh: Exit, when an update command fails (diff) | |
| download | nixos-config-34fed7039acad89642f9f27a3796f1cf959e5d73.zip | |
scripts/why-depends: Correctly parse command line arguments
Diffstat (limited to 'scripts/why-depends')
| -rwxr-xr-x | scripts/why-depends | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/scripts/why-depends b/scripts/why-depends index 1afe9150..61f40c5d 100755 --- a/scripts/why-depends +++ b/scripts/why-depends @@ -1,23 +1,43 @@ #! /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 -if [ "$1" = "--running" ]; then - shift 1 - base="/run/current-system" -else - host="$(hostname)" - base=".#nixosConfigurations.$host.config.system.build.toplevel" -fi + fd "[a-zA-Z0-9]{32}-$package-" /nix/store --type directory --threads 1 --exec nix why-depends "$base" +} + +running=false +host="$(hostname)" +packages="" +while [ "$#" -ne 0 ]; do + case "$1" in + "--running") + running=true + ;; + "--host") + shift 1 + host="$1" + ;; + *) + # Treat everything else as a package to check + packages="$packages $1" + ;; + esac + + shift 1 +done -fd "$search_string" /nix/store --type directory --threads 1 --exec nix why-depends "$@" "$base" +for package in $packages; do + main "$running" "$host" "$package" +done # vim: ft=sh |
