diff options
| author | Mathieu Othacehe <othacehe@gnu.org> | 2022-09-12 08:31:36 +0200 |
|---|---|---|
| committer | Mathieu Othacehe <othacehe@gnu.org> | 2022-09-24 14:49:09 +0200 |
| commit | ebe9d660a55629f2506db124b0e016885fc61e5c (patch) | |
| tree | 9d6e9b7345a2b1ae214d4117428a0748501426af /gnu/compression.scm | |
| parent | a13f5ead0265cf0fe11e60150547c09dfc8c45b0 (diff) | |
gnu: Add compression module.
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.
Diffstat (limited to 'gnu/compression.scm')
| -rw-r--r-- | gnu/compression.scm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/gnu/compression.scm b/gnu/compression.scm new file mode 100644 index 00000000000..0418e80a158 --- /dev/null +++ b/gnu/compression.scm | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu compression) | ||
| 20 | #:use-module (guix gexp) | ||
| 21 | #:use-module (guix ui) | ||
| 22 | #:use-module ((gnu packages compression) #:hide (zip)) | ||
| 23 | #:use-module (srfi srfi-1) | ||
| 24 | #:use-module (srfi srfi-9) | ||
| 25 | #:use-module (ice-9 match) | ||
| 26 | #:export (compressor | ||
| 27 | compressor? | ||
| 28 | compressor-name | ||
| 29 | compressor-extension | ||
| 30 | compressor-command | ||
| 31 | %compressors | ||
| 32 | lookup-compressor)) | ||
| 33 | |||
| 34 | ;; Type of a compression tool. | ||
| 35 | (define-record-type <compressor> | ||
| 36 | (compressor name extension command) | ||
| 37 | compressor? | ||
| 38 | (name compressor-name) ;string (e.g., "gzip") | ||
| 39 | (extension compressor-extension) ;string (e.g., ".lz") | ||
| 40 | (command compressor-command)) ;gexp (e.g., #~(list "/gnu/store/…/gzip" | ||
| 41 | ; "-9n" )) | ||
| 42 | |||
| 43 | (define %compressors | ||
| 44 | ;; Available compression tools. | ||
| 45 | (list (compressor "gzip" ".gz" | ||
| 46 | #~(list #+(file-append gzip "/bin/gzip") "-9n")) | ||
| 47 | (compressor "lzip" ".lz" | ||
| 48 | #~(list #+(file-append lzip "/bin/lzip") "-9")) | ||
| 49 | (compressor "xz" ".xz" | ||
| 50 | #~(append (list #+(file-append xz "/bin/xz") | ||
| 51 | "-e") | ||
| 52 | (%xz-parallel-args))) | ||
| 53 | (compressor "bzip2" ".bz2" | ||
| 54 | #~(list #+(file-append bzip2 "/bin/bzip2") "-9")) | ||
| 55 | (compressor "zstd" ".zst" | ||
| 56 | ;; The default level 3 compresses better than gzip in a | ||
| 57 | ;; fraction of the time, while the highest level 19 | ||
| 58 | ;; (de)compresses more slowly and worse than xz. | ||
| 59 | #~(list #+(file-append zstd "/bin/zstd") "-3")) | ||
| 60 | (compressor "none" "" #f))) | ||
| 61 | |||
| 62 | (define (lookup-compressor name) | ||
| 63 | "Return the compressor object called NAME. Error out if it could not be | ||
| 64 | found." | ||
| 65 | (or (find (match-lambda | ||
| 66 | (($ <compressor> name*) | ||
| 67 | (string=? name* name))) | ||
| 68 | %compressors) | ||
| 69 | (leave (G_ "~a: compressor not found~%") name))) | ||
