daemon: Add '--gc-keep-outputs' and '--gc-keep-derivations'.

* nix/nix-daemon/guix-daemon.cc (GUIX_OPT_GC_KEEP_OUTPUTS,
  GUIX_OPT_GC_KEEP_DERIVATIONS): New macros.
  (options): Add 'gc-keep-outputs' and 'gc-keep-derivations'.
  (string_to_bool): New function.
  (parse_opt): Honor GUIX_OPT_GC_KEEP_DERIVATIONS and
  GUIX_OPT_GC_KEEP_OUTPUTS.
* doc/guix.texi (Invoking guix-daemon): Document --gc-keep-outputs and
  --gc-keep-derivations.
This commit is contained in:
Ludovic Courtès 2014-02-06 21:49:47 +01:00
parent c37b2b2aa5
commit 6e37066e76
2 changed files with 57 additions and 0 deletions

View File

@ -502,6 +502,30 @@ the daemon makes the new file a hard link to the other file. This
slightly increases the input/output load at the end of a build process.
This option disables this.
@item --gc-keep-outputs[=yes|no]
Tell whether the garbage collector (GC) must keep outputs of live
derivations.
When set to ``yes'', the GC will keep the outputs of any live derivation
available in the store---the @code{.drv} files. The default is ``no'',
meaning that derivation outputs are kept only if they are GC roots.
@item --gc-keep-derivations[=yes|no]
Tell whether the garbage collector (GC) must keep derivations
corresponding to live outputs.
When set to ``yes'', as is the case by default, the GC keeps
derivations---i.e., @code{.drv} files---as long as at least one of their
outputs is live. This allows users to keep track of the origins of
items in their store. Setting it to ``no'' saves a bit of disk space.
Note that when both @code{--gc-keep-derivations} and
@code{--gc-keep-outputs} are used, the effect is to keep all the build
prerequisites (the sources, compiler, libraries, and other build-time
tools) of live objects in the store, regardless of whether these
prerequisites are live. This is convenient for developers since it
saves rebuilds or downloads.
@item --impersonate-linux-2.6
On Linux-based systems, impersonate Linux 2.6. This means that the
kernel's @code{uname} system call will report 2.6 as the release number.

View File

@ -30,6 +30,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <strings.h>
#include <exception>
/* Variables used by `nix-daemon.cc'. */
@ -68,6 +69,8 @@ builds derivations on behalf of its clients.";
#define GUIX_OPT_LISTEN 11
#define GUIX_OPT_NO_SUBSTITUTES 12
#define GUIX_OPT_NO_BUILD_HOOK 13
#define GUIX_OPT_GC_KEEP_OUTPUTS 14
#define GUIX_OPT_GC_KEEP_DERIVATIONS 15
static const struct argp_option options[] =
{
@ -111,6 +114,14 @@ static const struct argp_option options[] =
" (this option has no effect in this configuration)"
#endif
},
{ "gc-keep-outputs", GUIX_OPT_GC_KEEP_OUTPUTS,
"yes/no", OPTION_ARG_OPTIONAL,
"Tell whether the GC must keep outputs of live derivations" },
{ "gc-keep-derivations", GUIX_OPT_GC_KEEP_DERIVATIONS,
"yes/no", OPTION_ARG_OPTIONAL,
"Tell whether the GC must keep derivations corresponding \
to live outputs" },
{ "listen", GUIX_OPT_LISTEN, "SOCKET", 0,
"Listen for connections on SOCKET" },
{ "debug", GUIX_OPT_DEBUG, 0, 0,
@ -118,6 +129,22 @@ static const struct argp_option options[] =
{ 0, 0, 0, 0, 0 }
};
/* Convert ARG to a Boolean value, or throw an error if it does not denote a
Boolean. */
static bool
string_to_bool (const char *arg, bool dflt = true)
{
if (arg == NULL)
return dflt;
else if (strcasecmp (arg, "yes") == 0)
return true;
else if (strcasecmp (arg, "no") == 0)
return false;
else
throw nix::Error (format ("'%1%': invalid Boolean value") % arg);
}
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
@ -168,6 +195,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
case GUIX_OPT_DEBUG:
verbosity = lvlDebug;
break;
case GUIX_OPT_GC_KEEP_OUTPUTS:
settings.gcKeepOutputs = string_to_bool (arg);
break;
case GUIX_OPT_GC_KEEP_DERIVATIONS:
settings.gcKeepDerivations = string_to_bool (arg);
break;
case 'c':
settings.buildCores = atoi (arg);
break;