about summary refs log tree commit diff stats
path: root/scripts/why-depends
blob: 61f40c5d45227133908ceadce1adcc3e6d74a56f (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
#! /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 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

for package in $packages; do
    main "$running" "$host" "$package"
done

# vim: ft=sh