about summary refs log tree commit diff
path: root/scripts/nix-build.in
blob: cb7137a47bc37556da0d698af0e036ea132da15c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! @shell@ -e

nixExpr=$1

extraArgs=
addDrvLink=0
addOutLink=1


trap 'rm -f ./.nix-build-tmp-*' EXIT


# Process the arguments.
exprs=
for i in "$@"; do
    case "$i" in

        --help)
            echo "syntax: $0 [NIX-EXPR...]" >&2
            exit 0
            ;;

        --add-drv-link)
            addDrvLink=1
            ;;
            
        --no-link)
            addOutLink=0
            ;;
            
        -*)
            extraArgs="$extraArgs $i"
            ;;
            
        *)
            exprs="$exprs $i"
            ;;
    esac
done

if test -z "$exprs"; then
    exprs="./default.nix"
fi

# Process the specified Nix expressions.
for i in $exprs; do

    # Instantiate the Nix expression.
    prefix=
    if test "$addDrvLink" = 0; then prefix=.nix-build-tmp-; fi
    storeExprs=$(@bindir@/nix-instantiate \
        --add-root ./${prefix}derivation --indirect \
        "$i")
                
    for j in $storeExprs; do
        echo "store expression is $(readlink "$j")" >&2
    done

    # Build the resulting store derivation.
    prefix=
    if test "$addOutLink" = 0; then prefix=.nix-build-tmp-; fi
    outPaths=$(@bindir@/nix-store \
        --add-root ./${prefix}result --indirect \
        -rv $extraArgs $storeExprs)
                
    for j in $outPaths; do
        echo "$(readlink "$j")"
    done
done