summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-06-24 17:41:43 +0200
committerLudovic Courtès <ludo@gnu.org>2015-06-24 18:05:03 +0200
commite8277f90c88be9d65b948c299620fd9d6d9b28ae (patch)
tree59b7b3e3fbaed726ac1a5a416b542373610d3284 /gnu
parent7a18c3cc1098eab7499f6c8352211258432a527a (diff)
linux-initrd: Use (guix cpio) instead of GNU cpio.
* gnu/build/linux-initrd.scm (write-cpio-archive): Remove 'open-pipe*' and related calls. Compute list of files in 'files' variable. Use 'cpio:write-cpio-archive'. Remove #:cpio parameter. (build-initrd): Remove #:cpio parameter. * gnu/system/linux-initrd.scm (expression->initrd): Likewise, and adjust BUILDER accordingly. Add (guix cpio) to #:modules.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/build/linux-initrd.scm72
-rw-r--r--gnu/system/linux-initrd.scm6
2 files changed, 37 insertions, 41 deletions
diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm
index 54639bd319b..2c148836f35 100644
--- a/gnu/build/linux-initrd.scm
+++ b/gnu/build/linux-initrd.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2013, 2014, 2015 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;;;
@@ -17,12 +17,12 @@
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18 18
19(define-module (gnu build linux-initrd) 19(define-module (gnu build linux-initrd)
20 #:use-module ((guix cpio) #:prefix cpio:)
20 #:use-module (guix build utils) 21 #:use-module (guix build utils)
21 #:use-module (guix build store-copy) 22 #:use-module (guix build store-copy)
22 #:use-module (system base compile) 23 #:use-module (system base compile)
23 #:use-module (rnrs bytevectors) 24 #:use-module (rnrs bytevectors)
24 #:use-module ((system foreign) #:select (sizeof)) 25 #:use-module ((system foreign) #:select (sizeof))
25 #:use-module (ice-9 popen)
26 #:use-module (ice-9 ftw) 26 #:use-module (ice-9 ftw)
27 #:export (write-cpio-archive 27 #:export (write-cpio-archive
28 build-initrd)) 28 build-initrd))
@@ -38,42 +38,42 @@
38(define* (write-cpio-archive output directory 38(define* (write-cpio-archive output directory
39 #:key 39 #:key
40 (compress? #t) 40 (compress? #t)
41 (cpio "cpio") (gzip "gzip")) 41 (gzip "gzip"))
42 "Write a cpio archive containing DIRECTORY to file OUTPUT, using CPIO. When 42 "Write a cpio archive containing DIRECTORY to file OUTPUT. When
43COMPRESS? is true, compress it using GZIP. On success, return OUTPUT." 43COMPRESS? is true, compress it using GZIP. On success, return OUTPUT."
44 44
45 ;; Note: don't use '--no-absolute-filenames' since that strips leading 45 ;; Note: as per `ramfs-rootfs-initramfs.txt', always add directory entries
46 ;; slashes from symlink targets. 46 ;; before the files that are inside of it: "The Linux kernel cpio
47 (let ((pipe (open-pipe* OPEN_WRITE cpio "-o" "-O" output 47 ;; extractor won't create files in a directory that doesn't exist, so the
48 "-H" "newc" "--null"))) 48 ;; directory entries must go before the files that go in those
49 (define (print0 file) 49 ;; directories."
50 (format pipe "~a\0" file))
51
52 ;; Note: as per `ramfs-rootfs-initramfs.txt', always add directory entries
53 ;; before the files that are inside of it: "The Linux kernel cpio
54 ;; extractor won't create files in a directory that doesn't exist, so the
55 ;; directory entries must go before the files that go in those
56 ;; directories."
57 50
51 (define files
58 ;; XXX: Use a deterministic order. 52 ;; XXX: Use a deterministic order.
59 (file-system-fold (const #t) 53 (reverse
60 (lambda (file stat result) ; leaf 54 (file-system-fold (const #t) ;enter?
61 (print0 file)) 55 (lambda (file stat result) ;leaf
62 (lambda (dir stat result) ; down 56 (cons file result))
63 (unless (string=? dir directory) 57 (lambda (dir stat result) ;down
64 (print0 dir))) 58 (if (string=? dir directory)
65 (const #f) ; up 59 result
66 (const #f) ; skip 60 (cons dir result)))
67 (const #f) 61 (lambda (file stat result)
68 #f 62 result)
69 directory) 63 (const #f) ;skip
70 64 (const #f) ;error
71 (and (zero? (close-pipe pipe)) 65 '()
72 (or (not compress?) 66 directory)))
73 (and (zero? (system* gzip "--best" output)) 67
74 (rename-file (string-append output ".gz") 68 (call-with-output-file output
75 output)) 69 (lambda (port)
76 output)))) 70 (cpio:write-cpio-archive files port)))
71
72 (or (not compress?)
73 (and (zero? (system* gzip "--best" output))
74 (rename-file (string-append output ".gz")
75 output))
76 output))
77 77
78(define (cache-compiled-file-name file) 78(define (cache-compiled-file-name file)
79 "Return the file name of the in-cache .go file for FILE, relative to the 79 "Return the file name of the in-cache .go file for FILE, relative to the
@@ -105,7 +105,6 @@ This is similar to what 'compiled-file-name' in (system base compile) does."
105 #:key 105 #:key
106 guile init 106 guile init
107 (references-graphs '()) 107 (references-graphs '())
108 (cpio "cpio")
109 (gzip "gzip")) 108 (gzip "gzip"))
110 "Write an initial RAM disk (initrd) to OUTPUT. The initrd starts the script 109 "Write an initial RAM disk (initrd) to OUTPUT. The initrd starts the script
111at INIT, running GUILE. It contains all the items referred to by 110at INIT, running GUILE. It contains all the items referred to by
@@ -134,8 +133,7 @@ REFERENCES-GRAPHS."
134 (utime file 0 0 0 0))) 133 (utime file 0 0 0 0)))
135 (find-files "." ".*")) 134 (find-files "." ".*"))
136 135
137 (write-cpio-archive output "." 136 (write-cpio-archive output "." #:gzip gzip))
138 #:cpio cpio #:gzip gzip))
139 137
140 (delete-file-recursively "contents")) 138 (delete-file-recursively "contents"))
141 139
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 83685adcbc9..74dacf1ecd4 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -25,7 +25,6 @@
25 #:select (%store-prefix)) 25 #:select (%store-prefix))
26 #:use-module ((guix derivations) 26 #:use-module ((guix derivations)
27 #:select (derivation->output-path)) 27 #:select (derivation->output-path))
28 #:use-module (gnu packages cpio)
29 #:use-module (gnu packages compression) 28 #:use-module (gnu packages compression)
30 #:use-module (gnu packages linux) 29 #:use-module (gnu packages linux)
31 #:use-module (gnu packages guile) 30 #:use-module (gnu packages guile)
@@ -51,7 +50,6 @@
51(define* (expression->initrd exp 50(define* (expression->initrd exp
52 #:key 51 #:key
53 (guile %guile-static-stripped) 52 (guile %guile-static-stripped)
54 (cpio cpio)
55 (gzip gzip) 53 (gzip gzip)
56 (name "guile-initrd") 54 (name "guile-initrd")
57 (system (%current-system)) 55 (system (%current-system))
@@ -78,11 +76,11 @@ MODULES is a list of Guile module names to be embedded in the initrd."
78 #:init #$init 76 #:init #$init
79 ;; Copy everything INIT refers to into the initrd. 77 ;; Copy everything INIT refers to into the initrd.
80 #:references-graphs '("closure") 78 #:references-graphs '("closure")
81 #:cpio (string-append #$cpio "/bin/cpio")
82 #:gzip (string-append #$gzip "/bin/gzip")))) 79 #:gzip (string-append #$gzip "/bin/gzip"))))
83 80
84 (gexp->derivation name builder 81 (gexp->derivation name builder
85 #:modules '((guix build utils) 82 #:modules '((guix cpio)
83 (guix build utils)
86 (guix build store-copy) 84 (guix build store-copy)
87 (gnu build linux-initrd)) 85 (gnu build linux-initrd))
88 #:references-graphs `(("closure" ,init))))) 86 #:references-graphs `(("closure" ,init)))))