diff --git a/gnu/build/linux-initrd.scm b/gnu/build/linux-initrd.scm
index 2c148836f35b271435f8d144da5e3d170d714952..815c7a0aebff5aba0d52485fef5912a23bb7185b 100644
--- a/gnu/build/linux-initrd.scm
+++ b/gnu/build/linux-initrd.scm
@@ -49,21 +49,22 @@ (define* (write-cpio-archive output directory
   ;; directories."
 
   (define files
-    ;; XXX: Use a deterministic order.
-    (reverse
-     (file-system-fold (const #t)                 ;enter?
-                       (lambda (file stat result) ;leaf
-                         (cons file result))
-                       (lambda (dir stat result)  ;down
-                         (if (string=? dir directory)
-                             result
-                             (cons dir result)))
-                       (lambda (file stat result)
-                         result)
-                       (const #f)                 ;skip
-                       (const #f)                 ;error
-                       '()
-                       directory)))
+    ;; Use 'sort' so that (1) the order of files is deterministic, and (2)
+    ;; directories appear before the files they contain.
+    (sort (file-system-fold (const #t)                 ;enter?
+                            (lambda (file stat result) ;leaf
+                              (cons file result))
+                            (lambda (dir stat result)  ;down
+                              (if (string=? dir directory)
+                                  result
+                                  (cons dir result)))
+                            (lambda (file stat result)
+                              result)
+                            (const #f)                 ;skip
+                            (const #f)                 ;error
+                            '()
+                            directory)
+          string<?))
 
   (call-with-output-file output
     (lambda (port)