aboutsummaryrefslogtreecommitdiff
path: root/scripts/nix-build.in
blob: 33fbc61a3d20a2f085217b7f064ed69b78199824 (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
#! @shell@ -e

nixExpr=$1

if test -z "$nixExpr"; then
    echo "syntax: $0 NIX-EXPR..." >&2
    exit 1
fi

extraArgs=
noLink=

userName=$USER
if test -z "$username"; then userName="unknown"; fi

for i in "$@"; do
    case "$i" in
        --no-link)
            noLink=1
            ;;
        -*)
            extraArgs="$extraArgs $i"
            ;;
        *)
            storeExprs=$(@bindir@/nix-instantiate \
                --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-drv" \
                "$i")
            for j in $storeExprs; do
                echo "store expression is $j" >&2
            done
            outPaths=$(@bindir@/nix-store \
                --add-root "@localstatedir@/nix/gcroots/nix-build/$userName-out" \
                -rv $extraArgs $storeExprs)
            for j in $outPaths; do
                echo "$j"
                if test -z "$noLink"; then
                    if test -L result; then
                        rm result
                    elif test -e result; then
                        echo "cannot remove \`result' (not a symlink)"
                        exit 1
                    fi
                    ln -s "$j" result
                fi
            done
            ;;
    esac
done