summary refs log tree commit diff
path: root/nix/nix-daemon
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-01-06 17:33:02 +0100
committerLudovic Courtès <ludo@gnu.org>2013-01-06 17:33:02 +0100
commit4050e5d6cfe8f7af29f10b2f1b3c7febdc10946a (patch)
tree574828c84e7bfb0b6850db4f30fc38bd8143584e /nix/nix-daemon
parent79580eb698d07e4b21334ddfbcbcf620d27b5e41 (diff)
parent233e76769ae3a438bff7117c68f2c88739a28db0 (diff)
downloadguix-4050e5d6cfe8f7af29f10b2f1b3c7febdc10946a.tar.gz
Merge branch 'master' into core-updates
Conflicts:
	build-aux/download.scm
	distro/packages/autotools.scm
	distro/packages/base.scm
	distro/packages/bootstrap.scm
	distro/packages/lsh.scm
	distro/packages/make-bootstrap.scm
	distro/packages/ncurses.scm
	distro/packages/perl.scm
	tests/derivations.scm
	tests/union.scm
Diffstat (limited to 'nix/nix-daemon')
-rw-r--r--nix/nix-daemon/guix-daemon.cc73
-rw-r--r--nix/nix-daemon/shared.hh10
2 files changed, 66 insertions, 17 deletions
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index 79c719399e..7e266111a0 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -1,20 +1,20 @@
-/* Guix --- Nix package management from Guile.         -*- coding: utf-8 -*-
+/* GNU Guix --- Functional package management for GNU
    Copyright (C) 2012  Ludovic Courtès <ludo@gnu.org>
 
-   This file is part of Guix.
+   This file is part of GNU Guix.
 
-   Guix is free software; you can redistribute it and/or modify it
+   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.
 
-   Guix is distributed in the hope that it will be useful, but
+   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 Guix.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
@@ -23,8 +23,13 @@
 #include <globals.hh>
 #include <util.hh>
 
+#include <gcrypt.h>
+
 #include <stdlib.h>
 #include <argp.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <exception>
 
 /* Variables used by `nix-daemon.cc'.  */
 volatile ::sig_atomic_t blockInt;
@@ -58,6 +63,7 @@ builds derivations on behalf of its clients.";
 #define GUIX_OPT_DISABLE_STORE_OPTIMIZATION 7
 #define GUIX_OPT_IMPERSONATE_LINUX_26 8
 #define GUIX_OPT_DEBUG 9
+#define GUIX_OPT_CHROOT_DIR 10
 
 static const struct argp_option options[] =
   {
@@ -74,6 +80,13 @@ static const struct argp_option options[] =
       "this option has no effect)"
 #endif
     },
+    { "chroot-directory", GUIX_OPT_CHROOT_DIR, "DIR", 0,
+      "Add DIR to the build chroot"
+#ifndef HAVE_CHROOT
+      " (chroots are not supported in this configuration, so "
+      "this option has no effect)"
+#endif
+    },
     { "build-users-group", GUIX_OPT_BUILD_USERS_GROUP, "GROUP", 0,
       "Perform builds as a user of GROUP" },
     { "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
@@ -104,6 +117,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case GUIX_OPT_DISABLE_CHROOT:
       settings.useChroot = false;
       break;
+    case GUIX_OPT_CHROOT_DIR:
+      settings.dirsInChroot.insert (arg);
+      break;
     case GUIX_OPT_DISABLE_LOG_COMPRESSION:
       settings.compressLog = false;
       break;
@@ -151,20 +167,53 @@ main (int argc, char *argv[])
 {
   Strings nothing;
 
+  /* Initialize libgcrypt.  */
+  if (!gcry_check_version (GCRYPT_VERSION))
+    {
+      fprintf (stderr, "error: libgcrypt version mismatch\n");
+      exit (EXIT_FAILURE);
+    }
+
 #ifdef HAVE_CHROOT
   settings.useChroot = true;
 #else
   settings.useChroot = false;
 #endif
 
-  settings.processEnvironment ();
+  argvSaved = argv;
+
+  try
+    {
+      settings.processEnvironment ();
 
-  /* FIXME: Disable substitutes until we have something that works.  */
-  settings.useSubstitutes = false;
-  settings.substituters.clear ();
+      /* FIXME: Disable substitutes until we have something that works.  */
+      settings.useSubstitutes = false;
+      settings.substituters.clear ();
 
-  argp_parse (&argp, argc, argv, 0, 0, 0);
+      argp_parse (&argp, argc, argv, 0, 0, 0);
 
-  argvSaved = argv;
-  run (nothing);
+      if (geteuid () == 0 && settings.buildUsersGroup.empty ())
+	fprintf (stderr, "warning: running as root is highly recommended, "
+		 "unless `--build-users-group' is used\n");
+
+#ifdef HAVE_CHROOT
+      if (settings.useChroot)
+	{
+	  foreach (PathSet::iterator, i, settings.dirsInChroot)
+	    {
+	      printMsg (lvlDebug,
+			format ("directory `%1%' added to the chroot") % *i);
+	    }
+	}
+#endif
+
+      run (nothing);
+    }
+  catch (std::exception &e)
+    {
+      fprintf (stderr, "error: %s\n", e.what ());
+      return EXIT_FAILURE;
+    }
+
+  return EXIT_SUCCESS;				  /* never reached */
 }
diff --git a/nix/nix-daemon/shared.hh b/nix/nix-daemon/shared.hh
index a03c09c036..b45e9f0cfd 100644
--- a/nix/nix-daemon/shared.hh
+++ b/nix/nix-daemon/shared.hh
@@ -1,20 +1,20 @@
-/* Guix --- Nix package management from Guile.         -*- coding: utf-8 -*-
+/* GNU Guix --- Functional package management for GNU
    Copyright (C) 2012  Ludovic Courtès <ludo@gnu.org>
 
-   This file is part of Guix.
+   This file is part of GNU Guix.
 
-   Guix is free software; you can redistribute it and/or modify it
+   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.
 
-   Guix is distributed in the hope that it will be useful, but
+   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 Guix.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Replacement for Nix's libmain/shared.hh.  */