1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2014, 2015, 2016 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
="$NIX_STATE_DIR/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\")))"
85 # Check the failed build cache.
87 guix-daemon
--no-substitutes --listen="$socket" --disable-chroot \
92 (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34))
93 (define store (open-connection-for-tests \"$socket\"))
95 ;; Disable grafts to avoid building more than needed.
98 (define (build-without-failing drv)
100 (guard (c ((nix-protocol-error? c) (values #t store)))
101 (build-derivations store (list drv))
104 ;; Make sure failed builds are cached and can be removed from
106 (run-with-store store
107 (mlet* %store-monad ((drv (gexp->derivation \"failure\"
111 (out -> (derivation->output-path drv))
112 (ok? (build-without-failing drv)))
113 ;; Note the mixture of monadic and direct style. Don't try
115 (return (exit (and ok?
116 (equal? (query-failed-paths store) (list out))
118 (clear-failed-paths store (list out))
119 (null? (query-failed-paths store)))))))
120 #:guile-for-build (%guile-for-build)) "