Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
442a6ff5 | 2 | # Copyright © 2012, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
d23077dc | 3 | # |
233e7676 | 4 | # This file is part of GNU Guix. |
d23077dc | 5 | # |
233e7676 | 6 | # GNU Guix is free software; you can redistribute it and/or modify it |
d23077dc LC |
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 | # | |
233e7676 | 11 | # GNU Guix is distributed in the hope that it will be useful, but |
d23077dc LC |
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 | |
233e7676 | 17 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
d23077dc LC |
18 | |
19 | # | |
122c87ea | 20 | # Test the daemon and its interaction with 'guix substitute'. |
d23077dc LC |
21 | # |
22 | ||
23 | set -e | |
24 | ||
d23077dc | 25 | guix-daemon --version |
e49951eb | 26 | guix build --version |
d23077dc | 27 | |
c9e2b0b1 LC |
28 | drv="`guix build emacs -d`" |
29 | out="`guile -c ' \ | |
442a6ff5 | 30 | (use-modules (guix) (guix grafts) (gnu packages emacs)) \ |
c9e2b0b1 | 31 | (define store (open-connection)) \ |
442a6ff5 | 32 | (%graft? #f) |
c9e2b0b1 LC |
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. | |
122c87ea | 55 | rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part" |
c9e2b0b1 LC |
56 | |
57 | # Make sure we see the substitute. | |
24f5aaaf | 58 | guile -c " |
c9e2b0b1 LC |
59 | (use-modules (guix)) |
60 | (define store (open-connection)) | |
24f5aaaf LC |
61 | (set-build-options store #:use-substitutes? #t |
62 | #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\")) | |
63 | (exit (has-substitutes? store \"$out\"))" | |
c9e2b0b1 LC |
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=$! | |
16748d80 | 69 | trap 'kill $daemon_pid' EXIT |
c9e2b0b1 LC |
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. | |
24f5aaaf LC |
77 | (set-build-options store #:use-substitutes? #t |
78 | #:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\")) | |
c9e2b0b1 LC |
79 | |
80 | (exit (not (has-substitutes? store \"$out\")))" | |
16748d80 LC |
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 " | |
442a6ff5 | 92 | (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34)) |
16748d80 LC |
93 | (define store (open-connection-for-tests \"$socket\")) |
94 | ||
442a6ff5 LC |
95 | ;; Disable grafts to avoid building more than needed. |
96 | (%graft? #f) | |
97 | ||
16748d80 LC |
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)) " |