2013-01-05 23:47:50 +00:00
|
|
|
# GNU Guix --- Functional package management for GNU
|
2017-01-15 14:13:07 +00:00
|
|
|
# Copyright © 2012, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
|
2012-12-04 22:16:11 +00:00
|
|
|
#
|
2013-01-05 23:47:50 +00:00
|
|
|
# This file is part of GNU Guix.
|
2012-12-04 22:16:11 +00:00
|
|
|
#
|
2013-01-05 23:47:50 +00:00
|
|
|
# GNU Guix is free software; you can redistribute it and/or modify it
|
2012-12-04 22:16:11 +00:00
|
|
|
# under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
# your option) any later version.
|
|
|
|
#
|
2013-01-05 23:47:50 +00:00
|
|
|
# GNU Guix is distributed in the hope that it will be useful, but
|
2012-12-04 22:16:11 +00:00
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2013-01-05 23:47:50 +00:00
|
|
|
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
2012-12-04 22:16:11 +00:00
|
|
|
|
|
|
|
#
|
2015-03-26 22:34:21 +00:00
|
|
|
# Test the daemon and its interaction with 'guix substitute'.
|
2012-12-04 22:16:11 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
guix-daemon --version
|
Replace individual scripts with master 'guix' script.
* scripts/guix.in: New script.
* Makefile.am (bin_SCRIPTS): Add 'scripts/guix'. Remove 'guix-build',
'guix-download', 'guix-import', 'guix-package', and 'guix-gc'.
(MODULES): Add 'guix/scripts/build.scm', 'guix/scripts/download.scm',
'guix/scripts/import.scm', 'guix/scripts/package.scm', and
'guix/scripts/gc.scm'.
* configure.ac (AC_CONFIG_FILES): Add 'scripts/guix'. Remove 'guix-build',
'guix-download', 'guix-import', 'guix-package', and 'guix-gc'.
* guix-build.in, guix-download.in, guix-gc.in, guix-import.in,
guix-package.in: Remove shell script boilerplate. Move to guix-COMMAND.in
to guix/scripts/COMMAND.scm. Rename module from (guix-COMMAND) to
(guix scripts COMMAND). Change "guix-COMMAND" to "guix COMMAND" in
usage help string.
* pre-inst-env.in: Add "@abs_top_builddir@/scripts" to the front of $PATH.
Export $GUIX_UNINSTALLED.
* tests/guix-build.sh, tests/guix-daemon.sh, tests/guix-download.sh,
tests/guix-gc.sh, tests/guix-package.sh: Use "guix COMMAND" instead of
"guix-COMMAND".
* doc/guix.texi: Replace all occurrences of "guix-COMMAND" with
"guix COMMAND".
* po/POTFILES.in: Update.
2013-02-14 09:15:25 +00:00
|
|
|
guix build --version
|
2012-12-04 22:16:11 +00:00
|
|
|
|
2014-03-27 22:53:00 +00:00
|
|
|
drv="`guix build emacs -d`"
|
|
|
|
out="`guile -c ' \
|
2016-03-02 13:44:18 +00:00
|
|
|
(use-modules (guix) (guix grafts) (gnu packages emacs)) \
|
2014-03-27 22:53:00 +00:00
|
|
|
(define store (open-connection)) \
|
2016-03-02 13:44:18 +00:00
|
|
|
(%graft? #f)
|
2014-03-27 22:53:00 +00:00
|
|
|
(display (derivation->output-path (package-derivation store emacs)))'`"
|
|
|
|
|
|
|
|
hash_part="`basename $out | cut -c 1-32`"
|
|
|
|
narinfo="$hash_part.narinfo"
|
|
|
|
substitute_dir="`echo $GUIX_BINARY_SUBSTITUTE_URL | sed -'es,file://,,g'`"
|
|
|
|
|
|
|
|
cat > "$substitute_dir/nix-cache-info"<<EOF
|
|
|
|
StoreDir: `dirname $drv`
|
|
|
|
WantMassQuery: 0
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > "$substitute_dir/$narinfo"<<EOF
|
|
|
|
StorePath: $out
|
|
|
|
URL: /nowhere/example.nar
|
|
|
|
Compression: none
|
|
|
|
NarSize: 1234
|
|
|
|
References:
|
|
|
|
System: `guile -c '(use-modules (guix)) (display (%current-system))'`
|
|
|
|
Deriver: $drv
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Remove the cached narinfo.
|
2015-03-26 22:34:21 +00:00
|
|
|
rm -f "$XDG_CACHE_HOME/guix/substitute/$hash_part"
|
2014-03-27 22:53:00 +00:00
|
|
|
|
|
|
|
# Make sure we see the substitute.
|
substitute: Honor "substitute-urls" option passed by "untrusted" clients.
* guix/scripts/substitute.scm (or*): New macro.
(%cache-url): Honor "untrusted-substitute-urls".
* guix/tests.scm (%test-substitute-urls): New variable.
(open-connection-for-tests): Use it.
* tests/derivations.scm ("derivation-prerequisites-to-build and substitutes",
"derivation-prerequisites-to-build and substitutes, non-substitutable
build", "derivation-prerequisites-to-build and substitutes, local build"):
Pass it to 'set-build-options'.
* tests/guix-daemon.sh: Likewise.
* tests/store.scm ("substitute query, alternating URLs"): New test.
("substitute query", "substitute", "substitute + build-things with output
path", "substitute, corrupt output hash", "substitute --fallback"): Pass
#:substitute-urls to 'set-build-options'.
2015-07-13 13:46:12 +00:00
|
|
|
guile -c "
|
2014-03-27 22:53:00 +00:00
|
|
|
(use-modules (guix))
|
|
|
|
(define store (open-connection))
|
substitute: Honor "substitute-urls" option passed by "untrusted" clients.
* guix/scripts/substitute.scm (or*): New macro.
(%cache-url): Honor "untrusted-substitute-urls".
* guix/tests.scm (%test-substitute-urls): New variable.
(open-connection-for-tests): Use it.
* tests/derivations.scm ("derivation-prerequisites-to-build and substitutes",
"derivation-prerequisites-to-build and substitutes, non-substitutable
build", "derivation-prerequisites-to-build and substitutes, local build"):
Pass it to 'set-build-options'.
* tests/guix-daemon.sh: Likewise.
* tests/store.scm ("substitute query, alternating URLs"): New test.
("substitute query", "substitute", "substitute + build-things with output
path", "substitute, corrupt output hash", "substitute --fallback"): Pass
#:substitute-urls to 'set-build-options'.
2015-07-13 13:46:12 +00:00
|
|
|
(set-build-options store #:use-substitutes? #t
|
|
|
|
#:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
|
|
|
|
(exit (has-substitutes? store \"$out\"))"
|
2014-03-27 22:53:00 +00:00
|
|
|
|
|
|
|
# Now, run guix-daemon --no-substitutes.
|
|
|
|
socket="$NIX_STATE_DIR/alternate-socket"
|
|
|
|
guix-daemon --no-substitutes --listen="$socket" --disable-chroot &
|
|
|
|
daemon_pid=$!
|
2015-09-28 19:32:17 +00:00
|
|
|
trap 'kill $daemon_pid' EXIT
|
2014-03-27 22:53:00 +00:00
|
|
|
|
|
|
|
# Make sure we DON'T see the substitute.
|
|
|
|
guile -c "
|
|
|
|
(use-modules (guix))
|
|
|
|
(define store (open-connection \"$socket\"))
|
|
|
|
|
|
|
|
;; This setting MUST NOT override the daemon's --no-substitutes.
|
substitute: Honor "substitute-urls" option passed by "untrusted" clients.
* guix/scripts/substitute.scm (or*): New macro.
(%cache-url): Honor "untrusted-substitute-urls".
* guix/tests.scm (%test-substitute-urls): New variable.
(open-connection-for-tests): Use it.
* tests/derivations.scm ("derivation-prerequisites-to-build and substitutes",
"derivation-prerequisites-to-build and substitutes, non-substitutable
build", "derivation-prerequisites-to-build and substitutes, local build"):
Pass it to 'set-build-options'.
* tests/guix-daemon.sh: Likewise.
* tests/store.scm ("substitute query, alternating URLs"): New test.
("substitute query", "substitute", "substitute + build-things with output
path", "substitute, corrupt output hash", "substitute --fallback"): Pass
#:substitute-urls to 'set-build-options'.
2015-07-13 13:46:12 +00:00
|
|
|
(set-build-options store #:use-substitutes? #t
|
|
|
|
#:substitute-urls (list \"$GUIX_BINARY_SUBSTITUTE_URL\"))
|
2014-03-27 22:53:00 +00:00
|
|
|
|
|
|
|
(exit (not (has-substitutes? store \"$out\")))"
|
2015-09-28 19:32:17 +00:00
|
|
|
|
|
|
|
kill "$daemon_pid"
|
|
|
|
|
|
|
|
|
|
|
|
# Check the failed build cache.
|
|
|
|
|
|
|
|
guix-daemon --no-substitutes --listen="$socket" --disable-chroot \
|
|
|
|
--cache-failures &
|
|
|
|
daemon_pid=$!
|
|
|
|
|
|
|
|
guile -c "
|
2016-03-02 13:44:18 +00:00
|
|
|
(use-modules (guix) (guix grafts) (guix tests) (srfi srfi-34))
|
2015-09-28 19:32:17 +00:00
|
|
|
(define store (open-connection-for-tests \"$socket\"))
|
|
|
|
|
2016-03-02 13:44:18 +00:00
|
|
|
;; Disable grafts to avoid building more than needed.
|
|
|
|
(%graft? #f)
|
|
|
|
|
2015-09-28 19:32:17 +00:00
|
|
|
(define (build-without-failing drv)
|
|
|
|
(lambda (store)
|
|
|
|
(guard (c ((nix-protocol-error? c) (values #t store)))
|
|
|
|
(build-derivations store (list drv))
|
|
|
|
(values #f store))))
|
|
|
|
|
|
|
|
;; Make sure failed builds are cached and can be removed from
|
|
|
|
;; the cache.
|
|
|
|
(run-with-store store
|
|
|
|
(mlet* %store-monad ((drv (gexp->derivation \"failure\"
|
|
|
|
#~(begin
|
|
|
|
(ungexp output)
|
|
|
|
#f)))
|
|
|
|
(out -> (derivation->output-path drv))
|
|
|
|
(ok? (build-without-failing drv)))
|
|
|
|
;; Note the mixture of monadic and direct style. Don't try
|
|
|
|
;; this at home!
|
|
|
|
(return (exit (and ok?
|
|
|
|
(equal? (query-failed-paths store) (list out))
|
|
|
|
(begin
|
|
|
|
(clear-failed-paths store (list out))
|
|
|
|
(null? (query-failed-paths store)))))))
|
|
|
|
#:guile-for-build (%guile-for-build)) "
|
2017-01-15 14:13:07 +00:00
|
|
|
|
|
|
|
kill "$daemon_pid"
|
|
|
|
|
|
|
|
|
|
|
|
# Make sure the daemon's default 'build-cores' setting is honored.
|
|
|
|
|
|
|
|
guix-daemon --listen="$socket" --disable-chroot --cores=42 &
|
|
|
|
daemon_pid=$!
|
|
|
|
|
|
|
|
GUIX_DAEMON_SOCKET="$socket" \
|
|
|
|
guile -c '
|
|
|
|
(use-modules (guix) (gnu packages) (guix tests))
|
|
|
|
|
|
|
|
(with-store store
|
|
|
|
(let* ((build (add-text-to-store store "build.sh"
|
|
|
|
"echo $NIX_BUILD_CORES > $out"))
|
|
|
|
(bash (add-to-store store "bash" #t "sha256"
|
|
|
|
(search-bootstrap-binary "bash"
|
|
|
|
(%current-system))))
|
|
|
|
(drv (derivation store "the-thing" bash
|
|
|
|
`("-e" ,build)
|
|
|
|
#:inputs `((,bash) (,build))
|
|
|
|
#:env-vars `(("x" . ,(random-text))))))
|
|
|
|
(and (build-derivations store (list drv))
|
|
|
|
(exit
|
|
|
|
(= 42 (pk (call-with-input-file (derivation->output-path drv)
|
|
|
|
read)))))))'
|
2017-06-03 21:55:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
kill "$daemon_pid"
|
|
|
|
|
|
|
|
# Make sure the daemon's default 'timeout' and 'max-silent-time' settings are
|
|
|
|
# honored.
|
|
|
|
|
|
|
|
client_code='
|
|
|
|
(use-modules (guix) (gnu packages) (guix tests) (srfi srfi-34))
|
|
|
|
|
|
|
|
(with-store store
|
|
|
|
(let* ((build (add-text-to-store store "build.sh"
|
|
|
|
"while true ; do : ; done"))
|
|
|
|
(bash (add-to-store store "bash" #t "sha256"
|
|
|
|
(search-bootstrap-binary "bash"
|
|
|
|
(%current-system))))
|
|
|
|
(drv (derivation store "the-thing" bash
|
|
|
|
`("-e" ,build)
|
|
|
|
#:inputs `((,bash) (,build))
|
|
|
|
#:env-vars `(("x" . ,(random-text))))))
|
|
|
|
(exit (guard (c ((nix-protocol-error? c)
|
|
|
|
(->bool
|
|
|
|
(string-contains (pk (nix-protocol-error-message c))
|
|
|
|
"failed"))))
|
|
|
|
(build-derivations store (list drv))
|
|
|
|
#f))))'
|
|
|
|
|
|
|
|
|
|
|
|
for option in --max-silent-time=1 --timeout=1
|
|
|
|
do
|
|
|
|
guix-daemon --listen="$socket" --disable-chroot "$option" &
|
|
|
|
daemon_pid=$!
|
|
|
|
|
|
|
|
GUIX_DAEMON_SOCKET="$socket" guile -c "$client_code"
|
|
|
|
kill "$daemon_pid"
|
|
|
|
done
|