2013-01-06 00:47:50 +01:00
|
|
|
|
/* GNU Guix --- Functional package management for GNU
|
2013-02-19 22:48:13 +01:00
|
|
|
|
Copyright (C) 2012, 2013 Ludovic Courtès <ludo@gnu.org>
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
2013-01-06 00:47:50 +01:00
|
|
|
|
This file is part of GNU Guix.
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
2013-01-06 00:47:50 +01:00
|
|
|
|
GNU Guix is free software; you can redistribute it and/or modify it
|
2012-12-03 23:04:47 +01:00
|
|
|
|
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.
|
|
|
|
|
|
2013-01-06 00:47:50 +01:00
|
|
|
|
GNU Guix is distributed in the hope that it will be useful, but
|
2012-12-03 23:04:47 +01:00
|
|
|
|
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
|
2013-01-06 00:47:50 +01:00
|
|
|
|
along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <types.hh>
|
|
|
|
|
#include "shared.hh"
|
|
|
|
|
#include <globals.hh>
|
2012-12-15 00:06:09 +01:00
|
|
|
|
#include <util.hh>
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
2013-01-02 01:07:53 +01:00
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
|
2012-12-03 23:04:47 +01:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <argp.h>
|
2012-12-16 18:13:59 +01:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
2012-12-16 18:28:00 +01:00
|
|
|
|
#include <exception>
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
|
|
|
|
/* Variables used by `nix-daemon.cc'. */
|
|
|
|
|
volatile ::sig_atomic_t blockInt;
|
|
|
|
|
char **argvSaved;
|
|
|
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
/* Entry point in `nix-daemon.cc'. */
|
|
|
|
|
extern void run (Strings args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Command-line options. */
|
|
|
|
|
|
|
|
|
|
const char *argp_program_version =
|
|
|
|
|
"guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
|
|
|
|
|
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
|
|
|
|
|
|
|
|
|
|
static char doc[] =
|
|
|
|
|
"guix-daemon -- perform derivation builds and store accesses\
|
|
|
|
|
\v\
|
|
|
|
|
This program is a daemon meant to run in the background. It serves \
|
|
|
|
|
requests sent over a Unix-domain socket. It accesses the store, and \
|
|
|
|
|
builds derivations on behalf of its clients.";
|
|
|
|
|
|
|
|
|
|
#define GUIX_OPT_SYSTEM 1
|
|
|
|
|
#define GUIX_OPT_DISABLE_CHROOT 2
|
2012-12-06 22:21:45 +01:00
|
|
|
|
#define GUIX_OPT_BUILD_USERS_GROUP 3
|
|
|
|
|
#define GUIX_OPT_CACHE_FAILURES 4
|
|
|
|
|
#define GUIX_OPT_LOSE_LOGS 5
|
|
|
|
|
#define GUIX_OPT_DISABLE_LOG_COMPRESSION 6
|
|
|
|
|
#define GUIX_OPT_DISABLE_STORE_OPTIMIZATION 7
|
|
|
|
|
#define GUIX_OPT_IMPERSONATE_LINUX_26 8
|
2012-12-15 00:06:09 +01:00
|
|
|
|
#define GUIX_OPT_DEBUG 9
|
2012-12-16 18:09:27 +01:00
|
|
|
|
#define GUIX_OPT_CHROOT_DIR 10
|
2013-02-19 22:48:13 +01:00
|
|
|
|
#define GUIX_OPT_LISTEN 11
|
2013-04-18 22:46:34 +02:00
|
|
|
|
#define GUIX_OPT_NO_SUBSTITUTES 12
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
|
|
|
|
static const struct argp_option options[] =
|
|
|
|
|
{
|
|
|
|
|
{ "system", GUIX_OPT_SYSTEM, "SYSTEM", 0,
|
|
|
|
|
"Assume SYSTEM as the current system type" },
|
2013-01-09 12:14:23 +01:00
|
|
|
|
{ "cores", 'c', "N", 0,
|
2012-12-03 23:04:47 +01:00
|
|
|
|
"Use N CPU cores to build each derivation; 0 means as many as available" },
|
|
|
|
|
{ "max-jobs", 'M', "N", 0,
|
|
|
|
|
"Allow at most N build jobs" },
|
|
|
|
|
{ "disable-chroot", GUIX_OPT_DISABLE_CHROOT, 0, 0,
|
2012-12-05 15:22:28 +01:00
|
|
|
|
"Disable chroot builds"
|
|
|
|
|
#ifndef HAVE_CHROOT
|
|
|
|
|
" (chroots are not supported in this configuration, so "
|
|
|
|
|
"this option has no effect)"
|
2012-12-16 18:09:27 +01:00
|
|
|
|
#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)"
|
2012-12-05 15:22:28 +01:00
|
|
|
|
#endif
|
|
|
|
|
},
|
2012-12-06 22:21:45 +01:00
|
|
|
|
{ "build-users-group", GUIX_OPT_BUILD_USERS_GROUP, "GROUP", 0,
|
|
|
|
|
"Perform builds as a user of GROUP" },
|
2013-04-18 22:46:34 +02:00
|
|
|
|
{ "no-substitutes", GUIX_OPT_NO_SUBSTITUTES, 0, 0,
|
|
|
|
|
"Do not use substitutes" },
|
2012-12-06 22:21:45 +01:00
|
|
|
|
{ "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
|
|
|
|
|
"Cache build failures" },
|
|
|
|
|
{ "lose-logs", GUIX_OPT_LOSE_LOGS, 0, 0,
|
|
|
|
|
"Do not keep build logs" },
|
2012-12-03 23:04:47 +01:00
|
|
|
|
{ "disable-log-compression", GUIX_OPT_DISABLE_LOG_COMPRESSION, 0, 0,
|
|
|
|
|
"Disable compression of the build logs" },
|
2012-12-06 22:21:45 +01:00
|
|
|
|
{ "disable-store-optimization", GUIX_OPT_DISABLE_STORE_OPTIMIZATION, 0, 0,
|
|
|
|
|
"Disable automatic file \"deduplication\" in the store" },
|
|
|
|
|
{ "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0, 0,
|
|
|
|
|
"Impersonate Linux 2.6"
|
|
|
|
|
#ifndef HAVE_SYS_PERSONALITY_H
|
|
|
|
|
" (this option has no effect in this configuration)"
|
|
|
|
|
#endif
|
|
|
|
|
},
|
2013-02-19 22:48:13 +01:00
|
|
|
|
{ "listen", GUIX_OPT_LISTEN, "SOCKET", 0,
|
|
|
|
|
"Listen for connections on SOCKET" },
|
2012-12-15 00:06:09 +01:00
|
|
|
|
{ "debug", GUIX_OPT_DEBUG, 0, 0,
|
|
|
|
|
"Produce debugging output" },
|
2012-12-03 23:04:47 +01:00
|
|
|
|
{ 0, 0, 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Parse a single option. */
|
|
|
|
|
static error_t
|
|
|
|
|
parse_opt (int key, char *arg, struct argp_state *state)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case GUIX_OPT_DISABLE_CHROOT:
|
|
|
|
|
settings.useChroot = false;
|
|
|
|
|
break;
|
2012-12-16 18:09:27 +01:00
|
|
|
|
case GUIX_OPT_CHROOT_DIR:
|
|
|
|
|
settings.dirsInChroot.insert (arg);
|
|
|
|
|
break;
|
2012-12-03 23:04:47 +01:00
|
|
|
|
case GUIX_OPT_DISABLE_LOG_COMPRESSION:
|
|
|
|
|
settings.compressLog = false;
|
|
|
|
|
break;
|
2012-12-06 22:21:45 +01:00
|
|
|
|
case GUIX_OPT_BUILD_USERS_GROUP:
|
|
|
|
|
settings.buildUsersGroup = arg;
|
|
|
|
|
break;
|
|
|
|
|
case GUIX_OPT_DISABLE_STORE_OPTIMIZATION:
|
|
|
|
|
settings.autoOptimiseStore = false;
|
|
|
|
|
break;
|
|
|
|
|
case GUIX_OPT_CACHE_FAILURES:
|
|
|
|
|
settings.cacheFailure = true;
|
|
|
|
|
break;
|
|
|
|
|
case GUIX_OPT_IMPERSONATE_LINUX_26:
|
|
|
|
|
settings.impersonateLinux26 = true;
|
|
|
|
|
break;
|
|
|
|
|
case GUIX_OPT_LOSE_LOGS:
|
|
|
|
|
settings.keepLog = false;
|
|
|
|
|
break;
|
2013-02-19 22:48:13 +01:00
|
|
|
|
case GUIX_OPT_LISTEN:
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
settings.nixDaemonSocketFile = canonPath (arg);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "error: %s\n", e.what ());
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-04-18 22:46:34 +02:00
|
|
|
|
case GUIX_OPT_NO_SUBSTITUTES:
|
|
|
|
|
settings.useSubstitutes = false;
|
|
|
|
|
break;
|
2012-12-15 00:06:09 +01:00
|
|
|
|
case GUIX_OPT_DEBUG:
|
|
|
|
|
verbosity = lvlDebug;
|
|
|
|
|
break;
|
2013-01-09 12:14:23 +01:00
|
|
|
|
case 'c':
|
2012-12-03 23:04:47 +01:00
|
|
|
|
settings.buildCores = atoi (arg);
|
|
|
|
|
break;
|
|
|
|
|
case 'M':
|
|
|
|
|
settings.maxBuildJobs = atoi (arg);
|
|
|
|
|
break;
|
|
|
|
|
case GUIX_OPT_SYSTEM:
|
|
|
|
|
settings.thisSystem = arg;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-07-04 22:46:26 +02:00
|
|
|
|
return (error_t) ARGP_ERR_UNKNOWN;
|
2012-12-03 23:04:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 22:46:26 +02:00
|
|
|
|
return (error_t) 0;
|
2012-12-03 23:04:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Argument parsing. */
|
|
|
|
|
static struct argp argp = { options, parse_opt, 0, doc };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
Strings nothing;
|
|
|
|
|
|
2013-01-02 01:07:53 +01:00
|
|
|
|
/* Initialize libgcrypt. */
|
|
|
|
|
if (!gcry_check_version (GCRYPT_VERSION))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "error: libgcrypt version mismatch\n");
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-05 15:22:28 +01:00
|
|
|
|
#ifdef HAVE_CHROOT
|
2012-12-03 23:04:47 +01:00
|
|
|
|
settings.useChroot = true;
|
2012-12-05 15:22:28 +01:00
|
|
|
|
#else
|
|
|
|
|
settings.useChroot = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-16 18:28:00 +01:00
|
|
|
|
argvSaved = argv;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
settings.processEnvironment ();
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
2013-04-02 10:44:20 +02:00
|
|
|
|
/* Use our substituter by default. */
|
2012-12-16 18:28:00 +01:00
|
|
|
|
settings.substituters.clear ();
|
2013-04-18 22:46:34 +02:00
|
|
|
|
settings.useSubstitutes = true;
|
2012-12-14 23:51:20 +01:00
|
|
|
|
|
2012-12-16 18:28:00 +01:00
|
|
|
|
argp_parse (&argp, argc, argv, 0, 0, 0);
|
2012-12-03 23:04:47 +01:00
|
|
|
|
|
2013-04-18 22:46:34 +02:00
|
|
|
|
if (settings.useSubstitutes)
|
|
|
|
|
{
|
|
|
|
|
string subs = getEnv ("NIX_SUBSTITUTERS", "default");
|
|
|
|
|
|
|
|
|
|
if (subs == "default")
|
|
|
|
|
settings.substituters.push_back (settings.nixLibexecDir
|
|
|
|
|
+ "/guix/substitute-binary");
|
|
|
|
|
else
|
|
|
|
|
settings.substituters = tokenizeString<Strings> (subs, ":");
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-16 18:28:00 +01:00
|
|
|
|
if (geteuid () == 0 && settings.buildUsersGroup.empty ())
|
2013-01-09 12:16:26 +01:00
|
|
|
|
fprintf (stderr, "warning: daemon is running as root, so "
|
|
|
|
|
"using `--build-users-group' is highly recommended\n");
|
2012-12-16 18:13:59 +01:00
|
|
|
|
|
2013-01-02 18:31:40 +01:00
|
|
|
|
#ifdef HAVE_CHROOT
|
|
|
|
|
if (settings.useChroot)
|
|
|
|
|
{
|
|
|
|
|
foreach (PathSet::iterator, i, settings.dirsInChroot)
|
|
|
|
|
{
|
|
|
|
|
printMsg (lvlDebug,
|
|
|
|
|
format ("directory `%1%' added to the chroot") % *i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-02-19 22:48:13 +01:00
|
|
|
|
printMsg (lvlDebug,
|
|
|
|
|
format ("listening on `%1%'") % settings.nixDaemonSocketFile);
|
|
|
|
|
|
2012-12-16 18:28:00 +01:00
|
|
|
|
run (nothing);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "error: %s\n", e.what ());
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS; /* never reached */
|
2012-12-03 23:04:47 +01:00
|
|
|
|
}
|