Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
f9e8a123 | 2 | # Copyright © 2012, 2014, 2015, 2016, 2017, 2018, 2019 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. | |
a87d66f3 | 66 | socket="$GUIX_STATE_DIRECTORY/alternate-socket" |
c9e2b0b1 LC |
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 | 96 | |
81c580c8 LC |
97 | # Make sure 'profiles/per-user' is created when connecting over TCP. |
98 | ||
99 | orig_GUIX_STATE_DIRECTORY="$GUIX_STATE_DIRECTORY" | |
100 | GUIX_STATE_DIRECTORY="$GUIX_STATE_DIRECTORY-2" | |
101 | ||
102 | guix-daemon --disable-chroot --listen="localhost:9877" & | |
103 | daemon_pid=$! | |
104 | ||
105 | GUIX_DAEMON_SOCKET="guix://localhost:9877" | |
106 | export GUIX_DAEMON_SOCKET | |
107 | ||
108 | test ! -d "$GUIX_STATE_DIRECTORY/profiles/per-user" | |
109 | ||
110 | guix build guile-bootstrap -d | |
111 | ||
112 | test -d "$GUIX_STATE_DIRECTORY/profiles/per-user/$USER" | |
113 | ||
114 | kill "$daemon_pid" | |
115 | unset GUIX_DAEMON_SOCKET | |
116 | GUIX_STATE_DIRECTORY="$orig_GUIX_STATE_DIRECTORY" | |
117 | ||
16748d80 LC |
118 | # Check the failed build cache. |
119 | ||
120 | guix-daemon --no-substitutes --listen="$socket" --disable-chroot \ | |
121 | --cache-failures & | |
122 | daemon_pid=$! | |
123 | ||
124 | guile -c " | |
442a6ff5 | 125 | (use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34)) |
16748d80 LC |
126 | (define store (open-connection-for-tests \"$socket\")) |
127 | ||
442a6ff5 LC |
128 | ;; Disable grafts to avoid building more than needed. |
129 | (%graft? #f) | |
130 | ||
16748d80 LC |
131 | (define (build-without-failing drv) |
132 | (lambda (store) | |
f9e8a123 | 133 | (guard (c ((store-protocol-error? c) (values #t store))) |
16748d80 LC |
134 | (build-derivations store (list drv)) |
135 | (values #f store)))) | |
136 | ||
137 | ;; Make sure failed builds are cached and can be removed from | |
138 | ;; the cache. | |
139 | (run-with-store store | |
140 | (mlet* %store-monad ((drv (gexp->derivation \"failure\" | |
141 | #~(begin | |
142 | (ungexp output) | |
143 | #f))) | |
144 | (out -> (derivation->output-path drv)) | |
145 | (ok? (build-without-failing drv))) | |
146 | ;; Note the mixture of monadic and direct style. Don't try | |
147 | ;; this at home! | |
148 | (return (exit (and ok? | |
149 | (equal? (query-failed-paths store) (list out)) | |
150 | (begin | |
151 | (clear-failed-paths store (list out)) | |
152 | (null? (query-failed-paths store))))))) | |
153 | #:guile-for-build (%guile-for-build)) " | |
deac976d LC |
154 | |
155 | kill "$daemon_pid" | |
156 | ||
157 | ||
158 | # Make sure the daemon's default 'build-cores' setting is honored. | |
159 | ||
160 | guix-daemon --listen="$socket" --disable-chroot --cores=42 & | |
161 | daemon_pid=$! | |
162 | ||
163 | GUIX_DAEMON_SOCKET="$socket" \ | |
164 | guile -c ' | |
1ba0b1e6 | 165 | (use-modules (guix) (guix tests)) |
deac976d LC |
166 | |
167 | (with-store store | |
168 | (let* ((build (add-text-to-store store "build.sh" | |
169 | "echo $NIX_BUILD_CORES > $out")) | |
170 | (bash (add-to-store store "bash" #t "sha256" | |
171 | (search-bootstrap-binary "bash" | |
172 | (%current-system)))) | |
173 | (drv (derivation store "the-thing" bash | |
174 | `("-e" ,build) | |
175 | #:inputs `((,bash) (,build)) | |
176 | #:env-vars `(("x" . ,(random-text)))))) | |
177 | (and (build-derivations store (list drv)) | |
178 | (exit | |
179 | (= 42 (pk (call-with-input-file (derivation->output-path drv) | |
180 | read)))))))' | |
2ca9f51e LC |
181 | |
182 | ||
183 | kill "$daemon_pid" | |
184 | ||
185 | # Make sure the daemon's default 'timeout' and 'max-silent-time' settings are | |
186 | # honored. | |
187 | ||
188 | client_code=' | |
1ba0b1e6 | 189 | (use-modules (guix) (guix tests) (srfi srfi-34)) |
2ca9f51e LC |
190 | |
191 | (with-store store | |
192 | (let* ((build (add-text-to-store store "build.sh" | |
193 | "while true ; do : ; done")) | |
194 | (bash (add-to-store store "bash" #t "sha256" | |
195 | (search-bootstrap-binary "bash" | |
196 | (%current-system)))) | |
197 | (drv (derivation store "the-thing" bash | |
198 | `("-e" ,build) | |
199 | #:inputs `((,bash) (,build)) | |
200 | #:env-vars `(("x" . ,(random-text)))))) | |
f9e8a123 | 201 | (exit (guard (c ((store-protocol-error? c) |
2ca9f51e | 202 | (->bool |
f9e8a123 | 203 | (string-contains (pk (store-protocol-error-message c)) |
2ca9f51e LC |
204 | "failed")))) |
205 | (build-derivations store (list drv)) | |
206 | #f))))' | |
207 | ||
208 | ||
209 | for option in --max-silent-time=1 --timeout=1 | |
210 | do | |
211 | guix-daemon --listen="$socket" --disable-chroot "$option" & | |
212 | daemon_pid=$! | |
213 | ||
214 | GUIX_DAEMON_SOCKET="$socket" guile -c "$client_code" | |
215 | kill "$daemon_pid" | |
216 | done | |
29a68668 | 217 | |
5cefb13d RJ |
218 | # Make sure garbage collection from a TCP connection does not work. |
219 | ||
c30d1178 | 220 | tcp_socket="127.0.0.1:9998" |
5cefb13d RJ |
221 | guix-daemon --listen="$tcp_socket" & |
222 | daemon_pid=$! | |
223 | ||
224 | GUIX_DAEMON_SOCKET="guix://$tcp_socket" | |
225 | export GUIX_DAEMON_SOCKET | |
226 | ||
227 | if guix gc; then false; else true; fi | |
228 | ||
229 | unset GUIX_DAEMON_SOCKET | |
230 | kill "$daemon_pid" | |
231 | ||
29a68668 LC |
232 | # Log compression. |
233 | ||
234 | guix-daemon --listen="$socket" --disable-chroot --debug --log-compression=gzip & | |
235 | daemon_pid=$! | |
236 | ||
237 | stamp="compressed-build-log-test-$$-`date +%H%M%S`" | |
238 | client_code=" | |
239 | (use-modules (guix) (gnu packages bootstrap)) | |
240 | ||
241 | (with-store store | |
242 | (run-with-store store | |
243 | (mlet %store-monad ((drv (lower-object | |
244 | (computed-file \"compressed-log-test\" | |
245 | #~(begin | |
246 | (display \"$stamp\") | |
247 | (newline) | |
248 | (mkdir #\$output)) | |
249 | #:guile %bootstrap-guile)))) | |
250 | (display (derivation-file-name drv)) | |
251 | (newline) | |
252 | (return #t)))) | |
253 | " | |
254 | ||
255 | GUIX_DAEMON_SOCKET="$socket" | |
256 | export GUIX_DAEMON_SOCKET | |
257 | ||
258 | drv=`guile -c "$client_code"` | |
259 | guix build "$drv" | |
260 | ||
261 | log=`guix build "$drv" --log-file` | |
262 | test -f "$log" | |
263 | case "$log" in | |
264 | *.gz) test "`gunzip -c < "$log"`" = "$stamp" ;; | |
265 | *) false ;; | |
266 | esac |