guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/02: build: Protect against misconfiguration of localstatedir.


From: Ludovic Courtès
Subject: 02/02: build: Protect against misconfiguration of localstatedir.
Date: Sat, 19 Mar 2016 14:08:07 +0000

civodul pushed a commit to branch master
in repository guix.

commit ef5f5c8659b1ca3999e362dfa33478e0a0150ced
Author: Ludovic Courtès <address@hidden>
Date:   Sat Mar 19 14:45:58 2016 +0100

    build: Protect against misconfiguration of localstatedir.
    
    Suggested by Jookia <address@hidden>.
    
    * m4/guix.m4 (GUIX_CURRENT_LOCALSTATEDIR, GUIX_CHECK_LOCALSTATEDIR): New
    macros.
    * config-daemon.ac: Use 'GUIX_CHECK_LOCALSTATEDIR'.
    * Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Add --localstatedir.
    * doc/guix.texi (Requirements): Mention --localstatedir.
    (The Store): Mention LOCALSTATEDIR as such.
---
 Makefile.am      |    4 ++++
 config-daemon.ac |    2 ++
 doc/guix.texi    |   14 +++++++++++---
 m4/guix.m4       |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 8a54307..a9c281d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -421,7 +421,11 @@ include daemon.am
 endif BUILD_DAEMON
 
 ACLOCAL_AMFLAGS = -I m4
+
+# Pass an explicit '--localstatedir' so that configure does not error out if
+# it finds an existing installation with a different localstatedir.
 AM_DISTCHECK_CONFIGURE_FLAGS =                 \
+  --localstatedir="$$dc_install_base/var"      \
   --with-libgcrypt-prefix="$(LIBGCRYPT_PREFIX)"        \
   --with-libgcrypt-libdir="$(LIBGCRYPT_LIBDIR)"        \
   --with-nix-prefix="$(NIX_PREFIX)"            \
diff --git a/config-daemon.ac b/config-daemon.ac
index 63174d6..803eb53 100644
--- a/config-daemon.ac
+++ b/config-daemon.ac
@@ -140,6 +140,8 @@ if test "x$guix_build_daemon" = "xyes"; then
   GUIX_TEST_ROOT="$ac_cv_guix_test_root"
   AC_SUBST([GUIX_TEST_ROOT])
 
+  GUIX_CHECK_LOCALSTATEDIR
+
   AC_CONFIG_FILES([nix/scripts/list-runtime-roots],
     [chmod +x nix/scripts/list-runtime-roots])
   AC_CONFIG_FILES([nix/scripts/substitute],
diff --git a/doc/guix.texi b/doc/guix.texi
index b36be05..868948a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -527,6 +527,14 @@ following packages are also needed:
 C++11 standard.
 @end itemize
 
+When configuring Guix on a system that already has a Guix installation,
+be sure to specify the same state directory as the existing installation
+using the @code{--localstatedir} option of the @command{configure}
+script (@pxref{Directory Variables, @code{localstatedir},, standards,
+GNU Coding Standards}).  The @command{configure} script protects against
+unintended misconfiguration of @var{localstatedir} so you do not
+inadvertently corrupt your store (@pxref{The Store}).
+
 When a working installation of @url{http://nixos.org/nix/, the Nix package
 manager} is available, you
 can instead configure Guix with @code{--disable-daemon}.  In that case,
@@ -2945,9 +2953,9 @@ Sub-directories in the store are referred to as 
@dfn{store items} or
 sometimes @dfn{store paths}.  The store has an associated database that
 contains information such as the store paths referred to by each store
 path, and the list of @emph{valid} store items---results of successful
-builds.  This database resides in @file{/var/guix/db} (or under whatever
-state directory was specified @i{via} @option{--localstatedir} at
-configure time).
+builds.  This database resides in @address@hidden/guix/db},
+where @var{localstatedir} is the state directory specified @i{via}
address@hidden at configure time, usually @file{/var}.
 
 The store is @emph{always} accessed by the daemon on behalf of its clients
 (@pxref{Invoking guix-daemon}).  To manipulate the store, clients
diff --git a/m4/guix.m4 b/m4/guix.m4
index acfc33e..2d3dfd2 100644
--- a/m4/guix.m4
+++ b/m4/guix.m4
@@ -307,3 +307,49 @@ AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
      fi])
   $1="$guix_cv_libgcrypt_libdir"
 ])
+
+dnl GUIX_CURRENT_LOCALSTATEDIR
+dnl
+dnl Determine the localstatedir of an existing Guix installation and set
+dnl 'guix_cv_current_localstatedir' accordingly.  Set it to "none" if no
+dnl existing installation was found.
+AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
+  AC_PATH_PROG([GUILE], [guile])
+  AC_CACHE_CHECK([the current installation's localstatedir],
+    [guix_cv_current_localstatedir],
+    [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
+     guix_cv_current_localstatedir="`"$GUILE" \
+       -c '(use-modules (guix config))
+           (when (string=? %store-directory "'$storedir'")
+             (display (dirname %state-directory)))' \
+       2>/dev/null`"
+     if test "x$guix_cv_current_localstatedir" = "x"; then
+       guix_cv_current_localstatedir=none
+     fi])])
+
+dnl GUIX_CHECK_LOCALSTATEDIR
+dnl
+dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
+dnl Guix installation, if any.  Error out or warn if they do not match.
+AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
+  AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
+  if test "x$guix_cv_current_localstatedir" != "xnone"; then
+    if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
+      case "$localstatedir" in
+        NONE|\${prefix}*)
+          # User kept the default value---i.e., did not pass '--localstatedir'.
+          AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not 
match \
+that of the existing installation '$guix_cv_current_localstatedir'
+Installing may corrupt $storedir!
+Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
+          ;;
+        *)
+          # User passed an explicit '--localstatedir'.  Assume they know what
+          # they're doing.
+          AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not 
match \
+that of the existing installation '$guix_cv_current_localstatedir'])
+          AC_MSG_WARN([installing may corrupt $storedir!])
+         ;;
+      esac
+    fi
+  fi])



reply via email to

[Prev in Thread] Current Thread [Next in Thread]