summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-02-06 21:49:47 +0100
committerLudovic Courtès <ludo@gnu.org>2014-02-06 21:49:47 +0100
commit6e37066e76ce4ffaf8328242d941ca2e0af2965a (patch)
tree9d7337bc9b5ccc940e2df491582c036f85e08e74 /nix
parentc37b2b2aa5326feeeb4fa8edff988adf6fb96f15 (diff)
downloadpatches-6e37066e76ce4ffaf8328242d941ca2e0af2965a.tar
patches-6e37066e76ce4ffaf8328242d941ca2e0af2965a.tar.gz
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.
Diffstat (limited to 'nix')
-rw-r--r--nix/nix-daemon/guix-daemon.cc33
1 files changed, 33 insertions, 0 deletions
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 <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;