From 6e37066e76ce4ffaf8328242d941ca2e0af2965a Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 6 Feb 2014 21:49:47 +0100 Subject: 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. --- nix/nix-daemon/guix-daemon.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'nix/nix-daemon') diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index d35b1cd076..79cd080363 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include /* 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; -- cgit 1.4.1