summaryrefslogtreecommitdiffstats
path: root/nix-script-download-sources.sh
blob: 061f3121e41bb91bc420ec595b86e0d32d4a0a7a (plain)
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
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash

source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh

usage() {
    cat <<EOS
    $(help_synopsis "${BASH_SOURCE[0]}" "[-h] -p <pkg>")

        -p <pkg> | Package to download source and deps for
        -Q       | No build output
        -h       | Show this help and exit

    Download sources for the package <pkg>, so we can disconnect
    from the internet before building it.

$(help_end)
EOS
}

PACKAGE=""

while getopts "p:Qh" OPTION
do
    case $OPTION in
        p)
            PACKAGE=$OPTARG
            dbg "PACKAGE = $PACKAGE"
            ;;

        Q)
            NO_BUILD_OUTPUT=1
            dbg "NO_BUILD_OUTPUT = $NO_BUILD_OUTPUT"
            ;;

        h)
            usage
            exit 1
            ;;
    esac
done

[[ -z "$PACKAGE" ]] && stderr "No package passed" && usage && exit 1

continue_question "Install sources for package '$PACKAGE'"

drvs=$(nix-store -qR $(nix-instantiate '<nixpkgs>' -A $PACKAGE) | grep '.drv$')

ARGS=""
[[ $NO_BUILD_OUTPUT -eq 1 ]] && ARGS="-Q"

nix-store $ARGS -r $(grep -l outputHash $drv)