guix gc: Add '--derivers'.
authorLudovic Courtès <ludo@gnu.org>
Tue, 27 Mar 2018 12:16:19 +0000 (14:16 +0200)
committerLudovic Courtès <ludo@gnu.org>
Tue, 27 Mar 2018 12:51:44 +0000 (14:51 +0200)
* guix/scripts/gc.scm (show-help, %options): Add '--derivers'.
(guix-gc): Handle 'list-derivers'.
* tests/guix-gc.sh: Add test.
* doc/guix.texi (Invoking guix gc): Document it.

doc/guix.texi
guix/scripts/gc.scm
tests/guix-gc.sh

index 2204285..c37a87d 100644 (file)
@@ -2642,6 +2642,24 @@ of these, recursively.  In other words, the returned list is the
 of an element.  @xref{Invoking guix graph}, for a tool to visualize
 the graph of references.
 
+@item --derivers
+@cindex derivation
+Return the derivation(s) leading to the given store items
+(@pxref{Derivations}).
+
+For example, this command:
+
+@example
+guix gc --derivers `guix package -I ^emacs$ | cut -f4`
+@end example
+
+@noindent
+returns the @file{.drv} file(s) leading to the @code{emacs} package
+installed in your profile.
+
+Note that there may be zero matching @file{.drv} files, for instance
+because these files have been garbage-collected.  There can also be more
+than one matching @file{.drv} due to fixed-output derivations.
 @end table
 
 Lastly, the following options allow you to check the integrity of the
index a31d223..e4ed722 100644 (file)
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -61,6 +61,8 @@ Invoke the garbage collector.\n"))
   -R, --requisites       list the requisites of PATHS"))
   (display (G_ "
       --referrers        list the referrers of PATHS"))
+  (display (G_ "
+      --derivers         list the derivers of PATHS"))
   (newline)
   (display (G_ "
       --verify[=OPTS]    verify the integrity of the store; OPTS is a
@@ -153,6 +155,10 @@ Invoke the garbage collector.\n"))
                 (lambda (opt name arg result)
                   (alist-cons 'action 'list-referrers
                               (alist-delete 'action result))))
+        (option '("derivers") #f #f
+                (lambda (opt name arg result)
+                  (alist-cons 'action 'list-derivers
+                              (alist-delete 'action result))))
         (option '("list-failures") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'action 'list-failures
@@ -241,6 +247,8 @@ Invoke the garbage collector.\n"))
                            (requisites store (list item)))))
         ((list-referrers)
          (list-relatives referrers))
+        ((list-derivers)
+         (list-relatives valid-derivers))
         ((optimize)
          (assert-no-extra-arguments)
          (optimize-store store))
index efbc7e7..ef2d954 100644 (file)
@@ -1,5 +1,5 @@
 # GNU Guix --- Functional package management for GNU
-# Copyright © 2013, 2015, 2017 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2013, 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
 #
 # This file is part of GNU Guix.
 #
@@ -54,6 +54,9 @@ guix gc --references "$out/bin/guile"
 if guix gc --references /dev/null;
 then false; else true; fi
 
+# Check derivers.
+guix gc --derivers "$out" | grep "$drv"
+
 # Add then reclaim a .drv file.
 drv="`guix build idutils -d`"
 test -f "$drv"