ambrevar/guix: Add disk-usage-store and delete-store-items.

master
Pierre Neidhardt 2020-12-26 16:19:49 +01:00
parent 767dbe8491
commit 2fb7feecbb
1 changed files with 29 additions and 0 deletions

View File

@ -43,3 +43,32 @@
(defun setup-all ()
(share-setup-files)
(publish))
(export-always 'disk-usage-store)
(defun disk-usage-store (&key (limit 30)
dead?)
(flet ((size->human (pair)
(list (first pair)
(sera:format-human-size nil (second pair))))
(pair-item-with-disk-usage (path)
;; TODO: Replace `du' with native version? `disk-usage' only work on files.
(list path
(parse-integer
(first (first
($:tokenize
($:run* "du" "-sb" path))))))))
(mapcar
#'size->human
(sera:take
limit
(sort (mapcar #'pair-item-with-disk-usage
(if dead?
(alex:flatten ($:tokenize ($:run* "guix" "gc" "--list-dead")))
($:directory-listing "/gnu/store" :sort? t)))
#'> :key #'second)))))
(export-always 'delete-store-items)
(declaim (ftype (function (cons (or string pathname))) 'delete-store-items))
(defun delete-store-items (items)
"Garbage-collect items."
(apply #'$:run* "guix" "gc" "--delete" items))