summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-04-06 22:29:18 +0200
committerLudovic Courtès <ludo@gnu.org>2019-04-10 17:09:47 +0200
commitbacf980c76c94e7bda86220ca4bf662d0e34a45a (patch)
treecc5a7f09074b6b9d26e017d1a6d3c532722968cd
parent72eda0624be89ed18302fd7d7f22976071ab020c (diff)
guix gc: Add '--list-roots'.
* guix/scripts/gc.scm (show-help, %options): Add '--list-roots'. (guix-gc)[list-roots]: New procedure. Handle '--list-roots'. * tests/guix-gc.sh: Test it. * doc/guix.texi (Invoking guix gc): Document it.
-rw-r--r--doc/guix.texi6
-rw-r--r--guix/scripts/gc.scm21
-rw-r--r--tests/guix-gc.sh6
3 files changed, 29 insertions, 4 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 2f9fcbe3bf8..2345617b2e8 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -3385,7 +3385,7 @@ deleted. The set of garbage collector roots (``GC roots'' for short)
3385includes default user profiles; by default, the symlinks under 3385includes default user profiles; by default, the symlinks under
3386@file{/var/guix/gcroots} represent these GC roots. New GC roots can be 3386@file{/var/guix/gcroots} represent these GC roots. New GC roots can be
3387added with @command{guix build --root}, for example (@pxref{Invoking 3387added with @command{guix build --root}, for example (@pxref{Invoking
3388guix build}). 3388guix build}). The @command{guix gc --list-roots} command lists them.
3389 3389
3390Prior to running @code{guix gc --collect-garbage} to make space, it is 3390Prior to running @code{guix gc --collect-garbage} to make space, it is
3391often useful to remove old generations from user profiles; that way, old 3391often useful to remove old generations from user profiles; that way, old
@@ -3451,6 +3451,10 @@ This prints nothing unless the daemon was started with
3451@option{--cache-failures} (@pxref{Invoking guix-daemon, 3451@option{--cache-failures} (@pxref{Invoking guix-daemon,
3452@option{--cache-failures}}). 3452@option{--cache-failures}}).
3453 3453
3454@item --list-roots
3455List the GC roots owned by the user; when run as root, list @emph{all} the GC
3456roots.
3457
3454@item --clear-failures 3458@item --clear-failures
3455Remove the specified store items from the failed-build cache. 3459Remove the specified store items from the failed-build cache.
3456 3460
diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm
index 6f37b767ffa..2606e20deb1 100644
--- a/guix/scripts/gc.scm
+++ b/guix/scripts/gc.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -20,6 +20,7 @@
20 #:use-module (guix ui) 20 #:use-module (guix ui)
21 #:use-module (guix scripts) 21 #:use-module (guix scripts)
22 #:use-module (guix store) 22 #:use-module (guix store)
23 #:use-module (guix store roots)
23 #:autoload (guix build syscalls) (free-disk-space) 24 #:autoload (guix build syscalls) (free-disk-space)
24 #:use-module (ice-9 match) 25 #:use-module (ice-9 match)
25 #:use-module (ice-9 regex) 26 #:use-module (ice-9 regex)
@@ -49,6 +50,8 @@ Invoke the garbage collector.\n"))
49 (display (G_ " 50 (display (G_ "
50 -d, --delete attempt to delete PATHS")) 51 -d, --delete attempt to delete PATHS"))
51 (display (G_ " 52 (display (G_ "
53 --list-roots list the user's garbage collector roots"))
54 (display (G_ "
52 --optimize optimize the store by deduplicating identical files")) 55 --optimize optimize the store by deduplicating identical files"))
53 (display (G_ " 56 (display (G_ "
54 --list-dead list dead paths")) 57 --list-dead list dead paths"))
@@ -135,6 +138,10 @@ Invoke the garbage collector.\n"))
135 (alist-cons 'verify-options options 138 (alist-cons 'verify-options options
136 (alist-delete 'action 139 (alist-delete 'action
137 result)))))) 140 result))))))
141 (option '("list-roots") #f #f
142 (lambda (opt name arg result)
143 (alist-cons 'action 'list-roots
144 (alist-delete 'action result))))
138 (option '("list-dead") #f #f 145 (option '("list-dead") #f #f
139 (lambda (opt name arg result) 146 (lambda (opt name arg result)
140 (alist-cons 'action 'list-dead 147 (alist-cons 'action 'list-dead
@@ -205,6 +212,15 @@ Invoke the garbage collector.\n"))
205 (info (G_ "freeing ~h MiBs~%") (/ to-free 1024. 1024.)) 212 (info (G_ "freeing ~h MiBs~%") (/ to-free 1024. 1024.))
206 (collect-garbage store to-free))))) 213 (collect-garbage store to-free)))))
207 214
215 (define (list-roots)
216 ;; List all the user-owned GC roots.
217 (let ((roots (filter (if (zero? (getuid)) (const #t) user-owned?)
218 (gc-roots))))
219 (for-each (lambda (root)
220 (display root)
221 (newline))
222 roots)))
223
208 (with-error-handling 224 (with-error-handling
209 (let* ((opts (parse-options)) 225 (let* ((opts (parse-options))
210 (store (open-connection)) 226 (store (open-connection))
@@ -238,6 +254,9 @@ Invoke the garbage collector.\n"))
238 (else 254 (else
239 (let-values (((paths freed) (collect-garbage store))) 255 (let-values (((paths freed) (collect-garbage store)))
240 (info (G_ "freed ~h MiBs~%") (/ freed 1024. 1024.))))))) 256 (info (G_ "freed ~h MiBs~%") (/ freed 1024. 1024.)))))))
257 ((list-roots)
258 (assert-no-extra-arguments)
259 (list-roots))
241 ((delete) 260 ((delete)
242 (delete-paths store (map direct-store-path paths))) 261 (delete-paths store (map direct-store-path paths)))
243 ((list-references) 262 ((list-references)
diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh
index ef2d9543b72..8284287730f 100644
--- a/tests/guix-gc.sh
+++ b/tests/guix-gc.sh
@@ -1,5 +1,5 @@
1# GNU Guix --- Functional package management for GNU 1# GNU Guix --- Functional package management for GNU
2# Copyright © 2013, 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org> 2# Copyright © 2013, 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3# 3#
4# This file is part of GNU Guix. 4# This file is part of GNU Guix.
5# 5#
@@ -34,7 +34,7 @@ unset drv
34unset out 34unset out
35 35
36# For some operations, passing extra arguments is an error. 36# For some operations, passing extra arguments is an error.
37for option in "" "-C 500M" "--verify" "--optimize" 37for option in "" "-C 500M" "--verify" "--optimize" "--list-roots"
38do 38do
39 if guix gc $option whatever; then false; else true; fi 39 if guix gc $option whatever; then false; else true; fi
40done 40done
@@ -69,6 +69,8 @@ guix gc --delete "$drv"
69drv="`guix build --root=guix-gc-root lsh -d`" 69drv="`guix build --root=guix-gc-root lsh -d`"
70test -f "$drv" && test -L guix-gc-root 70test -f "$drv" && test -L guix-gc-root
71 71
72guix gc --list-roots | grep "$PWD/guix-gc-root"
73
72guix gc --list-live | grep "$drv" 74guix gc --list-live | grep "$drv"
73if guix gc --delete "$drv"; 75if guix gc --delete "$drv";
74then false; else true; fi 76then false; else true; fi