gnu: weechat: Update to 1.7.
[jackhill/guix/guix.git] / tests / guix-daemon.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
3 #
4 # This file is part of GNU Guix.
5 #
6 # GNU Guix is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # GNU Guix is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 #
20 # Test the daemon and its interaction with 'guix substitute'.
21 #
22
23 set -e
24
25 guix-daemon --version
26 guix build --version
27
28 drv="`guix build emacs -d`"
29 out="`guile -c ' \
30 (use-modules (guix) (guix grafts) (gnu packages emacs)) \
31 (define store (open-connection)) \
32 (%graft? #f)
33 (display (derivation->output-path (package-derivation store emacs)))'`"
34
35 hash_part="`basename $out | cut -c 1-32`"
36 narinfo="$hash_part.narinfo"
37 substitute_dir="`echo $GUIX_BINARY_SUBSTITUTE_URL | sed -'es,file://,,g'`"
38
39 cat > "$substitute_dir/nix-cache-info"<<EOF
40 StoreDir: `dirname $drv`
41 WantMassQuery: 0
42 EOF
43
44 cat > "$substitute_dir/$narinfo"<<EOF
45 StorePath: $out
46 URL: /nowhere/example.nar
47 Compression: none
48 NarSize: 1234
49 References:
50 System: `guile -c '(use-modules (guix)) (display (%current-system))'`
51 Deriver: $drv
52 EOF
53
54 # Remove the cached narinfo.
55 rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
56
57 # Make sure we see the substitute.
58 guile -c "
59 (use-modules (guix))
60 (define store (open-connection))
61 (set-build-options store #:use-substitutes? #t
62 #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
63 (exit (has-substitutes? store \"$out\"))"
64
65 # Now, run guix-daemon --no-substitutes.
66 socket="$NIX_STATE_DIR/alternate-socket"
67 guix-daemon --no-substitutes --listen="$socket" --disable-chroot &
68 daemon_pid=$!
69 trap 'kill $daemon_pid' EXIT
70
71 # Make sure we DON'T see the substitute.
72 guile -c "
73 (use-modules (guix))
74 (define store (open-connection \"$socket\"))
75
76 ;; This setting MUST NOT override the daemon's --no-substitutes.
77 (set-build-options store #:use-substitutes? #t
78 #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
79
80 (exit (not (has-substitutes? store \"$out\")))"
81
82 kill "$daemon_pid"
83
84
85 # Check the failed build cache.
86
87 guix-daemon --no-substitutes --listen="$socket" --disable-chroot \
88 --cache-failures &
89 daemon_pid=$!
90
91 guile -c "
92 (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34))
93 (define store (open-connection-for-tests \"$socket\"))
94
95 ;; Disable grafts to avoid building more than needed.
96 (%graft? #f)
97
98 (define (build-without-failing drv)
99 (lambda (store)
100 (guard (c ((nix-protocol-error? c) (values #t store)))
101 (build-derivations store (list drv))
102 (values #f store))))
103
104 ;; Make sure failed builds are cached and can be removed from
105 ;; the cache.
106 (run-with-store store
107 (mlet* %store-monad ((drv (gexp->derivation \"failure\"
108 #~(begin
109 (ungexp output)
110 #f)))
111 (out -> (derivation->output-path drv))
112 (ok? (build-without-failing drv)))
113 ;; Note the mixture of monadic and direct style. Don't try
114 ;; this at home!
115 (return (exit (and ok?
116 (equal? (query-failed-paths store) (list out))
117 (begin
118 (clear-failed-paths store (list out))
119 (null? (query-failed-paths store)))))))
120 #:guile-for-build (%guile-for-build)) "