aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013, 2014 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2015 Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
;;; Copyright © 2015 Paul van der Walt <paul@denknerd.org>
;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2017 John Darrington <jmd@gnu.org>
;;; Copyright © 2017 Thomas Danckaert <post@thomasdanckaert.be>
;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2017 Nikita <nikita@n0.is>
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2019 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2020 Timotej Lazar <timotej.lazar@araneo.si>
;;; Copyright © 2023 Zheng Junjie <873216071@qq.com>
;;; Copyright © 2024 Julian Flake <flake@uni-koblenz.de>
;;;
;;; 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 packages cdrom)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix packages)
  #:use-module ((guix licenses) #:select (lgpl2.1+ gpl2 gpl2+ gpl3+ cddl1.0))
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system glib-or-gtk)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages acl)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages docbook)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages man)
  #:use-module (gnu packages mp3)
  #:use-module (gnu packages music)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages elf)
  #:use-module (gnu packages wxwidgets)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages base)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages perl-web)
  #:use-module (gnu packages python)
  #:use-module (gnu packages image)
  #:use-module (gnu packages photo)
  #:use-module (gnu packages tcl)
  #:use-module (gnu packages video)
  #:use-module (gnu packages wget)
  #:use-module (gnu packages xiph))

(define-public libcddb
  (package
    (name "libcddb")
    (version "1.3.2")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://sourceforge/libcddb/libcddb/" version
                                 "/libcddb-" version ".tar.bz2"))
             (sha256
              (base32
               "0fr21a7vprdyy1bq6s99m0x420c9jm5fipsd63pqv8qyfkhhxkim"))))
    (build-system gnu-build-system)
    (arguments '(#:tests? #f))      ; tests rely on access to external servers
    (home-page "https://libcddb.sourceforge.net/")
    (synopsis "C library to access data on a CDDB server")
    (description
     "Libcddb is a C library to access data on a CDDB server (freedb.org).  It
allows you to:

 1. search the database for possible CD matches;

 2. retrieve detailed information about a specific CD;

 3. submit new CD entries to the database.

Libcddb supports both the custom CDDB protocol and tunnelling the query and
read operations over plain HTTP.  It is also possible to use an HTTP proxy
server.  If you want to speed things up, you can make use of the built-in
caching facility provided by the library.")
    (license lgpl2.1+)))

(define-public libcdio
  (package
    (name "libcdio")
    (version "2.1.0")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/libcdio/libcdio-"
                                 version ".tar.bz2"))
             (patches (search-patches "libcdio-glibc-compat.patch"))
             (sha256
              (base32
               "0avi6apv5ydjy6b9c3z9a46rvp5i57qyr09vr7x4nndxkmcfjl45"))))
    (build-system gnu-build-system)
    (inputs
     (list ncurses libcddb))
    (native-inputs
     (list help2man pkg-config))
    (home-page "https://www.gnu.org/software/libcdio/")
    (synopsis "CD Input and Control library")
    (description
     "The GNU Compact Disc Input and Control Library (libcdio) is a library
for CD-ROM and CD image file access.  It allows the developer to add CD
access to an application without having to worry about the OS- and
device-dependent properties of CD-ROM or the specific details of CD image
formats.  It includes pycdio, a Python interface to libcdio, and
libcdio-paranoia, a library providing jitter-free and error-free audio
extraction from CDs.")
    (license gpl3+)))

(define-public libcdio-paranoia
  (package
    (name "libcdio-paranoia")
    (version "10.2+2.0.1")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/libcdio/libcdio-paranoia-"
                                 version ".tar.bz2"))
             (sha256
              (base32
               "12hfnrq7amv9qjzc92cr265m7kh0a1hpasck8cxx1gygbhqczc9k"))))
    (build-system gnu-build-system)
    (native-inputs (list pkg-config))
    (propagated-inputs (list libcdio))
    (home-page "https://www.gnu.org/software/libcdio/")
    (synopsis "Jitter- and error-tolerant CD audio extraction")
    (description
     "libcdio-paranoia is an implementation of CD paranoia libraries based on
libcdio.")
    (license gpl3+)))

