summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--doc/guix.texi7
-rw-r--r--guix/scripts/pack.scm20
-rw-r--r--tests/guix-pack-localstatedir.sh69
4 files changed, 94 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index eda87f3124..70ec2e52ef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/doc/guix.texi b/doc/guix.texi
index 648f3e50bd..594aca731a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -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
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index a86b95dd38..ce46f549cc 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -149,6 +149,7 @@ dependencies are registered."
(define* (self-contained-tarball name profile
#:key target
+ (profile-name "guix-profile")
deduplicate?
(compressor (first %compressors))
localstatedir?
@@ -221,6 +222,7 @@ added to the pack."
;; <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 @@ added to the pack."
(define* (squashfs-image name profile
#:key target
+ (profile-name "guix-profile")
(compressor (first %compressors))
localstatedir?
(symlinks '())
@@ -377,6 +380,7 @@ added to the pack."
(define* (docker-image name profile
#:key target
+ (profile-name "guix-profile")
(compressor (first %compressors))
localstatedir?
(symlinks '())
@@ -587,6 +591,7 @@ please email '~a'~%")
(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 @@ please email '~a'~%")
(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)))
@@ -691,6 +703,9 @@ Create a bundle of PACKAGE.\n"))
(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)
(display (G_ "
@@ -779,7 +794,8 @@ Create a bundle of PACKAGE.\n"))
(#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 @@ Create a bundle of PACKAGE.\n"))
symlinks
#:localstatedir?
localstatedir?
+ #:profile-name
+ profile-name
#:archiver
archiver)))
(mbegin %store-monad
diff --git a/tests/guix-pack-localstatedir.sh b/tests/guix-pack-localstatedir.sh
new file mode 100644
index 0000000000..b734b0f7e3
--- /dev/null
+++ b/tests/guix-pack-localstatedir.sh
@@ -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))))"