summary refs log tree commit diff
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
parentc37b2b2aa5326feeeb4fa8edff988adf6fb96f15 (diff)
downloadguix-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.
-rw-r--r--doc/guix.texi24
-rw-r--r--nix/nix-daemon/guix-daemon.cc33
2 files changed, 57 insertions, 0 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 28b1cb8bd7..af84b75108 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -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.
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;