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'.
28 drv
="`guix build emacs -d`"
30 (use-modules (guix) (guix grafts) (gnu packages emacs)) \
31 (define store (open-connection)) \
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`
44 cat > "$substitute_dir/$narinfo"<<EOF
46 URL: /nowhere/example.nar
50 System: `guile -c '(use-modules (guix)) (display (%current-system))'`
54 # Remove the cached narinfo.
55 rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
57 # Make sure we see the substitute.
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 &
69 trap 'kill $daemon_pid' EXIT
71 # Make sure we DON'T see the substitute.
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\")))"
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" &
89 for uri
in "$socket" "$socket-second" \
90 "guix://localhost" "guix://localhost:9876"
92 GUIX_DAEMON_SOCKET
="$uri" guix build guile-bootstrap
97 # Check the failed build cache.
99 guix-daemon
--no-substitutes --listen="$socket" --disable-chroot \
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.
110 (define (build-without-failing drv)
112 (guard (c ((store-protocol-error? c) (values #t store)))
113 (build-derivations store (list drv))
116 ;; Make sure failed builds are cached and can be removed from
118 (run-with-store store
119 (mlet* %store-monad ((drv (gexp->derivation \"failure\"
123 (out -> (derivation->output-path drv))
124 (ok? (build-without-failing drv)))
125 ;; Note the mixture of monadic and direct style. Don't try
127 (return (exit (and ok?
128 (equal? (query-failed-paths store) (list out))
130 (clear-failed-paths store (list out))
131 (null? (query-failed-paths store)))))))
132 #:guile-for-build (%guile-for-build)) "
137 # Make sure the daemon's default 'build-cores' setting is honored.
139 guix-daemon
--listen="$socket" --disable-chroot --cores=42 &
142 GUIX_DAEMON_SOCKET
="$socket" \
144 (use-modules (guix) (gnu packages) (guix tests))
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"
152 (drv (derivation store "the-thing" bash
154 #:inputs `((,bash) (,build))
155 #:env-vars `(("x" . ,(random-text))))))
156 (and (build-derivations store (list drv))
158 (= 42 (pk (call-with-input-file (derivation->output-path drv)
164 # Make sure the daemon's default 'timeout' and 'max-silent-time' settings are
168 (use-modules (guix) (gnu packages) (guix tests) (srfi srfi-34))
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"
176 (drv (derivation store "the-thing" bash
178 #:inputs `((,bash) (,build))
179 #:env-vars `(("x" . ,(random-text))))))
180 (exit (guard (c ((store-protocol-error? c)
182 (string-contains (pk (store-protocol-error-message c))
184 (build-derivations store (list drv))
188 for option
in --max-silent-time=1 --timeout=1
190 guix-daemon
--listen="$socket" --disable-chroot "$option" &
193 GUIX_DAEMON_SOCKET
="$socket" guile
-c "$client_code"
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" &
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
213 guix-daemon
--listen="$socket" --disable-chroot --debug --log-compression=gzip &
216 stamp
="compressed-build-log-test-$$-`date +%H%M%S`"
218 (use-modules (guix) (gnu packages bootstrap))
221 (run-with-store store
222 (mlet %store-monad ((drv (lower-object
223 (computed-file \"compressed-log-test\"
228 #:guile %bootstrap-guile))))
229 (display (derivation-file-name drv))
234 GUIX_DAEMON_SOCKET
="$socket"
235 export GUIX_DAEMON_SOCKET
237 drv
=`guile -c "$client_code"`
240 log
=`guix build "$drv" --log-file`
243 *.gz
) test "`gunzip -c < "$log"`" = "$stamp" ;;