gnu: Add compression module.
authorMathieu Othacehe <othacehe@gnu.org>
Mon, 12 Sep 2022 06:31:36 +0000 (08:31 +0200)
committerMathieu Othacehe <othacehe@gnu.org>
Sat, 24 Sep 2022 12:49:09 +0000 (14:49 +0200)
Move the compression record to a dedicated module so that it can be used
outside (guix scripts pack) module.

* guix/scripts/pack.scm (<compressor>, %compressors, lookup-compressor): Move
it to ...
* gnu/compression.scm: ... this new file.
* gnu/ci.scm: Adapt it.
* local.mk (GNU_SYSTEM_MODULES): Add it.

gnu/ci.scm
gnu/compression.scm [new file with mode: 0644]
gnu/local.mk
guix/scripts/pack.scm

index 2c51ea7..19a48bd 100644 (file)
                 #:select (gpl3+ license? license-name))
   #:use-module ((guix utils) #:select (%current-system))
   #:use-module ((guix scripts pack)
-                #:select (lookup-compressor self-contained-tarball))
+                #:select (self-contained-tarball))
   #:use-module (gnu bootloader)
   #:use-module (gnu bootloader u-boot)
+  #:use-module (gnu compression)
   #:use-module (gnu image)
   #:use-module (gnu packages)
   #:use-module (gnu packages gcc)
diff --git a/gnu/compression.scm b/gnu/compression.scm
new file mode 100644 (file)
index 0000000..0418e80
--- /dev/null
@@ -0,0 +1,69 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu compression)
+  #:use-module (guix gexp)
+  #:use-module (guix ui)
+  #:use-module ((gnu packages compression) #:hide (zip))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-9)
+  #:use-module (ice-9 match)
+  #:export (compressor
+            compressor?
+            compressor-name
+            compressor-extension
+            compressor-command
+            %compressors
+            lookup-compressor))
+
+;; Type of a compression tool.
+(define-record-type <compressor>
+  (compressor name extension command)
+  compressor?
+  (name       compressor-name)      ;string (e.g., "gzip")
+  (extension  compressor-extension) ;string (e.g., ".lz")
+  (command    compressor-command))  ;gexp (e.g., #~(list "/gnu/store/…/gzip"
+                                    ;                    "-9n" ))
+
+(define %compressors
+  ;; Available compression tools.
+  (list (compressor "gzip"  ".gz"
+                    #~(list #+(file-append gzip "/bin/gzip") "-9n"))
+        (compressor "lzip"  ".lz"
+                    #~(list #+(file-append lzip "/bin/lzip") "-9"))
+        (compressor "xz"    ".xz"
+                    #~(append (list #+(file-append xz "/bin/xz")
+                                    "-e")
+                              (%xz-parallel-args)))
+        (compressor "bzip2" ".bz2"
+                    #~(list #+(file-append bzip2 "/bin/bzip2") "-9"))
+        (compressor "zstd" ".zst"
+                    ;; The default level 3 compresses better than gzip in a
+                    ;; fraction of the time, while the highest level 19
+                    ;; (de)compresses more slowly and worse than xz.
+                    #~(list #+(file-append zstd "/bin/zstd") "-3"))
+        (compressor "none" "" #f)))
+
+(define (lookup-compressor name)
+  "Return the compressor object called NAME.  Error out if it could not be
+found."
+  (or (find (match-lambda
+              (($ <compressor> name*)
+               (string=? name* name)))
+            %compressors)
+      (leave (G_ "~a: compressor not found~%") name)))
index 140845a..4774be2 100644 (file)
@@ -81,6 +81,7 @@ GNU_SYSTEM_MODULES =                          \
   %D%/bootloader/u-boot.scm                     \
   %D%/bootloader/depthcharge.scm                \
   %D%/ci.scm                                   \
+  %D%/compression.scm                          \
   %D%/home.scm                                 \
   %D%/home/services.scm                        \
   %D%/home/services/desktop.scm                        \
index d3ee698..78b6978 100644 (file)
@@ -48,6 +48,7 @@
   #:use-module (guix scripts build)
   #:use-module (guix transformations)
   #:use-module ((guix self) #:select (make-config.scm))
+  #:use-module (gnu compression)
   #:use-module (gnu packages)
   #:use-module (gnu packages bootstrap)
   #:use-module ((gnu packages compression) #:hide (zip))
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-37)
   #:use-module (ice-9 match)
-  #:export (compressor?
-            compressor-name
-            compressor-extension
-            compressor-command
-            %compressors
-            lookup-compressor
-            self-contained-tarball
+  #:export (self-contained-tarball
             debian-archive
             docker-image
             squashfs-image
             %formats
             guix-pack))
 
-;; Type of a compression tool.
-(define-record-type <compressor>
-  (compressor name extension command)
-  compressor?
-  (name       compressor-name)      ;string (e.g., "gzip")
-  (extension  compressor-extension) ;string (e.g., ".lz")
-  (command    compressor-command))  ;gexp (e.g., #~(list "/gnu/store/…/gzip"
-                                    ;                    "-9n" ))
-
-(define %compressors
-  ;; Available compression tools.
-  (list (compressor "gzip"  ".gz"
-                    #~(list #+(file-append gzip "/bin/gzip") "-9n"))
-        (compressor "lzip"  ".lz"
-                    #~(list #+(file-append lzip "/bin/lzip") "-9"))
-        (compressor "xz"    ".xz"
-                    #~(append (list #+(file-append xz "/bin/xz")
-                                    "-e")
-                              (%xz-parallel-args)))
-        (compressor "bzip2" ".bz2"
-                    #~(list #+(file-append bzip2 "/bin/bzip2") "-9"))
-        (compressor "zstd" ".zst"
-                    ;; The default level 3 compresses better than gzip in a
-                    ;; fraction of the time, while the highest level 19
-                    ;; (de)compresses more slowly and worse than xz.
-                    #~(list #+(file-append zstd "/bin/zstd") "-3"))
-        (compressor "none" "" #f)))
-
 ;; This one is only for use in this module, so don't put it in %compressors.
 (define bootstrap-xz
   (compressor "bootstrap-xz" ".xz"
                               "-e")
                         (%xz-parallel-args))))
 
-(define (lookup-compressor name)
-  "Return the compressor object called NAME.  Error out if it could not be
-found."
-  (or (find (match-lambda
-              (($ <compressor> name*)
-               (string=? name* name)))
-            %compressors)
-      (leave (G_ "~a: compressor not found~%") name)))
-
 (define not-config?
   ;; Select (guix …) and (gnu …) modules, except (guix config).
   (match-lambda