From a8ac4f081a9a679498ea42ccfe001f218bba3043 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 30 Jun 2017 00:04:38 +0200 Subject: 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. --- guix/build/store-copy.scm | 35 ++++++++++++++++++++++++++++++++++- guix/scripts/system.scm | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'guix') 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 +;;; Copyright © 2013, 2014, 2017 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,7 +20,9 @@ (define-module (guix build store-copy) #: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 @@ (define (read-reference-graph port) (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." diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 35675cc018..7e20b10dad 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -854,7 +854,7 @@ (define %default-options (build-hook? . #t) (max-silent-time . 3600) (verbosity . 0) - (image-size . ,(* 900 (expt 2 20))) + (image-size . guess) (install-bootloader? . #t))) -- cgit v1.2.3