gnu: xdg-utils: Propagate xprop and xset.
[jackhill/guix/guix.git] / tests / guix-daemon.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2014, 2015 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) (gnu packages emacs)) \
31 (define store (open-connection)) \
32 (display (derivation->output-path (package-derivation store emacs)))'`"
33
34 hash_part="`basename $out | cut -c 1-32`"
35 narinfo="$hash_part.narinfo"
36 substitute_dir="`echo $GUIX_BINARY_SUBSTITUTE_URL | sed -'es,file://,,g'`"
37
38 cat > "$substitute_dir/nix-cache-info"<<EOF
39 StoreDir: `dirname $drv`
40 WantMassQuery: 0
41 EOF
42
43 cat > "$substitute_dir/$narinfo"<<EOF
44 StorePath: $out
45 URL: /nowhere/example.nar
46 Compression: none
47 NarSize: 1234
48 References:
49 System: `guile -c '(use-modules (guix)) (display (%current-system))'`
50 Deriver: $drv
51 EOF
52
53 # Remove the cached narinfo.
54 rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
55
56 # Make sure we see the substitute.
57 guile -c "
58 (use-modules (guix))
59 (define store (open-connection))
60 (set-build-options store #:use-substitutes? #t
61 #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
62 (exit (has-substitutes? store \"$out\"))"
63
64 # Now, run guix-daemon --no-substitutes.
65 socket="$NIX_STATE_DIR/alternate-socket"
66 guix-daemon --no-substitutes --listen="$socket" --disable-chroot &
67 daemon_pid=$!
68 trap 'kill $daemon_pid' EXIT
69
70 # Make sure we DON'T see the substitute.
71 guile -c "
72 (use-modules (guix))
73 (define store (open-connection \"$socket\"))
74
75 ;; This setting MUST NOT override the daemon's --no-substitutes.
76 (set-build-options store #:use-substitutes? #t
77 #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
78
79 (exit (not (has-substitutes? store \"$out\")))"
80
81 kill "$daemon_pid"
82
83
84 # Check the failed build cache.
85
86 guix-daemon --no-substitutes --listen="$socket" --disable-chroot \
87 --cache-failures &
88 daemon_pid=$!
89
90 guile -c "
91 (use-modules (guix) (guix tests) (srfi srfi-34))
92 (define store (open-connection-for-tests \"$socket\"))
93
94 (define (build-without-failing drv)
95 (lambda (store)
96 (guard (c ((nix-protocol-error? c) (values #t store)))
97 (build-derivations store (list drv))
98 (values #f store))))
99
100 ;; Make sure failed builds are cached and can be removed from
101 ;; the cache.
102 (run-with-store store
103 (mlet* %store-monad ((drv (gexp->derivation \"failure\"
104 #~(begin
105 (ungexp output)
106 #f)))
107 (out -> (derivation->output-path drv))
108 (ok? (build-without-failing drv)))
109 ;; Note the mixture of monadic and direct style. Don't try
110 ;; this at home!
111 (return (exit (and ok?
112 (equal? (query-failed-paths store) (list out))
113 (begin
114 (clear-failed-paths store (list out))
115 (null? (query-failed-paths store)))))))
116 #:guile-for-build (%guile-for-build)) "