locale: Add 'glibc-supported-locales'.
[guix.git] / tests / guix-daemon.sh
blobce82cfd1e6cef0b0e560f34654e91b42ca752d17
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
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.
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.
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/>.
20 # Test the daemon and its interaction with 'guix substitute'.
23 set -e
25 guix-daemon --version
26 guix build --version
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)))'`"
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'`"
39 cat > "$substitute_dir/nix-cache-info"<<EOF
40 StoreDir: `dirname $drv`
41 WantMassQuery: 0
42 EOF
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
54 # Remove the cached narinfo.
55 rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
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\"))"
65 # Now, run guix-daemon --no-substitutes.
66 socket="$GUIX_STATE_DIRECTORY/alternate-socket"
67 guix-daemon --no-substitutes --listen="$socket" --disable-chroot &
68 daemon_pid=$!
69 trap 'kill $daemon_pid' EXIT
71 # Make sure we DON'T see the substitute.
72 guile -c "
73 (use-modules (guix))
74 (define store (open-connection \"$socket\"))
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\"))
80 (exit (not (has-substitutes? store \"$out\")))"
82 kill "$daemon_pid"
84 # Pass several '--listen' options, and make sure they are all honored.
85 guix-daemon --disable-chroot --listen="$socket" --listen="$socket-second" \
86 --listen="localhost" --listen="localhost:9876" &
87 daemon_pid=$!
89 for uri in "$socket" "$socket-second" \
90 "guix://localhost" "guix://localhost:9876"
92 GUIX_DAEMON_SOCKET="$uri" guix build guile-bootstrap
93 done
95 kill "$daemon_pid"
97 # Check the failed build cache.
99 guix-daemon --no-substitutes --listen="$socket" --disable-chroot \
100 --cache-failures &
101 daemon_pid=$!
103 guile -c "
104 (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34))
105 (define store (open-connection-for-tests \"$socket\"))
107 ;; Disable grafts to avoid building more than needed.
108 (%graft? #f)
110 (define (build-without-failing drv)
111 (lambda (store)
112 (guard (c ((store-protocol-error? c) (values #t store)))
113 (build-derivations store (list drv))
114 (values #f store))))
116 ;; Make sure failed builds are cached and can be removed from
117 ;; the cache.
118 (run-with-store store
119 (mlet* %store-monad ((drv (gexp->derivation \"failure\"
120 #~(begin
121 (ungexp output)
122 #f)))
123 (out -> (derivation->output-path drv))
124 (ok? (build-without-failing drv)))
125 ;; Note the mixture of monadic and direct style. Don't try
126 ;; this at home!
127 (return (exit (and ok?
128 (equal? (query-failed-paths store) (list out))
129 (begin
130 (clear-failed-paths store (list out))
131 (null? (query-failed-paths store)))))))
132 #:guile-for-build (%guile-for-build)) "
134 kill "$daemon_pid"
137 # Make sure the daemon's default 'build-cores' setting is honored.
139 guix-daemon --listen="$socket" --disable-chroot --cores=42 &
140 daemon_pid=$!
142 GUIX_DAEMON_SOCKET="$socket" \
143 guile -c '
144 (use-modules (guix) (gnu packages) (guix tests))
146 (with-store store
147 (let* ((build (add-text-to-store store "build.sh"
148 "echo $NIX_BUILD_CORES > $out"))
149 (bash (add-to-store store "bash" #t "sha256"
150 (search-bootstrap-binary "bash"
151 (%current-system))))
152 (drv (derivation store "the-thing" bash
153 `("-e" ,build)
154 #:inputs `((,bash) (,build))
155 #:env-vars `(("x" . ,(random-text))))))
156 (and (build-derivations store (list drv))
157 (exit
158 (= 42 (pk (call-with-input-file (derivation->output-path drv)
159 read)))))))'
162 kill "$daemon_pid"
164 # Make sure the daemon's default 'timeout' and 'max-silent-time' settings are
165 # honored.
167 client_code='
168 (use-modules (guix) (gnu packages) (guix tests) (srfi srfi-34))
170 (with-store store
171 (let* ((build (add-text-to-store store "build.sh"
172 "while true ; do : ; done"))
173 (bash (add-to-store store "bash" #t "sha256"
174 (search-bootstrap-binary "bash"
175 (%current-system))))
176 (drv (derivation store "the-thing" bash
177 `("-e" ,build)
178 #:inputs `((,bash) (,build))
179 #:env-vars `(("x" . ,(random-text))))))
180 (exit (guard (c ((store-protocol-error? c)
181 (->bool
182 (string-contains (pk (store-protocol-error-message c))
183 "failed"))))
184 (build-derivations store (list drv))
185 #f))))'
188 for option in --max-silent-time=1 --timeout=1
190 guix-daemon --listen="$socket" --disable-chroot "$option" &
191 daemon_pid=$!
193 GUIX_DAEMON_SOCKET="$socket" guile -c "$client_code"
194 kill "$daemon_pid"
195 done
197 # Make sure garbage collection from a TCP connection does not work.
199 tcp_socket="127.0.0.1:9999"
200 guix-daemon --listen="$tcp_socket" &
201 daemon_pid=$!
203 GUIX_DAEMON_SOCKET="guix://$tcp_socket"
204 export GUIX_DAEMON_SOCKET
206 if guix gc; then false; else true; fi
208 unset GUIX_DAEMON_SOCKET
209 kill "$daemon_pid"
211 # Log compression.
213 guix-daemon --listen="$socket" --disable-chroot --debug --log-compression=gzip &
214 daemon_pid=$!
216 stamp="compressed-build-log-test-$$-`date +%H%M%S`"
217 client_code="
218 (use-modules (guix) (gnu packages bootstrap))
220 (with-store store
221 (run-with-store store
222 (mlet %store-monad ((drv (lower-object
223 (computed-file \"compressed-log-test\"
224 #~(begin
225 (display \"$stamp\")
226 (newline)
227 (mkdir #\$output))
228 #:guile %bootstrap-guile))))
229 (display (derivation-file-name drv))
230 (newline)
231 (return #t))))
234 GUIX_DAEMON_SOCKET="$socket"
235 export GUIX_DAEMON_SOCKET
237 drv=`guile -c "$client_code"`
238 guix build "$drv"
240 log=`guix build "$drv" --log-file`
241 test -f "$log"
242 case "$log" in
243 *.gz) test "`gunzip -c < "$log"`" = "$stamp" ;;
244 *) false ;;
245 esac