summaryrefslogtreecommitdiff
path: root/guix/build/store-copy.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-06-30 00:04:38 +0200
committerLudovic Courtès <ludo@gnu.org>2017-06-30 00:16:50 +0200
commita8ac4f081a9a679498ea42ccfe001f218bba3043 (patch)
tree7c5d85cc5d3d52ecb1c482bfde52c4755b48a8bb /guix/build/store-copy.scm
parenta2cf57e79e0c1ca59ff854c12ece178a73fe224d (diff)
downloadguix-patches-a8ac4f081a9a679498ea42ccfe001f218bba3043.tar
guix-patches-a8ac4f081a9a679498ea42ccfe001f218bba3043.tar.gz
vm: Estimate the disk size by default.
* gnu/build/vm.scm (estimated-partition-size): New procedure. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Change #:disk-image-size default to 'guess. [builder]: When DISK-IMAGE-SIZE is 'guess, use 'estimated-partition-size' and compute and estimate of the image size. (qemu-image): Likewise. * guix/build/store-copy.scm (file-size, closure-size): New procedures. * guix/scripts/system.scm (%default-options): Change 'image-size' to 'guess. * doc/guix.texi (Building the Installation Image): Remove '--image-size' flag from example. (Invoking guix system): Document the image size estimate.
Diffstat (limited to 'guix/build/store-copy.scm')
-rw-r--r--guix/build/store-copy.scm35
1 files changed, 34 insertions, 1 deletions
diff --git a/guix/build/store-copy.scm b/guix/build/store-copy.scm
index a296bdf78f..fe2eb6f69a 100644
--- a/guix/build/store-copy.scm
+++ b/guix/build/store-copy.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2017 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -20,7 +20,9 @@
#:use-module (guix build utils)
#:use-module (srfi srfi-1)
#:use-module (ice-9 rdelim)
+ #:use-module (ice-9 ftw)
#:export (read-reference-graph
+ closure-size
populate-store))
;;; Commentary:
@@ -46,6 +48,37 @@ The data at PORT is the format produced by #:references-graphs."
(loop (read-line port)
result)))))
+(define (file-size file)
+ "Return the size of bytes of FILE, entering it if FILE is a directory."
+ (file-system-fold (const #t)
+ (lambda (file stat result) ;leaf
+ (+ (stat:size stat) result))
+ (lambda (directory stat result) ;down
+ (+ (stat:size stat) result))
+ (lambda (directory stat result) ;up
+ result)
+ (lambda (file stat result) ;skip
+ result)
+ (lambda (file stat errno result)
+ (format (current-error-port)
+ "file-size: ~a: ~a~%" file
+ (strerror errno))
+ result)
+ 0
+ file
+ lstat))
+
+(define (closure-size reference-graphs)
+ "Return an estimate of the size of the closure described by
+REFERENCE-GRAPHS, a list of reference-graph files."
+ (define (graph-from-file file)
+ (call-with-input-file file read-reference-graph))
+
+ (define items
+ (delete-duplicates (append-map graph-from-file reference-graphs)))
+
+ (reduce + 0 (map file-size items)))
+
(define* (populate-store reference-graphs target)
"Populate the store under directory TARGET with the items specified in
REFERENCE-GRAPHS, a list of reference-graph files."