publish: Produce a "FileSize" narinfo field when possible.
[jackhill/guix/guix.git] / tests / guix-daemon.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
deac976d 2# Copyright © 2012, 2014, 2015, 2016, 2017 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
23set -e
24
d23077dc 25guix-daemon --version
e49951eb 26guix build --version
d23077dc 27
c9e2b0b1
LC
28drv="`guix build emacs -d`"
29out="`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
35hash_part="`basename $out | cut -c 1-32`"
36narinfo="$hash_part.narinfo"
37substitute_dir="`echo $GUIX_BINARY_SUBSTITUTE_URL | sed -'es,file://,,g'`"
38
39cat > "$substitute_dir/nix-cache-info"<<EOF
40StoreDir: `dirname $drv`
41WantMassQuery: 0
42EOF
43
44cat > "$substitute_dir/$narinfo"<<EOF
45StorePath: $out
46URL: /nowhere/example.nar
47Compression: none
48NarSize: 1234
49References:
50System: `guile -c '(use-modules (guix)) (display (%current-system))'`
51Deriver: $drv
52EOF
53
54# Remove the cached narinfo.
122c87ea 55rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
c9e2b0b1
LC
56
57# Make sure we see the substitute.
24f5aaaf 58guile -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.
66socket="$NIX_STATE_DIR/alternate-socket"
67guix-daemon --no-substitutes --listen="$socket" --disable-chroot &
68daemon_pid=$!
16748d80 69trap 'kill $daemon_pid' EXIT
c9e2b0b1
LC
70
71# Make sure we DON'T see the substitute.
72guile -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
82kill "$daemon_pid"
83
84
85# Check the failed build cache.
86
87guix-daemon --no-substitutes --listen="$socket" --disable-chroot \
88 --cache-failures &
89daemon_pid=$!
90
91guile -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)) "
deac976d
LC
121
122kill "$daemon_pid"
123
124
125# Make sure the daemon's default 'build-cores' setting is honored.
126
127guix-daemon --listen="$socket" --disable-chroot --cores=42 &
128daemon_pid=$!
129
130GUIX_DAEMON_SOCKET="$socket" \
131guile -c '
132 (use-modules (guix) (gnu packages) (guix tests))
133
134 (with-store store
135 (let* ((build (add-text-to-store store "build.sh"
136 "echo $NIX_BUILD_CORES > $out"))
137 (bash (add-to-store store "bash" #t "sha256"
138 (search-bootstrap-binary "bash"
139 (%current-system))))
140 (drv (derivation store "the-thing" bash
141 `("-e" ,build)
142 #:inputs `((,bash) (,build))
143 #:env-vars `(("x" . ,(random-text))))))
144 (and (build-derivations store (list drv))
145 (exit
146 (= 42 (pk (call-with-input-file (derivation->output-path drv)
147 read)))))))'