pack: Add '--localstatedir' option.

* guix/scripts/pack.scm (self-contained-tarball): Add #:localstatedir?
parameter and honor it.
(%options, show-help): Add '--localstatedir'.
(guix-pack): Honor it.
* gnu/build/install.scm (populate-single-profile-directory): Add
 #:register? parameter and honor it.
* doc/guix.texi (Binary Installation): Use '--localstatedir' in
example.
(Invoking guix pack): Document it.
This commit is contained in:
Ludovic Courtès 2017-03-14 15:11:03 +01:00
parent 9b05ccfedd
commit 6b63c43e06
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
4 changed files with 56 additions and 21 deletions

View file

@ -488,7 +488,7 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \
guix-binary.%.tar.xz:
$(AM_V_GEN)GUIX_PACKAGE_PATH= \
tarball=`$(top_builddir)/pre-inst-env guix pack -C xz \
-s "$*" guix` ; \
-s "$*" --localstatedir guix` ; \
cp "$$tarball" "$@.tmp" ; mv "$@.tmp" "$@"

View file

@ -535,7 +535,7 @@ make guix-binary.@var{system}.tar.xz
... which, in turn, runs:
@example
guix pack -s @var{system} guix
guix pack -s @var{system} --localstatedir guix
@end example
@xref{Invoking guix pack}, for more info on this handy tool.
@ -2434,6 +2434,19 @@ the system type of the build host.
@itemx -C @var{tool}
Compress the resulting tarball using @var{tool}---one of @code{gzip},
@code{bzip2}, @code{xz}, or @code{lzip}.
@item --localstatedir
Include the ``local state directory'', @file{/var/guix}, in the
resulting pack.
@file{/var/guix} contains the store database (@pxref{The Store}) as well
as garbage-collector roots (@pxref{Invoking guix gc}). Providing it in
the pack means that the store is ``complete'' and manageable by Guix;
not providing it pack means that the store is ``dead'': items cannot be
added to it or removed from it after extraction of the pack.
One use case for this is the Guix self-contained binary tarball
(@pxref{Binary Installation}).
@end table
In addition, @command{guix pack} supports all the common build options

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
;;;
;;; This file is part of GNU Guix.
@ -192,13 +192,16 @@ (define* (register-closure store closure
(define* (populate-single-profile-directory directory
#:key profile closure
deduplicate?)
deduplicate?
register?)
"Populate DIRECTORY with a store containing PROFILE, whose closure is given
in the file called CLOSURE (as generated by #:references-graphs.) DIRECTORY
is initialized to contain a single profile under /root pointing to PROFILE.
DEDUPLICATE? determines whether to deduplicate files in the store.
When REGISTER? is true, initialize DIRECTORY/var/guix/db to reflect the
contents of the store; DEDUPLICATE? determines whether to deduplicate files in
the store.
This is used to create the self-contained Guix tarball."
This is used to create the self-contained tarballs with 'guix pack'."
(define (scope file)
(string-append directory "/" file))
@ -213,6 +216,8 @@ (define (symlink* old new)
;; Populate the store.
(populate-store (list closure) directory)
(when register?
(register-closure (canonicalize-path directory) closure
#:deduplicate? deduplicate?)
@ -220,7 +225,7 @@ (define (symlink* old new)
;; target uses $TMPDIR. Fix that.
(delete-file (scope "/var/guix/gcroots/profiles"))
(symlink* "/var/guix/profiles"
"/var/guix/gcroots/profiles")
"/var/guix/gcroots/profiles"))
;; Make root's profile, which makes it a GC root.
(mkdir-p* %root-profile)

View file

@ -69,10 +69,12 @@ (define (lookup-compressor name)
(define* (self-contained-tarball name profile
#:key deduplicate?
(compressor (first %compressors)))
(compressor (first %compressors))
localstatedir?)
"Return a self-contained tarball containing a store initialized with the
closure of PROFILE, a derivation. The tarball contains /gnu/store, /var/guix,
and PROFILE is available as /root/.guix-profile."
closure of PROFILE, a derivation. The tarball contains /gnu/store; if
LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db
with a properly initialized store database."
(define build
(with-imported-modules '((guix build utils)
(guix build store-copy)
@ -85,7 +87,10 @@ (define %root "root")
;; We need Guix here for 'guix-register'.
(setenv "PATH"
(string-append #$guix "/sbin:" #$tar "/bin:"
(string-append #$(if localstatedir?
(file-append guix "/sbin:")
"")
#$tar "/bin:"
#$(compressor-package compressor) "/bin"))
;; Note: there is not much to gain here with deduplication and
@ -94,7 +99,8 @@ (define %root "root")
(populate-single-profile-directory %root
#:profile #$profile
#:closure "profile"
#:deduplicate? #f)
#:deduplicate? #f
#:register? #$localstatedir?)
;; Create the tarball. Use GNU format so there's no file name
;; length limitation.
@ -119,7 +125,10 @@ (define %root "root")
;; extracting the archive. Do not include /root
;; because the root account might have a
;; different home directory.
"./var/guix"
#$@(if localstatedir?
'("./var/guix")
'())
(string-append "." (%store-directory))))))))
(gexp->derivation (string-append name ".tar."
@ -163,6 +172,9 @@ (define %options
(lambda (opt name arg result)
(alist-cons 'compressor (lookup-compressor arg)
result)))
(option '("localstatedir") #f #f
(lambda (opt name arg result)
(alist-cons 'localstatedir? #t result)))
(append %transformation-options
%standard-build-options)))
@ -178,6 +190,8 @@ (define (show-help)
-s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\""))
(display (_ "
-C, --compression=TOOL compress using TOOL--e.g., \"lzip\""))
(display (_ "
--localstatedir include /var/guix in the resulting pack"))
(newline)
(display (_ "
-h, --help display this help and exit"))
@ -209,14 +223,17 @@ (define opts
(specification->package+output spec))
list))
specs))
(compressor (assoc-ref opts 'compressor)))
(compressor (assoc-ref opts 'compressor))
(localstatedir? (assoc-ref opts 'localstatedir?)))
(with-store store
(run-with-store store
(mlet* %store-monad ((profile (profile-derivation
(packages->manifest packages)))
(drv (self-contained-tarball "pack" profile
#:compressor
compressor)))
compressor
#:localstatedir?
localstatedir?)))
(mbegin %store-monad
(show-what-to-build* (list drv)
#:use-substitutes?