From 533d1768f47520ac7010adc550b0dd9783ebb011 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 17 Mar 2015 10:19:36 -0400 Subject: store: Add query-path-info operation. * guix/store.scm (): New record type. (read-path-info): New procedure. (read-arg): Add 'path-info' syntax. (query-path-info): New variable. * tests/store.scm ("query-path-info"): New test. --- tests/store.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/store.scm b/tests/store.scm index f778c2086d..eeceed45c1 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -606,6 +606,16 @@ (file (add %store "foo" "Lowered."))) (call-with-input-file file get-string-all))) +(test-assert "query-path-info" + (let* ((ref (add-text-to-store %store "ref" "foo")) + (item (add-text-to-store %store "item" "bar" (list ref))) + (info (query-path-info %store item))) + (and (equal? (path-info-references info) (list ref)) + (equal? (path-info-hash info) + (sha256 + (string->utf8 + (call-with-output-string (cut write-file item <>)))))))) + (test-end "store") -- cgit v1.2.3 From aff8ce7c742443eaab0b0c6b6f27e6539f3af85f Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 17 Mar 2015 10:21:31 -0400 Subject: scripts: Add 'publish' command. * guix/scripts/publish.scm: New file. * po/guix/POTFILES.in: Add it. * tests/publish.scm: New file. * Makefile.am (MODULES): Add script module. (SCM_TESTS): Add test module. * doc/guix.texi ("Invoking guix publish"): New node. --- Makefile.am | 4 +- doc/guix.texi | 52 +++++++++- guix/scripts/publish.scm | 243 +++++++++++++++++++++++++++++++++++++++++++++++ po/guix/POTFILES.in | 1 + tests/publish.scm | 114 ++++++++++++++++++++++ 5 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 guix/scripts/publish.scm create mode 100644 tests/publish.scm (limited to 'tests') diff --git a/Makefile.am b/Makefile.am index cf709986ed..e15e43fdd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -105,6 +105,7 @@ MODULES = \ guix/scripts/import/gnu.scm \ guix/scripts/import/nix.scm \ guix/scripts/environment.scm \ + guix/scripts/publish.scm \ guix.scm \ $(GNU_SYSTEM_MODULES) @@ -180,7 +181,8 @@ SCM_TESTS = \ tests/profiles.scm \ tests/syscalls.scm \ tests/gremlin.scm \ - tests/lint.scm + tests/lint.scm \ + tests/publish.scm if HAVE_GUILE_JSON diff --git a/doc/guix.texi b/doc/guix.texi index f7f22e5b8a..f1dea45f1d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -121,6 +121,7 @@ Utilities * Invoking guix refresh:: Updating package definitions. * Invoking guix lint:: Finding errors in package definitions. * Invoking guix environment:: Setting up development environments. +* Invoking guix publish:: Sharing substitutes. GNU Distribution @@ -2527,7 +2528,7 @@ To illustrate the idea, here is an example of a gexp: #~(begin (mkdir #$output) (chdir #$output) - (symlink (string-append #$coreutils "/bin/ls") + (symlink (string-append #$coreutils "/bin/ls") "list-files"))) @end example @@ -2777,6 +2778,7 @@ programming interface of Guix in a convenient way. * Invoking guix refresh:: Updating package definitions. * Invoking guix lint:: Finding errors in package definitions. * Invoking guix environment:: Setting up development environments. +* Invoking guix publish:: Sharing substitutes. @end menu @node Invoking guix build @@ -3439,6 +3441,54 @@ environment. It also supports all of the common build options that @command{guix build} supports (@pxref{Invoking guix build, common build options}). +@node Invoking guix publish +@section Invoking @command{guix publish} + +The purpose of @command{guix publish} is to enable users to easily share +their store with others. When @command{guix publish} runs, it spawns an +HTTP server which allows anyone with network access to obtain +substitutes from it. This means that any machine running Guix can also +act as if it were a build farm, since the HTTP interface is +Hydra-compatible. + +For security, each substitute is signed, allowing recipients to check +their authenticity and integrity (@pxref{Substitutes}). Because +@command{guix publish} uses the system's signing key, which is only +readable by the system administrator, it must run as root. + +The general syntax is: + +@example +guix publish @var{options}@dots{} +@end example + +Running @command{guix publish} without any additional arguments will +spawn an HTTP server on port 8080: + +@example +guix publish +@end example + +Once a publishing server has been authorized (@pxref{Invoking guix +archive}), the daemon may download substitutes from it: + +@example +guix-daemon --substitute-urls=http://example.org:8080 +@end example + +The following options are available: + +@table @code +@item --port=@var{port} +@itemx -p @var{port} +Listen for HTTP requests on @var{port}. + +@item --repl[=@var{port}] +@itemx -r [@var{port}] +Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile +Reference Manual}) on @var{port} (37146 by default). +@end table + @c ********************************************************************* @node GNU Distribution @chapter GNU Distribution diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm new file mode 100644 index 0000000000..c7c66fefbe --- /dev/null +++ b/guix/scripts/publish.scm @@ -0,0 +1,243 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 David Thompson +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; 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. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; 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 +;;; along with GNU Guix. If not, see . + +(define-module (guix scripts publish) + #:use-module ((system repl server) #:prefix repl:) + #:use-module (ice-9 binary-ports) + #:use-module (ice-9 format) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (rnrs io ports) + #:use-module (rnrs bytevectors) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-2) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-37) + #:use-module (web http) + #:use-module (web request) + #:use-module (web response) + #:use-module (web server) + #:use-module (web uri) + #:use-module (guix base32) + #:use-module (guix base64) + #:use-module (guix config) + #:use-module (guix derivations) + #:use-module (guix hash) + #:use-module (guix pki) + #:use-module (guix pk-crypto) + #:use-module (guix store) + #:use-module (guix serialization) + #:use-module (guix ui) + #:export (guix-publish)) + +(define (show-help) + (format #t (_ "Usage: guix publish [OPTION]... +Publish ~a over HTTP.\n") %store-directory) + (display (_ " + -p, --port=PORT listen on PORT")) + (display (_ " + -r, --repl[=PORT] spawn REPL server on PORT")) + (newline) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %options + (list (option '(#\h "help") #f #f + (lambda _ + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda _ + (show-version-and-exit "guix publish"))) + (option '(#\p "port") #t #f + (lambda (opt name arg result) + (alist-cons 'port (string->number* arg) result))) + (option '(#\r "repl") #f #t + (lambda (opt name arg result) + ;; If port unspecified, use default Guile REPL port. + (let ((port (and arg (string->number* arg)))) + (alist-cons 'repl (or port 37146) result)))))) + +(define %default-options + '((port . 8080) + (repl . #f))) + +(define (lazy-read-file-sexp file) + "Return a promise to read the canonical sexp from FILE." + (delay + (call-with-input-file file + (compose string->canonical-sexp + get-string-all)))) + +(define %private-key + (lazy-read-file-sexp %private-key-file)) + +(define %public-key + (lazy-read-file-sexp %public-key-file)) + +(define %nix-cache-info + `(("StoreDir" . ,%store-directory) + ("WantMassQuery" . 0) + ("Priority" . 100))) + +(define (load-derivation file) + "Read the derivation from FILE." + (call-with-input-file file read-derivation)) + +(define (signed-string s) + "Sign the hash of the string S with the daemon's key." + (let* ((public-key (force %public-key)) + (hash (bytevector->hash-data (sha256 (string->utf8 s)) + #:key-type (key-type public-key)))) + (signature-sexp hash (force %private-key) public-key))) + +(define base64-encode-string + (compose base64-encode string->utf8)) + +(define (narinfo-string store-path path-info key) + "Generate a narinfo key/value string for STORE-PATH using the details in +PATH-INFO. The narinfo is signed with KEY." + (let* ((url (string-append "nar/" (basename store-path))) + (hash (bytevector->base32-string + (path-info-hash path-info))) + (size (path-info-nar-size path-info)) + (references (string-join + (map basename (path-info-references path-info)) + " ")) + (deriver (path-info-deriver path-info)) + (base-info (format #f + "StorePath: ~a +URL: ~a +Compression: none +NarHash: sha256:~a +NarSize: ~d +References: ~a~%" + store-path url hash size references)) + ;; Do not render a "Deriver" or "System" line if we are rendering + ;; info for a derivation. + (info (if (string-null? deriver) + base-info + (let ((drv (load-derivation deriver))) + (format #f "~aSystem: ~a~%Deriver: ~a~%" + base-info (derivation-system drv) + (basename deriver))))) + (signature (base64-encode-string + (canonical-sexp->string (signed-string info))))) + (format #f "~aSignature: 1;~a;~a~%" info (gethostname) signature))) + +(define (not-found request) + "Render 404 response for REQUEST." + (values (build-response #:code 404) + (string-append "Resource not found: " + (uri-path (request-uri request))))) + +(define (render-nix-cache-info) + "Render server information." + (values '((content-type . (text/plain))) + (lambda (port) + (for-each (match-lambda + ((key . value) + (format port "~a: ~a~%" key value))) + %nix-cache-info)))) + +(define (render-narinfo store request hash) + "Render metadata for the store path corresponding to HASH." + (let* ((store-path (hash-part->path store hash)) + (path-info (and (not (string-null? store-path)) + (query-path-info store store-path)))) + (if path-info + (values '((content-type . (application/x-nix-narinfo))) + (cut display + (narinfo-string store-path path-info (force %private-key)) + <>)) + (not-found request)))) + +(define (render-nar request store-item) + "Render archive of the store path corresponding to STORE-ITEM." + (let ((store-path (string-append %store-directory "/" store-item))) + ;; The ISO-8859-1 charset *must* be used otherwise HTTP clients will + ;; interpret the byte stream as UTF-8 and arbitrarily change invalid byte + ;; sequences. + (if (file-exists? store-path) + (values '((content-type . (application/x-nix-archive + (charset . "ISO-8859-1")))) + (lambda (port) + (write-file store-path port))) + (not-found request)))) + +(define extract-narinfo-hash + (let ((regexp (make-regexp "^([a-df-np-sv-z0-9]{32}).narinfo$"))) + (lambda (str) + "Return the hash within the narinfo resource string STR, or false if STR +is invalid." + (and=> (regexp-exec regexp str) + (cut match:substring <> 1))))) + +(define (get-request? request) + "Return #t if REQUEST uses the GET method." + (eq? (request-method request) 'GET)) + +(define (request-path-components request) + "Split the URI path of REQUEST into a list of component strings. For +example: \"/foo/bar\" yields '(\"foo\" \"bar\")." + (split-and-decode-uri-path (uri-path (request-uri request)))) + +(define (make-request-handler store) + (lambda (request body) + (format #t "~a ~a~%" + (request-method request) + (uri-path (request-uri request))) + (if (get-request? request) ; reject POST, PUT, etc. + (match (request-path-components request) + ;; /nix-cache-info + (("nix-cache-info") + (render-nix-cache-info)) + ;; /.narinfo + (((= extract-narinfo-hash (? string? hash))) + (render-narinfo store request hash)) + ;; /nar/ + (("nar" store-item) + (render-nar request store-item)) + (_ (not-found request))) + (not-found request)))) + +(define (run-publish-server port store) + (run-server (make-request-handler store) + 'http + `(#:addr ,INADDR_ANY + #:port ,port))) + +(define (guix-publish . args) + (with-error-handling + (let* ((opts (args-fold* args %options + (lambda (opt name arg result) + (leave (_ "~A: unrecognized option~%") name)) + (lambda (arg result) + (leave (_ "~A: extraneuous argument~%") arg)) + %default-options)) + (port (assoc-ref opts 'port)) + (repl-port (assoc-ref opts 'repl))) + (format #t (_ "publishing ~a on port ~d~%") %store-directory port) + (when repl-port + (repl:spawn-server (repl:make-tcp-server-socket #:port repl-port))) + (with-store store + (run-publish-server (assoc-ref opts 'port) store))))) diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 39115f970b..5ac9201295 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -13,6 +13,7 @@ guix/scripts/substitute.scm guix/scripts/authenticate.scm guix/scripts/system.scm guix/scripts/lint.scm +guix/scripts/publish.scm guix/gnu-maintenance.scm guix/ui.scm guix/http-client.scm diff --git a/tests/publish.scm b/tests/publish.scm new file mode 100644 index 0000000000..60f57a8ddb --- /dev/null +++ b/tests/publish.scm @@ -0,0 +1,114 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 David Thompson +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; 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. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; 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 +;;; along with GNU Guix. If not, see . + +(define-module (test-publish) + #:use-module (guix scripts publish) + #:use-module (guix tests) + #:use-module (guix config) + #:use-module (guix utils) + #:use-module (guix hash) + #:use-module (guix store) + #:use-module (guix base32) + #:use-module (guix base64) + #:use-module ((guix serialization) #:select (restore-file)) + #:use-module (guix pk-crypto) + #:use-module (web client) + #:use-module (web response) + #:use-module (rnrs bytevectors) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-64) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim)) + +(define %store + (open-connection-for-tests)) + +(define %reference (add-text-to-store %store "ref" "foo")) + +(define %item (add-text-to-store %store "item" "bar" (list %reference))) + +(define (http-get-body uri) + (call-with-values (lambda () (http-get uri)) + (lambda (response body) body))) + +(define (publish-uri route) + (string-append "http://localhost:6789" route)) + +;; Run a local publishing server in a separate thread. +(call-with-new-thread + (lambda () + (guix-publish "--port=6789"))) ; attempt to avoid port collision + +;; Wait until the server is accepting connections. +(let ((conn (socket PF_INET SOCK_STREAM 0))) + (let loop () + (unless (false-if-exception + (connect conn AF_INET (inet-pton AF_INET "127.0.0.1") 6789)) + (loop)))) + +(test-begin "publish") + +(test-equal "/nix-cache-info" + (format #f "StoreDir: ~a\nWantMassQuery: 0\nPriority: 100\n" + %store-directory) + (http-get-body (publish-uri "/nix-cache-info"))) + +(test-equal "/*.narinfo" + (let* ((info (query-path-info %store %item)) + (unsigned-info + (format #f + "StorePath: ~a +URL: nar/~a +Compression: none +NarHash: sha256:~a +NarSize: ~d +References: ~a~%" + %item + (basename %item) + (bytevector->base32-string + (path-info-hash info)) + (path-info-nar-size info) + (basename (first (path-info-references info))))) + (signature (base64-encode + (string->utf8 + (canonical-sexp->string + ((@@ (guix scripts publish) signed-string) + unsigned-info)))))) + (format #f "~aSignature: 1;~a;~a~%" + unsigned-info (gethostname) signature)) + (utf8->string + (http-get-body + (publish-uri + (string-append "/" (store-path-hash-part %item) ".narinfo"))))) + +(test-equal "/nar/*" + "bar" + (call-with-temporary-output-file + (lambda (temp port) + (let ((nar (utf8->string + (http-get-body + (publish-uri + (string-append "/nar/" (basename %item))))))) + (call-with-input-string nar (cut restore-file <> temp))) + (call-with-input-file temp read-string)))) + +(test-end "publish") + + +(exit (= (test-runner-fail-count (test-runner-current)) 0)) -- cgit v1.2.3 From 381ac93b5ed7bd51f8f3ab6a8b0127f8ea6288f8 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 6 Apr 2015 21:05:38 +0200 Subject: tests: Deal with 'mount-points' not returning "/". Fixes . Reported by Mark H Weaver . * tests/syscalls.scm ("mount-points"): Check for a few other likely mount points in addition to "/". --- tests/syscalls.scm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/syscalls.scm b/tests/syscalls.scm index f26331e164..706f3dff44 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -19,6 +19,7 @@ (define-module (test-syscalls) #:use-module (guix build syscalls) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-64) #:use-module (ice-9 match)) @@ -45,7 +46,10 @@ (memv (system-error-errno args) (list EPERM ENOENT))))) (test-assert "mount-points" - (member "/" (mount-points))) + ;; Reportedly "/" is not always listed as a mount point, so check a few + ;; others (see .) + (any (cute member <> (mount-points)) + '("/" "/proc" "/sys" "/dev"))) (test-assert "swapon, ENOENT/EPERM" (catch 'system-error -- cgit v1.2.3 From d26eb84d140af8d2119509d7da440b4f035608c5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 6 Apr 2015 21:26:12 +0200 Subject: guix package: Never remove the current generation and warn about it. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes . Reported by taylanbayirli@gmail.com (Taylan Ulrich Bayırlı/Kammer). * guix/scripts/package.scm (delete-matching-generations): Warn when CURRENT is in NUMBERS, and always remove it before calling 'delete-generations'. * tests/guix-package.sh: Add --switch-generation=2 invocation before --delete-generations=3 invocation. Add --delete-generations=1.. test case. --- guix/scripts/package.scm | 13 ++++++++++--- tests/guix-package.sh | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 7074243ed9..3a7afb724b 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -254,9 +254,16 @@ denote ranges as interpreted by 'matching-derivations'." #:duration-relation >) => (lambda (numbers) - (if (null-list? numbers) - (exit 1) - (delete-generations (%store) profile numbers)))) + (when (memv current numbers) + (warning (_ "not removing generation ~a, which is current~%") + current)) + + ;; Make sure we don't inadvertently remove the current + ;; generation. + (let ((numbers (delv current numbers))) + (if (null-list? numbers) + (exit 1) + (delete-generations (%store) profile numbers))))) (else (leave (_ "invalid syntax: ~a~%") pattern))))) diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 94cf927420..a4c04255ba 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -161,6 +161,9 @@ then guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap guix package --search-paths -p "$profile" | grep LIBRARY_PATH + # Roll back so we can delete #3 below. + guix package -p "$profile" --switch-generation=2 + # Delete the third generation and check that it was actually deleted. guix package -p "$profile" --delete-generations=3 test -z "`guix package -p "$profile" -l 3`" @@ -212,6 +215,14 @@ if guix package -p "$profile" --delete-generations=12m; then false; else true; fi test "`readlink_base "$profile"`" = "$generation" +# The following command should not delete the current generation, even though +# it matches the given pattern (see .) And since +# there's nothing else to delete, it should just fail. +guix package --list-generations -p "$profile" +if guix package --bootstrap -p "$profile" --delete-generations=1.. +then false; else true; fi +test "`readlink_base "$profile"`" = "$generation" + # Make sure $profile is a GC root at this point. real_profile="`readlink -f "$profile"`" if guix gc -d "$real_profile" -- cgit v1.2.3 From 57b8623754fdd10b2cc194db09772f60010928af Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 6 Apr 2015 21:52:40 +0200 Subject: tests: Move 'guix package' tests that require networking to a separate file. * tests/guix-package.sh (shebang_not_too_long): Remove. Move everything below "if [networking + shebang_not_too_long]" to... * tests/guix-package-net.sh: ... here. New file. * Makefile.am (SH_TESTS): Add it. --- Makefile.am | 1 + tests/guix-package-net.sh | 170 ++++++++++++++++++++++++++++++++++++++++++++++ tests/guix-package.sh | 138 ++----------------------------------- 3 files changed, 177 insertions(+), 132 deletions(-) create mode 100644 tests/guix-package-net.sh (limited to 'tests') diff --git a/Makefile.am b/Makefile.am index e15e43fdd4..d54e281163 100644 --- a/Makefile.am +++ b/Makefile.am @@ -205,6 +205,7 @@ SH_TESTS = \ tests/guix-gc.sh \ tests/guix-hash.sh \ tests/guix-package.sh \ + tests/guix-package-net.sh \ tests/guix-system.sh \ tests/guix-archive.sh \ tests/guix-authenticate.sh \ diff --git a/tests/guix-package-net.sh b/tests/guix-package-net.sh new file mode 100644 index 0000000000..cedfa3217b --- /dev/null +++ b/tests/guix-package-net.sh @@ -0,0 +1,170 @@ +# GNU Guix --- Functional package management for GNU +# Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès +# Copyright © 2013 Nikita Karetnikov +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# 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. +# +# GNU Guix is distributed in the hope that it will be useful, but +# 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 +# along with GNU Guix. If not, see . + +# +# Test the `guix package' command-line utility. This test requires network +# access and is skipped when that is lacking. +# + +guix package --version + +readlink_base () +{ + basename `readlink "$1"` +} + +# Return true if a typical shebang in the store would exceed Linux's default +# static limit. +shebang_too_long () +{ + test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \ + -ge 128 +} + +profile="t-profile-$$" +rm -f "$profile" + +trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT + + +guix package --bootstrap -p "$profile" -i guile-bootstrap +test -L "$profile" && test -L "$profile-1-link" +! test -f "$profile-2-link" +test -f "$profile/bin/guile" + +boot_make="(@@ (gnu packages commencement) gnu-make-boot0)" +boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`" +guix package --bootstrap -p "$profile" -i "$boot_make_drv" +test -L "$profile-2-link" +test -f "$profile/bin/make" && test -f "$profile/bin/guile" + +# Check whether `--list-installed' works. +# XXX: Change the tests when `--install' properly extracts the package +# name and version string. +installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`" +case "x$installed" in + "guile-bootstrap make-boot0") + true;; + "make-boot0 guile-bootstrap") + true;; + "*") + false;; +esac + +test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap" + +# List generations. +test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \ + = " guile-bootstrap" + +# Exit with 1 when a generation does not exist. +if guix package -p "$profile" --list-generations=42; +then false; else true; fi +if guix package -p "$profile" --switch-generation=99; +then false; else true; fi + +# Remove a package. +guix package --bootstrap -p "$profile" -r "guile-bootstrap" +test -L "$profile-3-link" +test -f "$profile/bin/make" && ! test -f "$profile/bin/guile" + +# Roll back. +guix package --roll-back -p "$profile" +test "`readlink_base "$profile"`" = "$profile-2-link" +test -x "$profile/bin/guile" && test -x "$profile/bin/make" +guix package --roll-back -p "$profile" +test "`readlink_base "$profile"`" = "$profile-1-link" +test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" + +# Switch to the rolled generation and switch back. +guix package -p "$profile" --switch-generation=2 +test "`readlink_base "$profile"`" = "$profile-2-link" +guix package -p "$profile" --switch-generation=-1 +test "`readlink_base "$profile"`" = "$profile-1-link" + +# Move to the empty profile. +for i in `seq 1 3` +do + guix package --bootstrap --roll-back -p "$profile" + ! test -f "$profile/bin" + ! test -f "$profile/lib" + test "`readlink_base "$profile"`" = "$profile-0-link" +done + +# Test that '--list-generations' does not output the zeroth generation. +test -z "`guix package -p "$profile" -l 0`" + +# Reinstall after roll-back to the empty profile. +guix package --bootstrap -p "$profile" -e "$boot_make" +test "`readlink_base "$profile"`" = "$profile-1-link" +test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" + +# Check that the first generation is the current one. +test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)" + +# Roll-back to generation 0, and install---all at once. +guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap +test "`readlink_base "$profile"`" = "$profile-1-link" +test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" + +# Install Make. +guix package --bootstrap -p "$profile" -e "$boot_make" +test "`readlink_base "$profile"`" = "$profile-2-link" +test -x "$profile/bin/guile" && test -x "$profile/bin/make" +grep "`guix build -e "$boot_make"`" "$profile/manifest" + +# Make a "hole" in the list of generations, and make sure we can +# roll back and switch "over" it. +rm "$profile-1-link" +guix package --bootstrap -p "$profile" --roll-back +test "`readlink_base "$profile"`" = "$profile-0-link" +guix package -p "$profile" --switch-generation=+1 +test "`readlink_base "$profile"`" = "$profile-2-link" + +# Make sure LIBRARY_PATH gets listed by `--search-paths'. +guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap +guix package --search-paths -p "$profile" | grep LIBRARY_PATH + +# Roll back so we can delete #3 below. +guix package -p "$profile" --switch-generation=2 + +# Delete the third generation and check that it was actually deleted. +guix package -p "$profile" --delete-generations=3 +test -z "`guix package -p "$profile" -l 3`" + + +# +# Try with the default profile. +# + +XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" +export XDG_CACHE_HOME +HOME="$PWD/t-home-$$" +export HOME + +mkdir -p "$HOME" + +# Get the canonical directory name so that 'guix package' recognizes it. +HOME="`cd $HOME; pwd -P`" + +guix package --bootstrap -e "$boot_make" +test -f "$HOME/.guix-profile/bin/make" + +guix package --bootstrap --roll-back +! test -f "$HOME/.guix-profile/bin/make" diff --git a/tests/guix-package.sh b/tests/guix-package.sh index a4c04255ba..6cfd50b5e5 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -28,14 +28,6 @@ readlink_base () basename `readlink "$1"` } -# Return true if a typical shebang in the store would not exceed Linux's -# default static limit. -shebang_not_too_long () -{ - test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \ - -lt 128 -} - module_dir="t-guix-package-$$" profile="t-profile-$$" rm -f "$profile" @@ -63,118 +55,12 @@ test -f "$profile/bin/guile" guix package --search-paths -p "$profile" test "`guix package --search-paths -p "$profile" | wc -l`" = 0 -# Check whether we have network access and an acceptable shebang length. -if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \ - && shebang_not_too_long -then - boot_make="(@@ (gnu packages commencement) gnu-make-boot0)" - boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`" - guix package --bootstrap -p "$profile" -i "$boot_make_drv" - test -L "$profile-2-link" - test -f "$profile/bin/make" && test -f "$profile/bin/guile" - - - # Check whether `--list-installed' works. - # XXX: Change the tests when `--install' properly extracts the package - # name and version string. - installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`" - case "x$installed" in - "guile-bootstrap make-boot0") - true;; - "make-boot0 guile-bootstrap") - true;; - "*") - false;; - esac - - test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap" - - # List generations. - test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \ - = " guile-bootstrap" - - # Exit with 1 when a generation does not exist. - if guix package -p "$profile" --list-generations=42; - then false; else true; fi - if guix package -p "$profile" --switch-generation=99; - then false; else true; fi - - # Remove a package. - guix package --bootstrap -p "$profile" -r "guile-bootstrap" - test -L "$profile-3-link" - test -f "$profile/bin/make" && ! test -f "$profile/bin/guile" - - # Roll back. - guix package --roll-back -p "$profile" - test "`readlink_base "$profile"`" = "$profile-2-link" - test -x "$profile/bin/guile" && test -x "$profile/bin/make" - guix package --roll-back -p "$profile" - test "`readlink_base "$profile"`" = "$profile-1-link" - test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" - - # Switch to the rolled generation and switch back. - guix package -p "$profile" --switch-generation=2 - test "`readlink_base "$profile"`" = "$profile-2-link" - guix package -p "$profile" --switch-generation=-1 - test "`readlink_base "$profile"`" = "$profile-1-link" - - # Move to the empty profile. - for i in `seq 1 3` - do - guix package --bootstrap --roll-back -p "$profile" - ! test -f "$profile/bin" - ! test -f "$profile/lib" - test "`readlink_base "$profile"`" = "$profile-0-link" - done - - # Test that '--list-generations' does not output the zeroth generation. - test -z "`guix package -p "$profile" -l 0`" - - # Reinstall after roll-back to the empty profile. - guix package --bootstrap -p "$profile" -e "$boot_make" - test "`readlink_base "$profile"`" = "$profile-1-link" - test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" - - # Check that the first generation is the current one. - test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)" - - # Roll-back to generation 0, and install---all at once. - guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap - test "`readlink_base "$profile"`" = "$profile-1-link" - test -x "$profile/bin/guile" && ! test -x "$profile/bin/make" - - # Install Make. - guix package --bootstrap -p "$profile" -e "$boot_make" - test "`readlink_base "$profile"`" = "$profile-2-link" - test -x "$profile/bin/guile" && test -x "$profile/bin/make" - grep "`guix build -e "$boot_make"`" "$profile/manifest" - - # Make a "hole" in the list of generations, and make sure we can - # roll back and switch "over" it. - rm "$profile-1-link" - guix package --bootstrap -p "$profile" --roll-back - test "`readlink_base "$profile"`" = "$profile-0-link" - guix package -p "$profile" --switch-generation=+1 - test "`readlink_base "$profile"`" = "$profile-2-link" - - # Make sure LIBRARY_PATH gets listed by `--search-paths'. - guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap - guix package --search-paths -p "$profile" | grep LIBRARY_PATH - - # Roll back so we can delete #3 below. - guix package -p "$profile" --switch-generation=2 - - # Delete the third generation and check that it was actually deleted. - guix package -p "$profile" --delete-generations=3 - test -z "`guix package -p "$profile" -l 3`" - - # Exit with 1 when a generation does not exist. - if guix package -p "$profile" --delete-generations=42; - then false; else true; fi - - # Exit with 0 when trying to delete the zeroth generation. - guix package -p "$profile" --delete-generations=0 -fi +# Exit with 1 when a generation does not exist. +if guix package -p "$profile" --delete-generations=42; +then false; else true; fi + +# Exit with 0 when trying to delete the zeroth generation. +guix package -p "$profile" --delete-generations=0 # Make sure multiple arguments to -i works. guix package --bootstrap -i guile gcc -p "$profile" -n @@ -253,18 +139,6 @@ guix package --bootstrap -i guile-bootstrap test -L "$HOME/.guix-profile" test -f "$HOME/.guix-profile/bin/guile" -if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null -then - guix package --bootstrap -e "$boot_make" - test -f "$HOME/.guix-profile/bin/make" - first_environment="`cd $HOME/.guix-profile ; pwd`" - - guix package --bootstrap --roll-back - test -f "$HOME/.guix-profile/bin/guile" - ! test -f "$HOME/.guix-profile/bin/make" - test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment" -fi - # Move to the empty profile. default_profile="`readlink "$HOME/.guix-profile"`" for i in `seq 1 3` -- cgit v1.2.3