;; Xorriso is used by Guix for creating ISO images. If you change this package,
;; please make sure the Guix functionality still works by running some related
;; system tests.
;; For example, try running `make check-system TESTS=iso-image-installer`.
(define-public xorriso
  (package
    (name "xorriso")
    (version "1.5.6.pl02")
    (outputs '("out" "gui"))
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/xorriso/xorriso-"
                                 version ".tar.gz"))
             (sha256
              (base32
               "1qfs9ybd9k67r78rp1csijmlrq7mq39f7kpyq6qcap46z5fryvvq"))))
    (build-system gnu-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'install 'install-frontends
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (out-bin (string-append out "/bin")))
               (install-file "frontend/grub-mkrescue-sed.sh" out-bin))))
         (add-after 'install 'move-gui-to-separate-output
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out"))
                   (gui (assoc-ref outputs "gui")))
               (for-each
                 (lambda (file)
                   (mkdir-p (string-append gui (dirname file)))
                   (rename-file (string-append out file)
                                (string-append gui file)))
                 (list "/bin/xorriso-tcltk"
                       "/share/info/xorriso-tcltk.info"
                       "/share/man/man1/xorriso-tcltk.1"))
               (wrap-program (string-append gui "/bin/xorriso-tcltk")
                 `("PATH" ":" prefix (,(string-append out "/bin"))))))))))
    (inputs
     (list acl bash-minimal readline tk zlib))
    (home-page "https://www.gnu.org/software/xorriso/")
    (synopsis "Create, manipulate, burn ISO-9660 file systems")
    (description
     "GNU Xorriso is a tool for copying files to and from ISO 9660 Rock
Ridge, a.k.a. Compact Disc File System, file systems and it allows
session-wise manipulation of them.  It features a formatter and burner for
CD, DVD and BD.  It can operate on existing ISO images or it can create new
ones.  xorriso can then be used to copy files directly into or out of ISO
files.")
    (license gpl3+)))

(define-public cdparanoia
  (package
    (name "cdparanoia")
    (version "10.2")
    (source (origin
             (method url-fetch)
             (uri (string-append "http://downloads.xiph.org/releases/"
                                 "cdparanoia/cdparanoia-III-"
                                 version ".src.tgz"))
             (sha256
              (base32
               "1pv4zrajm46za0f6lv162iqffih57a8ly4pc69f7y0gfyigb8p80"))
             (patches (search-patches "cdparanoia-fpic.patch"))
             (modules '((guix build utils)))
             (snippet
              '(begin
                 ;; Make libraries respect LDFLAGS.
                 (substitute* '("paranoia/Makefile.in" "interface/Makefile.in")
                   (("-Wl,-soname") "$(LDFLAGS) -Wl,-soname"))))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; there is no check target
       #:parallel-build? #f             ;randomly fails to link
       #:configure-flags ; Add $libdir to the RUNPATH of all the executables.
       (list (string-append "LDFLAGS=-Wl,-rpath="
                            ,(if (%current-target-system)
                                 '(assoc-ref %outputs "out")
                                 '%output)
                            "/lib"))
       ;; Building in parallel is flaky: “ld: […]/cachetest.c:393: undefined
       ;; reference to `paranoia_free'”.
       #:parallel-build? #f
       ,@(if (and (or (target-riscv64?)
                      (target-aarch64?))
                  (%current-target-system))
             '(#:phases
               (modify-phases %standard-phases
                 (add-after 'unpack 'update-config-scripts
                   (lambda* (#:key inputs native-inputs #:allow-other-keys)
                     ;; Replace outdated config.guess and config.sub.
                     (for-each (lambda (file)
                                 (install-file
                                  (search-input-file
                                   (or native-inputs inputs)
                                   (string-append "/bin/" file)) "."))
                               '("config.guess" "config.sub"))))))
             '())))
    (native-inputs
     (if (and (or (target-riscv64?)
                  (target-aarch64?))
              (%current-target-system))
         (list config)
         '()))
    (home-page "https://www.xiph.org/paranoia/")
    (synopsis "Audio CD reading utility")
    (description "Cdparanoia retrieves audio tracks from CDDA capable CDROM
drives.  The data can be saved to a file or directed to standard output
in WAV, AIFF, AIFF-C or raw format.  Most ATAPI, SCSI and several
proprietary CDROM drive makes are supported; cdparanoia can determine if the
target drive is CDDA capable.  In addition to simple reading, cdparanoia adds
extra-robust data verification, synchronization, error handling and scratch
reconstruction capability.")
    (license gpl2))) ; libraries under lgpl2.1

(define-public cdrdao
  (package
    (name "cdrdao")
    (version "1.2.5")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/cdrdao/cdrdao")
             (commit
              (string-append "rel_" (string-replace-substring version "." "_")))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "1hh1lm4wr1vhsq2brczn94h88h3bppvjidj9cfqkl20jhaj38968"))))
    (build-system gnu-build-system)
    (arguments
     '(#:configure-flags
       (list
        ;; GCDMaster depends on obsolete libgnomeuimm, see
        ;; <https://github.com/cdrdao/cdrdao/issues/3>.
        "--without-gcdmaster"
        ;; Use the native SCSI interface.
        "--without-scglib")
       #:phases
       (modify-phases %standard-phases
         (add-before 'bootstrap 'fix-configure.ac
           (lambda _
             ;; Remove references to missing macros.
             (substitute* "configure.ac"
              (("^AM_GCONF_SOURCE_2.*") "")
              ;; This was introduced in autoconf-2.70, but is described
              ;; as usually not needed in the autoconf documentation.
              (("^AC_CHECK_INCLUDES_DEFAULT") "")))))))
    (native-inputs
     (list autoconf automake pkg-config))
    (inputs
     (list ao lame libmad libvorbis))
    (home-page "https://cdrdao.sourceforge.net")
    (synopsis "Read and write CDs in disk-at-once mode")
    (description "cdrdao records audio or data CDs in disk-at-once (DAO) mode,
based on a textual description of the contents.  This mode writes the complete
disc – lead-in, one or more tracks, and lead-out – in a single step and is
commonly used with audio CDs.  @code{cdrdao} can also handle the bin/cue
format, commonly used for VCDs or disks with subchannel data.")
    (license gpl2+)))

(define-public cdrtools
  (package
    (name "cdrtools")
    (version "3.01")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "mirror://sourceforge/cdrtools/cdrtools-" version ".tar.bz2"))
              (sha256
               (base32
                "03w6ypsmwwy4d7vh6zgwpc60v541vc5ywp8bdb758hbc4yv2wa7d"))
              (modules '((guix build utils)))
              (snippet
               '(begin
                  ;; By default 'cdda2wav --help' would print a string like
                  ;; "Version 3.01_linux_4.19.10-gnu_x86_64_x86_64".  Change
                  ;; it to not capture the kernel version of the build
                  ;; machine, to allow for reproducible builds.
                  (substitute* "cdda2wav/local.cnf.in"
                    (("^VERSION_OS=.*")
                     (string-append
                      "actual_os := $(shell uname -o)\n"
                      "actual_arch := $(shell uname -m)\n"
                      "VERSION_OS = _$(actual_os)_$(actual_arch)\n")))))
              (patches (search-patches "cdrtools-3.01-mkisofs-isoinfo.patch"))))
    (build-system gnu-build-system)
    ;; XXX cdrtools bundles a modified, relicensed early version of cdparanoia.
    (arguments
     (list #:make-flags
        #~(list "RM=rm" "LN=ln" "SYMLINK=ln -s"
                "CONFIG_SHELL=sh"
                (string-append "CCOM=" #$(cc-for-target))
                "LINKMODE=dynamic"
                (string-append "INS_BASE=" #$output)
                (string-append "INS_RBASE=" #$output))
        ;; Parallel builds appear to be unsafe, see
        ;; https://hydra.gnu.org/build/3346840/log/raw
        #:parallel-build? #f
        #:phases
        #~(modify-phases %standard-phases
            (delete 'configure)
            (add-before 'build 'set-linux-headers
              (lambda _
                (substitute* "autoconf/configure"
                  (("/usr/src/linux")
                   (assoc-ref %build-inputs "kernel-headers")))))
            (add-before 'build 'avoid-bogus-RPATH-entry
              (lambda _
                (substitute* (append (find-files "DEFAULTS" "^Defaults\\.")
                                     (find-files "DEFAULTS_ENG" "^Defaults\\.")
                                     (find-files "TEMPLATES" "^Defaults\\."))
                  (("/opt/schily")
                   #$output)))))
        #:tests? #f))  ; no tests
   (synopsis "Command line utilities to manipulate and burn CD/DVD/BD images")
   (description "cdrtools is a collection of command line utilities to create
CD's, DVD's or Blue Ray discs.  The most important components are
@command{cdrecord}, a burning program, @command{cdda2wav}, a CD audio ripper
which uses libparanoia, and @command{mkisofs}, which can create various disc
images.")
   (home-page "https://cdrtools.sourceforge.net/private/cdrecord.html")

   ;; mkisofs is GPL, the other programs are CDDL.
   (license (list cddl1.0 gpl2))))

(define-public dvd+rw-tools
  (package
    (name "dvd+rw-tools")
    (version "7.1")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "http://fy.chalmers.se/~appro/linux/DVD+RW/tools/dvd+rw-tools-"
                    version ".tar.gz"))
              (sha256
               (base32
                "1jkjvvnjcyxpql97xjjx0kwvy70kxpiznr2zpjy2hhci5s10zmpq"))
              (patches (search-patches "dvd+rw-tools-add-include.patch"))))
    (build-system gnu-build-system)
    (inputs
     (list cdrtools))
    (native-inputs
     (list m4))
    (arguments
     `(#:tests? #f ; No tests.
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'fix-glibc-compatability
           (lambda* (#:key inputs #:allow-other-keys)
             ;; We use sed --in-place because substitute* cannot handle the
             ;; character encoding used by growisofs.c.
             (invoke "sed" "-i" "-e"
                     (string-append
                       "s,<sys/stat.h>,"
                       "<sys/stat.h>\\\n#include <sys/sysmacros.h>,")
                     "growisofs.c")))
         (replace 'configure
           (lambda _ (setenv "prefix" (assoc-ref %outputs "out")) #t))
         (add-before 'build 'embed-mkisofs
           (lambda* (#:key inputs #:allow-other-keys)
             ;; We use sed --in-place because substitute* cannot handle the
             ;; character encoding used by growisofs.c.
             (invoke "sed" "-i" "-e"
                     (string-append
                       "s,\"mkisofs\","
                       "\"" (which "mkisofs") "\",")
                     "growisofs.c"))))))
    (home-page "http://fy.chalmers.se/~appro/linux/DVD+RW/")
    (synopsis "DVD and Blu-ray Disc burning tools")
    (description "dvd+rw-tools, mostly known for its command
@command{growisofs}, is a collection of DVD and Blu-ray Disc burning tools.
It requires another program, such as @command{mkisofs}, @command{genisoimage},
or @command{xorrisofs} to create ISO 9660 images.")
    (license gpl2)))

(define-public dvdisaster
  (package
    (name "dvdisaster")
    (version "0.79.10")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://dvdisaster.jcea.es/downloads/dvdisaster-"
                           version ".tar.bz2"))
       (sha256
        (base32 "1s3z4098ixdjr3gjs36fg7rykqs0zz1rnvz2v9rvyj0s5zv9y2nx"))))
    (build-system gnu-build-system)
    (inputs
     (list gtk+-2))
    (native-inputs
     (list gettext-minimal pkg-config which))
    (arguments
     (list #:parallel-build? #f ; http://hydra.gnu.org/build/49331/nixlog/1/raw
           #:phases
           #~(modify-phases %standard-phases
               (replace 'check
                 (lambda _
                   (with-directory-excursion "regtest"
                     (substitute* "common.bash"
                       (("ISODIR=/var/tmp/regtest") "ISODIR=/tmp"))
                     (for-each invoke (find-files "." "rs.*\\.bash")))))
               (add-after 'install 'install-desktop
                 (lambda* (#:key outputs #:allow-other-keys)
                   (let* ((datadir (string-append (assoc-ref outputs "out")
                                                  "/share")))
                     (substitute* "contrib/dvdisaster.desktop"
                       (("dvdisaster48.png") "dvdisaster.png"))
                     (install-file "contrib/dvdisaster.desktop"
                                   (string-append datadir "/applications"))
                     (for-each
                      (lambda (png)
                        (let* ((size (substring
                                      png
                                      (string-index png char-set:digit)
                                      (string-rindex png #\.)))
                               (icondir (string-append datadir "/icons/"
                                                       size "x" size "/apps")))
                          (mkdir-p icondir)
                          (copy-file png
                                     (string-append icondir
                                                    "/dvdisaster.png"))))
                      (find-files "contrib" "dvdisaster[0-9]*\\.png"))
                     (mkdir-p (string-append datadir "/pixmaps"))
                     (copy-file "contrib/dvdisaster48.xpm"
                                (string-append datadir
                                               "/pixmaps/dvdisaster.xpm")))))
               (add-after 'install 'remove-uninstall-script
                 (lambda* (#:key outputs #:allow-other-keys)
                   (let* ((out (assoc-ref outputs "out")))
                     (delete-file
                      (string-append out "/bin/dvdisaster-uninstall.sh"))))))))
    (home-page "https://dvdisaster.jcea.es/")
    (synopsis "Error correcting codes for optical media images")
    (description "Optical media (CD,DVD,BD) keep their data only for a
finite time (typically for many years).  After that time, data loss develops
slowly with read errors growing from the outer media region towards the
inside.

Dvdisaster stores data on CD/DVD/BD (supported media) in a way that it is
fully recoverable even after some read errors have developed.  This enables
you to rescue the complete data to a new medium.

Data loss is prevented by using error correcting codes.  Error correction
data is either added to the medium or kept in separate error correction
files.  Dvdisaster works at the image level so that the recovery does not
depend on the file system of the medium.  The maximum error correction
capacity is user-selectable.")
    (license gpl2+)))

(define-public dvdstyler
  (package
    (name "dvdstyler")
    (version "3.0.4")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "mirror://sourceforge/dvdstyler/dvdstyler/"
                            version "/DVDStyler-" version ".tar.bz2"))
       (sha256
        (base32
         "0lwc0hn94m9r8fi07sjqz3fr618l6lnw3zsakxw7nlgnxbjsk7pi"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       (list (string-append "XMLTO="
                            (assoc-ref %build-inputs "xmlto")
                            "/bin/xmlto --searchpath "
                            (assoc-ref %build-inputs "docbook-xsl")
                            "/xml/xsl/docbook-xsl-" ,(package-version docbook-xsl)
                            "/htmlhelp:"
                            (assoc-ref %build-inputs "docbook-xml")
                            "/xml/dtd/docbook"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'wrap-program
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (wrap-program (string-append (assoc-ref outputs "out") "/bin/dvdstyler")
               `("PATH" ":" prefix
                 (,(string-join
                    (map (lambda (in) (string-append (assoc-ref inputs in) "/bin"))
                         '("cdrtools" "dvdauthor" "dvd+rw-tools" "ffmpeg"))
                    ":"))))
             #t)))
       #:tests? #f)) ; No tests.
    (inputs ; TODO package bundled wxvillalib
     `(("wxwidgets" ,wxwidgets)
       ("wssvg" ,wxsvg)
       ("bash" ,bash-minimal) ; for wrap-program
       ("dbus" ,dbus)
       ("cdrtools" ,cdrtools)
       ("dvd+rw-tools" ,dvd+rw-tools)
       ("dvdauthor" ,dvdauthor)
       ("eudev" ,eudev)
       ("fontconfig" ,fontconfig)
       ("libexif" ,libexif)
       ("libjpeg" ,libjpeg-turbo)
       ("ffmpeg" ,ffmpeg-3.4)))
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("flex" ,flex)
       ("python" ,python-2)
       ("xmlto" ,xmlto)
       ("gettext" ,gettext-minimal)
       ("docbook-xml" ,docbook-xml)
       ("docbook-xsl" ,docbook-xsl)
       ("zip" ,zip)))
    (synopsis "DVD authoring application")
    (description "DVDStyler is a DVD authoring application which allows users
to burn video files in many formats to DVD discs, complete with individually
designed menus.  It can be used to create professional-looking DVD's with
custom buttons, backgrounds and animations, from within a user-friendly
graphical interface.")
    (home-page "https://www.dvdstyler.org")
    (license gpl2)))

(define-public libcue
  (package
    (name "libcue")
    (version "2.3.0")
    (source (origin
             (method git-fetch)
             (uri (git-reference
                   (url "https://github.com/lipnitsk/libcue")
                   (commit (string-append "v" version))))
             (file-name (git-file-name name version))
             (sha256
              (base32
               "1lkcj31fc0wjqr9lgr1ws6invx6ayvrk7v5kd9lm7956q1mi9ib4"))))
    (build-system cmake-build-system)
    (arguments
     `(#:configure-flags '("-DBUILD_SHARED_LIBS=ON")))
    (native-inputs
     (list bison flex))
    (home-page "https://github.com/lipnitsk/libcue")
    (synopsis "C library to parse cue sheets")
    (description "Libcue is a C library to parse so-called @dfn{cue sheets}
which contain meta-data for CD/DVD tracks.  It provides an API to manipulate
the data.")
    (license gpl2+)))

(define-public cd-discid
  (package
    (name "cd-discid")
    (version "1.4")
    (home-page "https://linukz.org/cd-discid.shtml")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://linukz.org/download/cd-discid-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "0qrcvn7227qaayjcd5rm7z0k5q89qfy5qkdgwr5pd7ih0va8rmpz"))
              (modules '((guix build utils)))
              (snippet
               '(begin
                  (substitute* "Makefile"
                    (("/usr/bin/install")
                     "install"))
                  #t))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f
       #:phases (modify-phases %standard-phases (delete 'configure))
       #:make-flags (list ,(string-append "CC=" (cc-for-target))
                          (string-append "PREFIX="
                                         (assoc-ref %outputs "out")))))
    (synopsis "Get CDDB discid information from an audio CD")
    (description
     "cd-discid is a command-line tool to retrieve CDDB discid information
from an audio CD.")
    (license gpl2+)))

(define-public abcde
  (package
    (name "abcde")
    (version "2.9.3")
    (home-page "https://abcde.einval.com/")
    (source (origin
              (method url-fetch)
              (uri (string-append home-page "/download/abcde-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "091ip2iwb6b67bhjsj05l0sxyq2whqjycbzqpkfbpm4dlyxx0v04"))
              (modules '((guix build utils)))
              (snippet
               '(begin
                  (substitute* "Makefile"
                    (("/usr/bin/install")
                     "install"))))))
    (build-system gnu-build-system)
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'configure
           (lambda* (#:key outputs inputs #:allow-other-keys)
             (substitute* "Makefile"
               (("^prefix = .*$")
                (string-append "prefix = "
                               (assoc-ref outputs "out")
                               "\n"))
               (("^sysconfdir = .*$")
                (string-append "sysconfdir = "
                               (assoc-ref outputs "out")
                               "/etc/\n")))))
         (add-after 'install 'wrap
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let ((wget   (assoc-ref inputs "wget"))
                   (vorbis (assoc-ref inputs "vorbis-tools"))
                   (parano (assoc-ref inputs "cdparanoia"))
                   (which  (assoc-ref inputs "which"))
                   (discid (assoc-ref inputs "cd-discid"))
                   (perl-discid (assoc-ref inputs "perl-musicbrainz-discid"))
                   (perl-ws (assoc-ref inputs "perl-webservice-musicbrainz"))
                   (perl-mojo (assoc-ref inputs "perl-mojolicious"))
                   (flac   (assoc-ref inputs "flac"))
                   (out    (assoc-ref outputs "out")))
               (define (wrap file)
                 (wrap-program file
                               `("PATH" ":" prefix
                                 (,(string-append out "/bin:"
                                                  wget "/bin:"
                                                  flac "/bin:"
                                                  which "/bin:"
                                                  vorbis "/bin:"
                                                  discid "/bin:"
                                                  parano "/bin")))
                               `("PERL5LIB" ":" prefix
                                 (,(string-append perl-discid
                                                  "/lib/perl5/site_perl:"
                                                  perl-ws
                                                  "/lib/perl5/site_perl:"
                                                  perl-mojo
                                                  "/lib/perl5/site_perl")))))

               (for-each wrap
                         (find-files (string-append out "/bin")
                                     ".*"))))))
       #:tests? #f)) ; no test target

    (inputs (list bash-minimal
                  wget
                  which
                  cdparanoia
                  cd-discid
                  vorbis-tools
                  flac
                  perl-musicbrainz-discid
                  perl-webservice-musicbrainz
                  perl-mojolicious ;indirect dependency
                  ;; A couple of Python and Perl scripts are included.
                  python
                  perl))

    (synopsis "Command-line audio CD ripper")
    (description
     "abcde is a front-end command-line utility (actually, a shell script)
that grabs tracks off a CD, encodes them to Ogg/Vorbis, MP3, FLAC, Ogg/Speex
and/or MPP/MP+ (Musepack) format, and tags them, all in one go.")
    (license gpl2+)))

(define-public geteltorito
  (let ((commit "d6c7ba03c3c4c5bc4cb68e3602c9427b0912f16f")
        (revision "1"))          ;Guix package revision
    (package
      (name "geteltorito")
      (version (git-version "0.6" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/rainer042/geteltorito")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32 "15dh5ibmqr3pyxyiica4r9nn1xk1j0gr3xy2s3n8b4n7b2mn8n01"))))
      (build-system gnu-build-system)
      (arguments
       `(#:tests? #f ; No tests.
         #:phases
         (modify-phases %standard-phases
           (delete 'configure)
           (delete 'build)
           (replace 'install
             (lambda* (#:key outputs #:allow-other-keys)
               (let ((out (assoc-ref outputs "out")))
                 (install-file "geteltorito.pl"
                               (string-append out "/bin"))
                 (rename-file (string-append out "/bin/geteltorito.pl")
                              (string-append out "/bin/geteltorito"))
                 (chmod (string-append out "/bin/geteltorito") #o555)))))))
      (home-page
       "https://github.com/rainer042/geteltorito")
      (inputs (list perl))
      (synopsis "Extract the boot image from a CD-ROM")
      (description
       "@command{geteltorito} can extract the initial/default boot
image from CDs (and ISOs) that follow the El Torito specification
for bootable CD-ROMs.

Image data is written to standard output by default and all other
information is written to standard error.")
      (license gpl2+))))

(define-public asunder
  (package
    (name "asunder")
    (version "3.0.1")
    (source
     (origin
       (method url-fetch)
       (uri
        (string-append "https://www.littlesvr.ca/asunder/releases/asunder-"
                       version ".tar.bz2"))
       (sha256
        (base32 "0srpag9bca76iiv8766kxmbvhsri58k15xp70348frkvp7hy4s48"))))
    (build-system glib-or-gtk-build-system)
    (arguments
     (list
      #:out-of-source? #f
       #:phases
       #~(modify-phases %standard-phases
         (add-before 'check 'fix-tests
           ;; As of 3.0.1, there are no ‘real’ tests under src/, and the linty
           ;; test under po/ is broken.  Still, it's trivial to fix.
           (lambda _
             (let ((file (open-file "po/POTFILES.in" "a")))
               (format file "~%src/upload.c~%")
               (close-port file))))
         (add-after 'install 'wrap
           (lambda _
             (wrap-program (string-append #$output "/bin/asunder")
               `("PATH" ":" prefix
                 ,(map (lambda (input) (string-append input "/bin"))
                       '#$(map (lambda (label) (this-package-input label))
                               (list "cdparanoia"
                                     "flac"
                                     "lame"
                                     "opus-tools"
                                     "vorbis-tools"
                                     "wavpack"))))))))))
    (native-inputs (list intltool pkg-config))
    ;; TODO: Add the necessary packages for Musepack encoding.
    (inputs `(("bash" ,bash-minimal) ; for wrap-program
              ("gtk+-2" ,gtk+-2)
              ("glib" ,glib)
              ("libcddb" ,libcddb)
              ("cdparanoia" ,cdparanoia)
              ("lame" ,lame)
              ("vorbis-tools" ,vorbis-tools)
              ("flac" ,flac)
              ("opus-tools" ,opus-tools)
              ("wavpack" ,wavpack)))
    (home-page "http://www.littlesvr.ca/asunder/")
    (synopsis "Graphical audio CD ripper and encoder")
    (description
     "Asunder is a graphical audio CD ripper and encoder.  It can save audio
tracks as WAV, MP3, Ogg Vorbis, FLAC, Opus, Wavpack, and Musepack.  It can use
CDDB to name and tag each track automatically, and it allows for each track to
be by a different artist.  Asunder can encode to multiple formats in one
session, and it can create M3U playlists.")
    (license gpl2)))

(define-public ripit
  (package
    (name "ripit")
    (version "3.9.0")
    (source
     (origin
       (method url-fetch)
       ;; The original suwald.com domain has expired.
       (uri (list
             (string-append "https://web.archive.org/web/20160327050927/"
                            "http://suwald.com/ripit/ripit-" version ".tar.gz")
             (string-append "https://ponce.cc/slackware/sources/repo/ripit-"
                            version ".tar.gz")))
       (sha256
        (base32 "0ap71x477jy9c4jiqazb3y45hxdxm3jbq24x05g3vjyqzigi4x1b"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f                      ; no test suite
       #:phases
       (modify-phases %standard-phases
         (delete 'configure)
         (add-after 'unpack 'patch-usr-bin-install
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (substitute* "Makefile"
               (("/usr/bin/install") (string-append
                                      (assoc-ref inputs "coreutils")
                                      "/bin/install"))
               (("\\$\\(DESTDIR\\)/usr/local") (assoc-ref outputs "out"))
               (("../../etc") "etc")))))))
    (native-inputs
     (list coreutils))
    (inputs
     (list perl))
    (propagated-inputs
     (list cdparanoia flac vorbis-tools wavpack perl-cddb-get))
    (home-page (string-append "https://web.archive.org/web/20170119092156/"
                              "http://www.suwald.com/ripit/about.php"))
    (synopsis "Command-line program to extract audio CDs")
    (description "RipIT is used to extract audio from CDs.")
    (license gpl2)))

(define-public ccd2cue
  (package
    (name "ccd2cue")
    (version "0.5")
    (source
     (origin
       (method url-fetch)
       (uri (string-append
             "mirror://gnu/ccd2cue/ccd2cue-" version
             ".tar.gz"))
       (sha256
        (base32
         "1icrkg25hwx4gsn3dski2172ia4ywjh8m1sa17zmjclnrgdwy9c7"))))
    (build-system gnu-build-system)
    (synopsis "CCD to CUE sheet conversion")
    (description
     "GNU ccd2cue is a preprocessor for CD burning software that allows
the conversion of the proprietary CCD format to the CUE format, which
is well-supported by free software.  These files are commonly
distributed with CD images and are used to describe how tracks are
laid out on the image.")
    (home-page "https://www.gnu.org/software/ccd2cue/")
    (license gpl3+)))

(define-public libburn
  (package
    (name "libburn")
    (version "1.5.6")
    (source (origin
             (method url-fetch)
             (uri (string-append "http://files.libburnia-project.org/releases/"
                                 "libburn-" version ".tar.gz"))
             (sha256
              (base32
               "0jv447ixwvj68vslbgbbvkzmaabf4dz0dcizg9garvp59cdlk5bj"))))
    (build-system gnu-build-system)
    (native-inputs
     (list pkg-config))
    (home-page "https://dev.lovelyhq.com/libburnia/libburn")
    (synopsis "Library for reading and writing optical discs")
    (description
     "Libburn is a library for reading and writing optical discs.
Supported media are: CD-R, CD-RW, DVD-RAM, DVD+RW, DVD+R, DVD+R/DL,
DVD-RW, DVD-R, DVD-R/DL, BD-R, and BD-RE.")
    (license gpl2)))

(define-public libisofs
  (package
    (name "libisofs")
    (version "1.5.6.pl01")
    (source (origin
             (method url-fetch)
             (uri (string-append "http://files.libburnia-project.org/releases/"
                                 "libisofs-" version ".tar.gz"))
             (sha256
              (base32
               "09czddjriv2zi1bdsck8a31ci6xpi1qr2rqmzfhlqx21sqwd67xc"))))
    (build-system gnu-build-system)
    (inputs
     (list zlib acl))
    (native-inputs
     (list pkg-config))
    (home-page "https://dev.lovelyhq.com/libburnia/libisofs")
    (synopsis "Library to create ISO 9660 images")
    (description
     "Libisofs creates ISO 9660 (also known as ECMA-119) file system images
which can either be written to POSIX file objects or handed over to
libburn for being written directly to optical media.
It can read metadata of ISO 9660 filesystems, manipulate them, and use them
to produce new complete file system images or add-on images to be appended
to the read file system image.
Supported extensions to ISO 9660 are Rock Ridge, Joliet, AAIP, zisofs.")
    (license gpl2+)))

(define-public cdrkit-libre
  (package
    (name "cdrkit-libre")
    (version "1.1.11")
    (source (origin
              (method url-fetch)
              ;; cdrkit.org is dead.
              ;;
              ;; ‘cdrkit-libre’ removes a couple of problematic files,
              ;; see <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32165#14>.
              (uri (string-append
                    "https://repo.parabola.nu/other/cdrkit-libre/cdrkit-libre-"
                    version ".tar.gz"))
              (sha256
               (base32
                "0g2zyzb56czh429qy87lvaddzjnlcq8c616ddxsmsshz3clhyzrh"))
              (patches (search-patches "cdrkit-libre-cross-compile.patch"))
              (modules '((guix build utils)))
              (snippet
                #~(begin
                    ;; Fix building with gcc-10.
                    (substitute* "genisoimage/genisoimage.h"
                      (("char\t\t\\*outfile")
                       "extern char\t*outfile"))))))
    (build-system cmake-build-system)
    (inputs
     (list bzip2 libcap perl zlib))
    (arguments
     `(#:tests? #f ;no tests
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'old-cdrecord
           (lambda* (#:key outputs #:allow-other-keys)
             (with-directory-excursion (string-append (assoc-ref outputs "out")
                                                      "/bin")
               (symlink "genisoimage" "mkisofs")
               (symlink "wodim" "cdrecord"))
             #t)))))
    (home-page "https://repo.parabola.nu/other/cdrkit-libre/")
    (synopsis "Command-line CD/DVD recorder")
    (description "Cdrkit is a suite of programs for recording CDs and DVDs,
blanking CD-RW media, creating ISO-9660 file system images, extracting audio
CD data, and more.  It's mostly compatible with @code{cdrtools}.")
    (license gpl2+)))

(define-public libmirage
  (package
    (name "libmirage")
    (version "3.2.7")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "mirror://sourceforge/cdemu/libmirage/libmirage-"
                    version ".tar.xz"))
              (sha256
               (base32
                "1lxkpmad8l2wl0afp26jahzf5cxp10p0zl1a56lcqjwmsy0292gs"))))
    (build-system cmake-build-system)
    (native-inputs
     (list pkg-config intltool))
    (inputs
     (list glib))
    (arguments
     ;; No tests.
     '(#:tests? #f))
    (home-page "https://cdemu.sourceforge.io/")
    (synopsis "CD-ROM image access library")
    (description "libMirage is a CD-ROM image access library.  It supports the
following formats: B6T, C2D, CCD, CDI, CIF, CUE, ISO, MDS, MDX, NRG, TOC.  It
is written in C and based on GLib.  Its aim is to provide uniform access to
the data stored in various image formats.")
    (license gpl2+)))

(define-public cdemu-daemon
  (package
    (name "cdemu-daemon")
    (version "3.2.6")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "mirror://sourceforge/cdemu/cdemu-daemon/"
                    "cdemu-daemon-" version ".tar.xz"))
              (sha256
               (base32
                "13vxhl7ik3h5qnfh6m0zxywb8qzx1n46akrm6rp19ikmxzih9r56"))))
    (build-system cmake-build-system)
    (native-inputs
     (list pkg-config intltool))
    (inputs
     (list libmirage glib ao))
    (arguments
     ;; No tests.
     '(#:tests? #f))
    (home-page "https://cdemu.sourceforge.io/")
    (synopsis "CD/DVD-ROM device emulator")
    (description "CDemu is a software suite designed to emulate an optical
drive and disc (including CD-ROMs and DVD-ROMs).")
    (license gpl2+)))

(define-public cdemu-client
  (package
    (name "cdemu-client")
    (version "3.2.5")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "mirror://sourceforge/cdemu/cdemu-client/cdemu-client-"
                    version ".tar.xz"))
              (sha256
               (base32
                "1prrdhv0ia0axc6b73crszqzh802wlkihz6d100yvg7wbgmqabd7"))))
    (build-system cmake-build-system)
    (native-inputs
     (list pkg-config intltool))
    (inputs
     (list bash-minimal python python-pygobject cdemu-daemon))
    (arguments
     ;; No tests.
     `(#:tests? #f
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'patch-shebang
           (lambda* (#:key outputs #:allow-other-keys)
             (patch-shebang (string-append (assoc-ref outputs "out")
                                           "/bin/cdemu"))))
         (add-after 'patch-shebang 'wrap-program
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((prog (string-append (assoc-ref outputs "out")
                                        "/bin/cdemu")))
               (wrap-program prog
                 `("GUIX_PYTHONPATH" = (,(getenv "GUIX_PYTHONPATH"))))))))))
    (home-page "https://cdemu.sourceforge.io/")
    (synopsis "Command-line client for controlling cdemu-daemon")
    (description "CDEmu client is a simple command-line client for controlling
CDEmu daemon.

It provides a way to perform the key tasks related to controlling the CDEmu
daemon, such as loading and unloading devices, displaying devices' status and
retrieving/setting devices' debug masks.")
    (license gpl2+)))
