pack: Add '--profile-name'.

* guix/scripts/pack.scm (self-contained-tarball): Add #:profile-name and
honor it.
(squashfs-image, docker-image): Add #:profile-name.
(%default-options): Add 'profile-name'.
(%options, show-help): Add "--profile-name".
(guix-pack): Honor it.
* tests/guix-pack-localstatedir.sh: New file.
* Makefile.am (SH_TESTS): Add it.
* doc/guix.texi (Invoking guix pack): Document "--profile-name".
This commit is contained in:
Ludovic Courtès 2018-10-20 19:28:05 +02:00
parent 4bd5b9707e
commit 08f410834b
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
4 changed files with 94 additions and 3 deletions

View file

@ -410,6 +410,7 @@ SH_TESTS = \
tests/guix-gc.sh \
tests/guix-hash.sh \
tests/guix-pack.sh \
tests/guix-pack-localstatedir.sh \
tests/guix-pack-relocatable.sh \
tests/guix-package.sh \
tests/guix-package-net.sh \

View file

@ -3488,8 +3488,11 @@ For instance, @code{-S /opt/gnu/bin=bin} creates a @file{/opt/gnu/bin}
symlink pointing to the @file{bin} sub-directory of the profile.
@item --localstatedir
Include the ``local state directory'', @file{/var/guix}, in the
resulting pack.
@itemx --profile-name=@var{name}
Include the ``local state directory'', @file{/var/guix}, in the resulting
pack, and notably the @file{/var/guix/profiles/per-user/root/@var{name}}
profile---by default @var{name} is @code{guix-profile}, which corresponds to
@file{~root/.guix-profile}.
@file{/var/guix} contains the store database (@pxref{The Store}) as well
as garbage-collector roots (@pxref{Invoking guix gc}). Providing it in

View file

@ -149,6 +149,7 @@ (define (read-closure closure)
(define* (self-contained-tarball name profile
#:key target
(profile-name "guix-profile")
deduplicate?
(compressor (first %compressors))
localstatedir?
@ -221,6 +222,7 @@ (define tar-supports-sort?
;; <http://lists.gnu.org/archive/html/bug-tar/2017-11/msg00009.html>.
(populate-single-profile-directory %root
#:profile #$profile
#:profile-name #$profile-name
#:closure "profile"
#:database #+database)
@ -279,6 +281,7 @@ (define tar-supports-sort?
(define* (squashfs-image name profile
#:key target
(profile-name "guix-profile")
(compressor (first %compressors))
localstatedir?
(symlinks '())
@ -377,6 +380,7 @@ (define database #+database)
(define* (docker-image name profile
#:key target
(profile-name "guix-profile")
(compressor (first %compressors))
localstatedir?
(symlinks '())
@ -587,6 +591,7 @@ (define (map-manifest-entries proc manifest)
(define %default-options
;; Alist of default option values.
`((format . tarball)
(profile-name . "guix-profile")
(system . ,(%current-system))
(substitutes? . #t)
(build-hook? . #t)
@ -658,6 +663,13 @@ (define %options
(option '("localstatedir") #f #f
(lambda (opt name arg result)
(alist-cons 'localstatedir? #t result)))
(option '("profile-name") #t #f
(lambda (opt name arg result)
(match arg
((or "guix-profile" "current-guix")
(alist-cons 'profile-name arg result))
(_
(leave (G_ "~a: unsupported profile name~%") arg)))))
(option '("bootstrap") #f #f
(lambda (opt name arg result)
(alist-cons 'bootstrap? #t result)))
@ -690,6 +702,9 @@ (define (show-help)
-m, --manifest=FILE create a pack with the manifest from FILE"))
(display (G_ "
--localstatedir include /var/guix in the resulting pack"))
(display (G_ "
--profile-name=NAME
populate /var/guix/profiles/.../NAME"))
(display (G_ "
--bootstrap use the bootstrap binaries to build the pack"))
(newline)
@ -779,7 +794,8 @@ (define (manifest-from-args store opts)
(#f
(leave (G_ "~a: unknown pack format~%")
pack-format))))
(localstatedir? (assoc-ref opts 'localstatedir?)))
(localstatedir? (assoc-ref opts 'localstatedir?))
(profile-name (assoc-ref opts 'profile-name)))
(run-with-store store
(mlet* %store-monad ((profile (profile-derivation
manifest
@ -798,6 +814,8 @@ (define (manifest-from-args store opts)
symlinks
#:localstatedir?
localstatedir?
#:profile-name
profile-name
#:archiver
archiver)))
(mbegin %store-monad

View file

@ -0,0 +1,69 @@
# GNU Guix --- Functional package management for GNU
# Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
#
# 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 <http://www.gnu.org/licenses/>.
#
# Test the 'guix pack --localstatedir' command-line utility.
#
guix pack --version
# 'guix pack --localstatedir' produces derivations that depend on
# guile-sqlite3 and guile-gcrypt. To make that relatively inexpensive, run
# the test in the user's global store if possible, on the grounds that
# binaries may already be there or can be built or downloaded inexpensively.
NIX_STORE_DIR="`guile -c '(use-modules (guix config))(display %storedir)'`"
localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
export NIX_STORE_DIR GUIX_DAEMON_SOCKET
if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
then
exit 77
fi
# Build a tarball with '--localstatedir'
the_pack="`guix pack -C none --localstatedir --profile-name=current-guix \
guile-bootstrap`"
test_directory="`mktemp -d`"
trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
cd "$test_directory"
tar -xf "$the_pack"
profile="`find -name current-guix`"
test "`readlink $profile`" = "current-guix-1-link"
test -s "`dirname $profile`/../../../db/db.sqlite"
test -x ".`guix build guile-bootstrap`/bin/guile"
cd -
# Make sure the store database is not completely bogus.
guile -c "(use-modules (sqlite3) (guix config) (ice-9 match))
(define db
(sqlite-open (string-append \"$test_directory\"
%localstatedir
\"/guix/db/db.sqlite\")
SQLITE_OPEN_READONLY))
(define stmt
(sqlite-prepare db \"SELECT * FROM ValidPaths;\"))
(match (sqlite-fold cons '() stmt)
((#(ids paths hashes times derivers sizes) ...)
(exit (member \"`guix build guile-bootstrap`\" paths))))"