Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
29a68668 | 2 | # Copyright © 2012, 2014, 2015, 2016, 2017, 2018 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 | ||
1071f781 LC |
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=$! | |
88 | ||
89 | for uri in "$socket" "$socket-second" \ | |
90 | "guix://localhost" "guix://localhost:9876" | |
91 | do | |
92 | GUIX_DAEMON_SOCKET="$uri" guix build guile-bootstrap | |
93 | done | |
94 | ||
95 | kill "$daemon_pid" | |
16748d80 LC |
96 | |
97 | # Check the failed build cache. | |
98 | ||
99 | guix-daemon --no-substitutes --listen="$socket" --disable-chroot \ | |
100 | --cache-failures & | |
101 | daemon_pid=$! | |
102 | ||
103 | guile -c " | |
442a6ff5 | 104 | (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34)) |
16748d80 LC |
105 | (define store (open-connection-for-tests \"$socket\")) |
106 | ||
442a6ff5 LC |
107 | ;; Disable grafts to avoid building more than needed. |
108 | (%graft? #f) | |
109 | ||
16748d80 LC |
110 | (define (build-without-failing drv) |
111 | (lambda (store) | |
112 | (guard (c ((nix-protocol-error? c) (values #t store))) | |
113 | (build-derivations store (list drv)) | |
114 | (values #f store)))) | |
115 | ||
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)) " | |
deac976d LC |
133 | |
134 | kill "$daemon_pid" | |
135 | ||
136 | ||
137 | # Make sure the daemon's default 'build-cores' setting is honored. | |
138 | ||
139 | guix-daemon --listen="$socket" --disable-chroot --cores=42 & | |
140 | daemon_pid=$! | |
141 | ||
142 | GUIX_DAEMON_SOCKET="$socket" \ | |
143 | guile -c ' | |
144 | (use-modules (guix) (gnu packages) (guix tests)) | |
145 | ||
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)))))))' | |
2ca9f51e LC |
160 | |
161 | ||
162 | kill "$daemon_pid" | |
163 | ||
164 | # Make sure the daemon's default 'timeout' and 'max-silent-time' settings are | |
165 | # honored. | |
166 | ||
167 | client_code=' | |
168 | (use-modules (guix) (gnu packages) (guix tests) (srfi srfi-34)) | |
169 | ||
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 ((nix-protocol-error? c) | |
181 | (->bool | |
182 | (string-contains (pk (nix-protocol-error-message c)) | |
183 | "failed")))) | |
184 | (build-derivations store (list drv)) | |
185 | #f))))' | |
186 | ||
187 | ||
188 | for option in --max-silent-time=1 --timeout=1 | |
189 | do | |
190 | guix-daemon --listen="$socket" --disable-chroot "$option" & | |
191 | daemon_pid=$! | |
192 | ||
193 | GUIX_DAEMON_SOCKET="$socket" guile -c "$client_code" | |
194 | kill "$daemon_pid" | |
195 | done | |
29a68668 | 196 | |
5cefb13d RJ |
197 | # Make sure garbage collection from a TCP connection does not work. |
198 | ||
199 | tcp_socket="127.0.0.1:9999" | |
200 | guix-daemon --listen="$tcp_socket" & | |
201 | daemon_pid=$! | |
202 | ||
203 | GUIX_DAEMON_SOCKET="guix://$tcp_socket" | |
204 | export GUIX_DAEMON_SOCKET | |
205 | ||
206 | if guix gc; then false; else true; fi | |
207 | ||
208 | unset GUIX_DAEMON_SOCKET | |
209 | kill "$daemon_pid" | |
210 | ||
29a68668 LC |
211 | # Log compression. |
212 | ||
213 | guix-daemon --listen="$socket" --disable-chroot --debug --log-compression=gzip & | |
214 | daemon_pid=$! | |
215 | ||
216 | stamp="compressed-build-log-test-$$-`date +%H%M%S`" | |
217 | client_code=" | |
218 | (use-modules (guix) (gnu packages bootstrap)) | |
219 | ||
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)))) | |
232 | " | |
233 | ||
234 | GUIX_DAEMON_SOCKET="$socket" | |
235 | export GUIX_DAEMON_SOCKET | |
236 | ||
237 | drv=`guile -c "$client_code"` | |
238 | guix build "$drv" | |
239 | ||
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 |