gt; service-type make-service-type service-type? (name service-type-name) ;symbol (for debugging) ;; Things extended by services of this type. (extensions service-type-extensions) ;list of <service-extensions> ;; Given a list of extensions, "compose" them. (compose service-type-compose ;list of Any -> Any (default #f)) ;; Extend the services' own parameters with the extension composition. (extend service-type-extend ;list of Any -> parameters (default #f)) ;; Optional default value for instances of this type. (default-value service-type-default-value ;Any (default &no-default-value)) ;; Meta-data. (description service-type-description) ;string (location service-type-location ;<location> (default (and=> (current-source-location) source-properties->location)) (innate))) (define (write-service-type type port) (format port "#<service-type ~a ~a>" (service-type-name type) (number->string (object-address type) 16))) (set-record-type-printer! <service-type> write-service-type) (define %distro-root-directory ;; Absolute file name of the module hierarchy. (dirname (search-path %load-path "guix.scm"))) (define %service-type-path ;; Search path for service types. (make-parameter `((,%distro-root-directory . "gnu/services") (,%distro-root-directory . "gnu/system")))) (define (all-service-modules) "Return the default set of service modules." (cons (resolve-interface '(gnu services)) (all-modules (%service-type-path) #:warn warn-about-load-error))) (define* (fold-service-types proc seed #:optional (modules (all-service-modules))) "For each service type exported by one of MODULES, call (PROC RESULT). SEED is used as the initial value of RESULT." (fold-module-public-variables (lambda (object result) (if (service-type? object) (proc object result) result)) seed modules)) (define lookup-service-types (let ((table (delay (fold-service-types (lambda (type result) (vhash-consq (service-type-name type) type result)) vlist-null)))) (lambda (name) "Return the list of services with the given NAME (a symbol)." (vhash-foldq* cons '() name (force table))))) ;; Services of a given type. (define-record-type <service> (make-service type value) service? (type service-kind) (value service-value)) (define-syntax service (syntax-rules () "Return a service instance of TYPE. The service value is VALUE or, if omitted, TYPE's default value." ((_ type value) (make-service type value)) ((_ type) (%service-with-default-value (current-source-location) type)))) (define (%service-with-default-value location type) "Return a instance of service type TYPE with its default value, if any. If TYPE does not have a default value, an error is raised." ;; TODO: Currently this is a run-time error but with a little bit macrology ;; we could turn it into an expansion-time error. (let ((default (service-type-default-value type))) (if (eq? default &no-default-value) (let ((location (source-properties->location location))) (raise (make-compound-condition (condition (&missing-value-service-error (type type) (location location))) (formatted-message (G_ "~a: no value specified \ for service of type '~a'") (location->string location) (service-type-name type))))) (service type default)))) (define-condition-type &service-error &error service-error?) (define-condition-type &missing-value-service-error &service-error missing-value-service-error? (type missing-value-service-error-type) (location missing-value-service-error-location)) ;;; ;;; Helpers. ;;; (define service-parameters ;; Deprecated alias. service-value) (define (simple-service name target value) "Return a service that extends TARGET with VALUE. This works by creating a singleton service type NAME, of which the returned service is an instance." (let* ((extension (service-extension target identity)) (type (service-type (name name) (extensions (list extension)) (description "This is a simple service.")))) (service type value))) (define-syntax clause-alist (syntax-rules (=> delete) "Build an alist of clauses. Each element has the form (KIND PROC LOC) where PROC is the service transformation procedure to apply for KIND, and LOC is the source location information." ((_ (delete kind) rest ...) (cons (list kind (lambda (service) #f) (current-source-location)) (clause-alist rest ...))) ((_ (kind param => exp ...) rest ...) (cons (list kind (lambda (svc) (let ((param (service-value svc))) (service (service-kind svc) (begin exp ...)))) (current-source-location)) (clause-alist rest ...))) ((_) '()))) (define (apply-clauses clauses services) "Apply CLAUSES, an alist as returned by 'clause-alist', to SERVICES, a list of services. Use each clause at most once; raise an error if a clause was not used." (let loop ((services services) (clauses clauses) (result '())) (match services (() (match clauses (() ;all clauses fired, good (reverse result)) (((kind _ properties) _ ...) ;one or more clauses didn't match (raise (make-compound-condition (condition (&error-location (location (source-properties->location properties)))) (formatted-message (G_ "modify-services: service '~a' not found in service list") (service-type-name kind))))))) ((head . tail) (let ((service clauses (fold2 (lambda (clause service remainder) (if service (match clause ((kind proc properties) (if (eq? kind (service-kind service)) (values (proc service) remainder) (values service (cons clause remainder))))) (values #f (cons clause remainder)))) head '() clauses))) (loop tail (reverse clauses) (if service (cons service result) result))))))) (define-syntax modify-services (syntax-rules () "Modify the services listed in SERVICES according to CLAUSES and return the resulting list of services. Each clause must have the form: (TYPE VARIABLE => BODY) where TYPE is a service type, such as 'guix-service-type', and VARIABLE is an identifier that is bound within BODY to the value of the service of that TYPE. Clauses can also remove services of a given type: (delete TYPE) Consider this example: (modify-services %base-services (guix-service-type config => (guix-configuration (inherit config) (use-substitutes? #f) (extra-options '(\"--gc-keep-derivations\")))) (mingetty-service-type config => (mingetty-configuration (inherit config) (motd (plain-file \"motd\" \"Hi there!\")))) (delete udev-service-type)) It changes the configuration of the GUIX-SERVICE-TYPE instance, and that of all the MINGETTY-SERVICE-TYPE instances, and it deletes instances of the UDEV-SERVICE-TYPE." ((_ services clauses ...) (apply-clauses (clause-alist clauses ...) services)))) ;;; ;;; Core services. ;;; (define (system-derivation entries mextensions) "Return as a monadic value the derivation of the 'system' directory containing the given entries." (mlet %store-monad ((extensions (mapm/accumulate-builds identity mextensions))) (lower-object (file-union "system" (append entries (concatenate extensions)))))) (define system-service-type ;; This is the ultimate service type, the root of the service DAG. The ;; service of this type is extended by monadic name/item pairs. These items ;; end up in the "system directory" as returned by ;; 'operating-system-derivation'. (service-type (name 'system) (extensions '()) (compose identity) (extend system-derivation) (description "Build the operating system top-level directory, which in turn refers to everything the operating system needs: its kernel, initrd, system profile, boot script, and so on."))) (define (compute-boot-script _ gexps) ;; Reverse GEXPS so that extensions appear in the boot script in the right ;; order. That is, user extensions would come first, and extensions added ;; by 'essential-services' (e.g., running shepherd) are guaranteed to come ;; last. (gexp->file "boot" ;; Clean up and activate the system, then spawn shepherd. #~(begin #$@(reverse gexps)))) (define (boot-script-entry mboot) "Return, as a monadic value, an entry for the boot script in the system directory." (mlet %store-monad ((boot mboot)) (return `(("boot" ,boot))))) (define boot-service-type ;; The service of this type is extended by being passed gexps. It ;; aggregates them in a single script, as a monadic value, which becomes its ;; value. (service-type (name 'boot) (extensions (list (service-extension system-service-type boot-script-entry))) (compose identity) (extend compute-boot-script) (default-value #f) (description "Produce the operating system's boot script, which is spawned by the initrd once the root file system is mounted."))) (define %boot-service ;; The service that produces the boot script. (service boot-service-type #t)) ;;; ;;; Provenance tracking. ;;; (define (object->pretty-string obj) "Like 'object->string', but using 'pretty-print'." (call-with-output-string (lambda (port) (pretty-print obj port)))) (define (channel->code channel) "Return code to build CHANNEL, ready to be dropped in a 'channels.scm' file." ;; Since the 'introduction' field is backward-incompatible, and since it's ;; optional when using the "official" 'guix channel, include it if and only ;; if we're referring to a different channel. (let ((intro (and (not (equal? (list channel) %default-channels)) (channel-introduction channel)))) `(channel (name ',(channel-name channel)) (url ,(channel-url channel)) (branch ,(channel-branch channel)) (commit ,(channel-commit channel)) ,@(if intro `((introduction (make-channel-introduction ,(channel-introduction-first-signed-commit intro) (openpgp-fingerprint ,(openpgp-format-fingerprint (channel-introduction-first-commit-signer intro)))))) '())))) (define (channel->sexp channel) "Return an sexp describing CHANNEL. The sexp is _not_ code and is meant to be parsed by tools; it's potentially more future-proof than code." ;; TODO: Add CHANNEL's introduction. Currently we can't do that because ;; older 'guix system describe' expect exactly name/url/branch/commit ;; without any additional fields. `(channel (name ,(channel-name channel)) (url ,(channel-url channel)) (branch ,(channel-branch channel)) (commit ,(channel-commit channel)))) (define (sexp->channel sexp) "Return the channel corresponding to SEXP, an sexp as found in the \"provenance\" file produced by 'provenance-service-type'." (match sexp (('channel ('name name) ('url url) ('branch branch) ('commit commit) rest ...) ;; XXX: In the future REST may include a channel introduction. (channel (name name) (url url) (branch branch) (commit commit))))) (define (provenance-file channels config-file) "Return a 'provenance' file describing CHANNELS, a list of channels, and CONFIG-FILE, which can be either #f or a <local-file> containing the OS configuration being used." (scheme-file "provenance" #~(provenance (version 0) (channels #+@(if channels (map channel->sexp channels) '())) (configuration-file #+config-file)))) (define (provenance-entry config-file) "Return system entries describing the operating system provenance: the channels in use and CONFIG-FILE, if it is true." (define channels (current-channels)) (mbegin %store-monad (let ((config-file (cond ((string? config-file) ;; CONFIG-FILE has been passed typically via ;; 'guix system reconfigure CONFIG-FILE' so we ;; can assume it's valid: tell 'local-file' to ;; not emit a warning. (local-file (assume-valid-file-name config-file) "configuration.scm")) ((not config-file) #f) (else config-file)))) (return `(("provenance" ,(provenance-file channels config-file)) ,@(if channels `(("channels.scm" ,(plain-file "channels.scm" (object->pretty-string `(list ,@(map channel->code channels)))))) '()) ,@(if config-file `(("configuration.scm" ,config-file)) '())))))) (define provenance-service-type (service-type (name 'provenance) (extensions (list (service-extension system-service-type provenance-entry))) (default-value #f) ;the OS config file (description "Store provenance information about the system in the system itself: the channels used when building the system, and its configuration file, when available."))) (define (sexp->system-provenance sexp) "Parse SEXP, an s-expression read from /run/current-system/provenance or similar, and return two values: the list of channels listed therein, and the OS configuration file or #f." (match sexp (('provenance ('version 0) ('channels channels ...) ('configuration-file config-file)) (values (map sexp->channel channels) config-file)) (_ (values '() #f)))) (define (system-provenance system) "Given SYSTEM, the file name of a system generation, return two values: the list of channels SYSTEM is built from, and its configuration file. If that information is missing, return the empty list (for channels) and possibly #false (for the configuration file)." (catch 'system-error (lambda () (sexp->system-provenance (call-with-input-file (string-append system "/provenance") read))) (lambda _ (values '() #f)))) ;;; ;;; Cleanup. ;;; (define (cleanup-gexp _) "Return a gexp to clean up /tmp and similar places upon boot." (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) ;; Clean out /tmp and /var/run. ;; ;; XXX This needs to happen before service activations, so it ;; has to be here, but this also implicitly assumes that /tmp ;; and /var/run are on the root partition. (letrec-syntax ((fail-safe (syntax-rules () ((_ exp rest ...) (begin (catch 'system-error (lambda () exp) (const #f)) (fail-safe rest ...))) ((_) #t)))) ;; Ignore I/O errors so the system can boot. (fail-safe ;; Remove stale Shadow lock files as they would lead to ;; failures of 'useradd' & co. (delete-file "/etc/group.lock") (delete-file "/etc/passwd.lock") (delete-file "/etc/.pwd.lock") ;from 'lckpwdf' ;; Force file names to be decoded as UTF-8. See ;; <https://bugs.gnu.org/26353>. (setenv "GUIX_LOCPATH" #+(file-append glibc-utf8-locales "/lib/locale")) (setlocale LC_CTYPE "en_US.utf8") (delete-file-recursively "/tmp") (delete-file-recursively "/var/run") (mkdir "/tmp") (chmod "/tmp" #o1777) (mkdir "/var/run") (chmod "/var/run" #o755) (delete-file-recursively "/run/udev/watch.old")))))) (define cleanup-service-type ;; Service that cleans things up in /tmp and similar. (service-type (name 'cleanup) (extensions (list (service-extension boot-service-type cleanup-gexp))) (description "Delete files from @file{/tmp}, @file{/var/run}, and other temporary locations at boot time."))) (define* (activation-service->script service) "Return as a monadic value the activation script for SERVICE, a service of ACTIVATION-SCRIPT-TYPE." (activation-script (service-value service))) (define (activation-script gexps) "Return the system's activation script, which evaluates GEXPS." (define actions (map (cut program-file "activate-service.scm" <>) gexps)) (program-file "activate.scm" (with-imported-modules (source-module-closure '((gnu build activation) (guix build utils))) #~(begin (use-modules (gnu build activation) (guix build utils)) ;; Make sure the user accounting database exists. If it ;; does not exist, 'setutxent' does not create it and ;; thus there is no accounting at all. (close-port (open-file "/var/run/utmpx" "a0")) ;; Same for 'wtmp', which is populated by mingetty et ;; al. (mkdir-p "/var/log") (close-port (open-file "/var/log/wtmp" "a0")) ;; Set up /run/current-system. Among other things this ;; sets up locales, which the activation snippets ;; executed below may expect. (activate-current-system) ;; Run the services' activation snippets. ;; TODO: Use 'load-compiled'. (for-each primitive-load '#$actions))))) (define (gexps->activation-gexp gexps) "Return a gexp that runs the activation script containing GEXPS." #~(primitive-load #$(activation-script gexps))) (define (activation-profile-entry gexps) "Return, as a monadic value, an entry for the activation script in the system directory." (mlet %store-monad ((activate (lower-object (activation-script gexps)))) (return `(("activate" ,activate))))) (define (second-argument a b) b) (define activation-service-type (service-type (name 'activate) (extensions (list (service-extension boot-service-type gexps->activation-gexp) (service-extension system-service-type activation-profile-entry))) (compose identity) (extend second-argument) (default-value #f) (description "Run @dfn{activation} code at boot time and upon @command{guix system reconfigure} completion."))) (define %activation-service ;; The activation service produces the activation script from the gexps it ;; receives. (service activation-service-type #t)) (define %modprobe-wrapper ;; Wrapper for the 'modprobe' command that knows where modules live. ;; ;; This wrapper is typically invoked by the Linux kernel ('call_modprobe', ;; in kernel/kmod.c), a situation where the 'LINUX_MODULE_DIRECTORY' ;; environment variable is not set---hence the need for this wrapper. (let ((modprobe "/run/current-system/profile/bin/modprobe")) (program-file "modprobe" #~(begin (setenv "LINUX_MODULE_DIRECTORY" "/run/booted-system/kernel/lib/modules") ;; FIXME: Remove this crutch when the patch #40422, ;; updating to kmod 27 is merged. (setenv "MODPROBE_OPTIONS" "-C /etc/modprobe.d") (apply execl #$modprobe (cons #$modprobe (cdr (command-line)))))))) (define %linux-kernel-activation ;; Activation of the Linux kernel running on the bare metal (as opposed to ;; running in a container.) #~(begin ;; Tell the kernel to use our 'modprobe' command. (activate-modprobe #$%modprobe-wrapper) ;; Let users debug their own processes! (activate-ptrace-attach))) (define %linux-bare-metal-service ;; The service that does things that are needed on the "bare metal", but not ;; necessary or impossible in a container. (simple-service 'linux-bare-metal activation-service-type %linux-kernel-activation)) (define %hurd-rc-script ;; The RC script to be started upon boot. (program-file "rc" (with-imported-modules (source-module-closure '((guix build utils) (gnu build hurd-boot) (guix build syscalls))) #~(begin (use-modules (guix build utils) (gnu build hurd-boot) (guix build syscalls) (ice-9 match) (system repl repl) (srfi srfi-1) (srfi srfi-26)) (boot-hurd-system))))) (define (hurd-rc-entry rc) "Return, as a monadic value, an entry for the RC script in the system directory." (mlet %store-monad ((rc (lower-object rc))) (return `(("rc" ,rc))))) (define hurd-startup-service-type ;; The service that creates the initial SYSTEM/rc startup file. (service-type (name 'startup) (extensions (list (service-extension system-service-type hurd-rc-entry))) (default-value %hurd-rc-script) (description "This service creates an @file{rc} script in the system; that script is responsible for booting the Hurd."))) (define %hurd-startup-service ;; The service that produces the RC script. (service hurd-startup-service-type %hurd-rc-script)) (define special-files-service-type ;; Service to install "special files" such as /bin/sh and /usr/bin/env. (service-type (name 'special-files) (extensions (list (service-extension activation-service-type (lambda (files) #~(activate-special-files '#$files))))) (compose concatenate) (extend append) (description "Add special files to the root file system---e.g., @file{/usr/bin/env}."))) (define (extra-special-file file target) "Use TARGET as the \"special file\" FILE. For example, TARGET might be (file-append coreutils \"/bin/env\") and FILE could be \"/usr/bin/env\"." (simple-service (string->symbol (string-append "special-file-" file)) special-files-service-type `((,file ,target)))) (define (etc-directory service) "Return the directory for SERVICE, a service of type ETC-SERVICE-TYPE." (files->etc-directory (service-value service))) (define (files->etc-directory files) (define (assert-no-duplicates files) (let loop ((files files) (seen (set))) (match files (() #t) (((file _) rest ...) (when (set-contains? seen file) (raise (formatted-message (G_ "duplicate '~a' entry for /etc") file))) (loop rest (set-insert file seen)))))) ;; Detect duplicates early instead of letting them through, eventually ;; leading to a build failure of "etc.drv". (assert-no-duplicates files) (file-union "etc" files)) (define (etc-entry files) "Return an entry for the /etc directory consisting of FILES in the system directory." (with-monad %store-monad (return `(("etc" ,(files->etc-directory files)))))) (define etc-service-type (service-type (name 'etc) (extensions (list (service-extension activation-service-type (lambda (files) (let ((etc (files->etc-directory files))) #~(activate-etc #$etc)))) (service-extension system-service-type etc-entry))) (compose concatenate) (extend append) (default-value '()) (description "Populate the @file{/etc} directory."))) (define-deprecated (etc-service files) etc-service-type "Return a new service of ETC-SERVICE-TYPE that populates /etc with FILES. FILES must be a list of name/file-like object pairs." (service etc-service-type files)) (define (setuid-program->activation-gexp programs) "Return an activation gexp for setuid-program from PROGRAMS." (let ((programs (map (lambda (program) ;; FIXME This is really ugly, I didn't managed to use ;; "inherit" (let ((program-name (setuid-program-program program)) (setuid? (setuid-program-setuid? program)) (setgid? (setuid-program-setgid? program)) (user (setuid-program-user program)) (group (setuid-program-group program)) ) #~(setuid-program (setuid? #$setuid?) (setgid? #$setgid?) (user #$user) (group #$group) (program #$program-name)))) programs))) (with-imported-modules (source-module-closure '((gnu system setuid))) #~(begin (use-modules (gnu system setuid)) (activate-setuid-programs (list #$@programs)))))) (define setuid-program-service-type (service-type (name 'setuid-program) (extensions (list (service-extension activation-service-type setuid-program->activation-gexp))) (compose concatenate) (extend (lambda (config extensions) (append config extensions))) (description "Populate @file{/run/setuid-programs} with the specified executables, making them setuid and/or setgid."))) (define (packages->profile-entry packages) "Return a system entry for the profile containing PACKAGES." ;; XXX: 'mlet' is needed here for one reason: to get the proper ;; '%current-target' and '%current-target-system' bindings when ;; 'packages->manifest' is called, and thus when the 'package-inputs' ;; etc. procedures are called on PACKAGES. That way, conditionals in those ;; inputs see the "correct" value of these two parameters. See ;; <https://issues.guix.gnu.org/44952>. (mlet %store-monad ((_ (current-target-system))) (return `(("profile" ,(profile (content (packages->manifest (delete-duplicates packages eq?))))))))) (define profile-service-type ;; The service that populates the system's profile---i.e., ;; /run/current-system/profile. It is extended by package lists. (service-type (name 'profile) (extensions (list (service-extension system-service-type packages->profile-entry))) (compose concatenate) (extend append) (default-value '()) (description "This is the @dfn{system profile}, available as @file{/run/current-system/profile}. It contains packages that the sysadmin wants to be globally available to all the system users."))) (define (firmware->activation-gexp firmware) "Return a gexp to make the packages listed in FIRMWARE loadable by the kernel." (let ((directory (directory-union "firmware" firmware))) ;; Tell the kernel where firmware is. #~(activate-firmware (string-append #$directory "/lib/firmware")))) (define firmware-service-type ;; The service that collects firmware. (service-type (name 'firmware) (extensions (list (service-extension activation-service-type firmware->activation-gexp))) (compose concatenate) (extend append) (description "Make ``firmware'' files loadable by the operating system kernel. Firmware may then be uploaded to some of the machine's devices, such as Wifi cards."))) (define (gc-roots->system-entry roots) "Return an entry in the system's output containing symlinks to ROOTS." (mlet %store-monad ((entry (gexp->derivation "gc-roots" #~(let ((roots '#$roots)) (mkdir #$output) (chdir #$output) (for-each symlink roots (map number->string (iota (length roots)))))))) (return (if (null? roots) '() `(("gc-roots" ,entry)))))) (define gc-root-service-type ;; A service to associate extra garbage-collector roots to the system. This ;; is a simple hack that guarantees that the system retains references to ;; the given list of roots. Roots must be "lowerable" objects like ;; packages, or derivations. (service-type (name 'gc-roots) (extensions (list (service-extension system-service-type gc-roots->system-entry))) (compose concatenate) (extend append) (description "Register garbage-collector roots---i.e., store items that will not be reclaimed by the garbage collector.") (default-value '()))) ;; Configuration for the Linux kernel builder. (define-record-type* <linux-builder-configuration> linux-builder-configuration make-linux-builder-configuration linux-builder-configuration? this-linux-builder-configuration (kernel linux-builder-configuration-kernel) ; package (modules linux-builder-configuration-modules (default '()))) ; list of packages (define (package-for-kernel target-kernel module-package) "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if possible (that is if there's a LINUX keyword argument in the build system)." (package (inherit module-package) (arguments (substitute-keyword-arguments (package-arguments module-package) ((#:linux kernel #f) target-kernel))))) (define (linux-builder-configuration->system-entry config) "Return the kernel entry of the 'system' directory." (let* ((kernel (linux-builder-configuration-kernel config)) (modules (linux-builder-configuration-modules config)) (kernel (profile (content (packages->manifest (cons kernel (map (lambda (module) (cond ((package? module) (package-for-kernel kernel module)) ;; support (,package "kernel-module-output") ((and (list? module) (package? (car module))) (cons (package-for-kernel kernel (car module)) (cdr module))) (else module))) modules)))) (hooks (list linux-module-database))))) (with-monad %store-monad (return `(("kernel" ,kernel)))))) (define linux-builder-service-type (service-type (name 'linux-builder) (extensions (list (service-extension system-service-type linux-builder-configuration->system-entry))) (default-value '()) (compose identity) (extend (lambda (config modifiers) (if (null? modifiers) config ((apply compose modifiers) config)))) (description "Builds the linux-libre kernel profile, containing the kernel itself and any linux-loadable kernel modules. This can be extended with a function that accepts the current configuration and returns a new configuration."))) (define (linux-loadable-module-builder-modifier modules) "Extends linux-builder-service-type by appending the given MODULES to the configuration of linux-builder-service-type." (lambda (config) (linux-builder-configuration (inherit config) (modules (append (linux-builder-configuration-modules config) modules))))) (define linux-loadable-module-service-type (service-type (name 'linux-loadable-modules) (extensions (list (service-extension linux-builder-service-type linux-loadable-module-builder-modifier))) (default-value '()) (compose concatenate) (extend append) (description "Adds packages and package outputs as modules included in the booted linux-libre profile. Other services can extend this service type to add particular modules to the set of linux-loadable modules."))) ;;; ;;; Service folding. ;;; (define-condition-type &missing-target-service-error &service-error missing-target-service-error? (service missing-target-service-error-service) (target-type missing-target-service-error-target-type)) (define-condition-type &ambiguous-target-service-error &service-error ambiguous-target-service-error? (service ambiguous-target-service-error-service) (target-type ambiguous-target-service-error-target-type)) (define (missing-target-error service target-type) (raise (condition (&missing-target-service-error (service service) (target-type target-type)) (&message (message (format #f (G_ "no target of type '~a' for service '~a'") (service-type-name target-type) (service-type-name (service-kind service)))))))) (define (service-back-edges services) "Return a procedure that, when passed a <service>, returns the list of <service> objects that depend on it." (define (add-edges service edges) (define (add-edge extension edges) (let ((target-type (service-extension-target extension))) (match (filter (lambda (service) (eq? (service-kind service) target-type)) services) ((target) (vhash-consq target service edges)) (() (missing-target-error service target-type)) (x (raise (condition (&ambiguous-target-service-error (service service) (target-type target-type)) (&message (message (format #f (G_ "more than one target service of type '~a'") (service-type-name target-type)))))))))) (fold add-edge edges (service-type-extensions (service-kind service)))) (let ((edges (fold add-edges vlist-null services))) (lambda (node) (reverse (vhash-foldq* cons '() node edges))))) (define (instantiate-missing-services services) "Return SERVICES, a list, augmented with any services targeted by extensions and missing from SERVICES. Only service types with a default value can be instantiated; other missing services lead to a '&missing-target-service-error'." (define (adjust-service-list svc result instances) (fold2 (lambda (extension result instances) (define target-type (service-extension-target extension)) (match (vhash-assq target-type instances) (#f (let ((default (service-type-default-value target-type))) (if (eq? &no-default-value default) (missing-target-error svc target-type) (let ((new (service target-type))) (values (cons new result) (vhash-consq target-type new instances)))))) (_ (values result instances)))) result instances (service-type-extensions (service-kind svc)))) (let loop ((services services)) (define instances (fold (lambda (service result) (vhash-consq (service-kind service) service result)) vlist-null services)) (define adjusted (fold2 adjust-service-list services instances services)) ;; If we instantiated services, they might in turn depend on missing ;; services. Loop until we've reached fixed point. (if (= (length adjusted) (vlist-length instances)) adjusted (loop adjusted)))) (define* (fold-services services #:key (target-type system-service-type)) "Fold SERVICES by propagating their extensions down to the root of type TARGET-TYPE; return the root service adjusted accordingly." (define dependents (service-back-edges services)) (define (matching-extension target) (let ((target (service-kind target))) (match-lambda (($ <service-extension> type) (eq? type target))))) (define (apply-extension target) (lambda (service) (match (find (matching-extension target) (service-type-extensions (service-kind service))) (($ <service-extension> _ compute) (compute (service-value service)))))) (match (filter (lambda (service) (eq? (service-kind service) target-type)) services) ((sink) ;; Use the state monad to keep track of already-visited services in the ;; graph and to memoize their value once folded. (run-with-state (let loop ((sink sink)) (mlet %state-monad ((visited (current-state))) (match (vhash-assq sink visited) (#f (mlet* %state-monad ((dependents (mapm %state-monad loop (dependents sink))) (visited (current-state)) (extensions -> (map (apply-extension sink) dependents)) (extend -> (service-type-extend (service-kind sink))) (compose -> (service-type-compose (service-kind sink))) (params -> (service-value sink)) (service -> ;; Distinguish COMPOSE and EXTEND because PARAMS typically ;; has a different type than the elements of EXTENSIONS. (if extend (service (service-kind sink) (extend params (compose extensions))) sink))) (mbegin %state-monad (set-current-state (vhash-consq sink service visited)) (return service)))) ((_ . service) ;SINK was already visited (return service))))) vlist-null)) (() (raise (make-compound-condition (condition (&missing-target-service-error (service #f) (target-type target-type))) (formatted-message (G_ "service of type '~a' not found") (service-type-name target-type))))) (x (raise (condition (&ambiguous-target-service-error (service #f) (target-type target-type)) (&message (message (format #f (G_ "more than one target service of type '~a'") (service-type-name target-type))))))))) (define (remove-service-extensions type lst) "Return TYPE, a service type, without any of the service extensions targeting one of the types in LST." (service-type (inherit type) (extensions (remove (lambda (extension) (memq (service-extension-target extension) lst)) (service-type-extensions type))))) (define-syntax-parameter for-home? ;; Whether the configuration being defined is for a Home service. (identifier-syntax #f)) (define-syntax-rule (for-home exp ...) "Mark EXP, which typically defines a service configuration, as targeting a Home service rather than a System service." (syntax-parameterize ((for-home? (identifier-syntax #t))) exp ...)) ;;; services.scm ends here.