# GNU Guix --- Functional package management for GNU # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès # Copyright © 2013 Andreas Enge # Copyright © 2015, 2017 Alex Kost # Copyright © 2016, 2018 Mathieu Lirzin # Copyright © 2016, 2017, 2018, 2019 Mark H Weaver # Copyright © 2017 Mathieu Othacehe # Copyright © 2017 Leo Famulari # Copyright © 2017 Ricardo Wurmus # Copyright © 2017 Jan Nieuwenhuizen # Copyright © 2017 Arun Isaac # Copyright © 2018 ng0 # Copyright © 2018 Julien Lepiller # Copyright © 2018 Oleg Pykhalov # Copyright © 2018 Alex Vong # Copyright © 2019 Efraim Flashner # # This file is part of GNU Guix. # # GNU Guix is free software; you can re
aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012-2024 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2019 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2014, 2015, 2016, 2018 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
;;; Copyright © 2014, 2015 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
;;; Copyright © 2016, 2017, 2019-2023 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016, 2020, 2023, 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2016, 2018 Alex Vong <alexvong1995@gmail.com>
;;; Copyright © 2017 Rene Saavedra <rennes@openmailbox.org>
;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2017, 2018, 2020, 2022 Marius Bakke <marius@gnu.org>
;;; Copyright © 2017 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018, 2019, 2022 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Vitaliy Shatrov <D0dyBo0D0dyBo0@protonmail.com>
;;; Copyright © 2020 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2021 Leo Le Bouter <lle-bout@zaclys.net>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2021, 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2022 zamfofex <zamfofex@twdb.moe>
;;; Copyright © 2022 John Kehayias <john.kehayias@protonmail.com>
;;; Copyright © 2023 Josselin Poiret <dev@jpoiret.xyz>
;;; Copyright © 2024 Zheng Junjie <873216071@qq.com>
;;;
;;; 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 base)
  #:use-module ((guix licenses)
                #:select (gpl3+ lgpl2.0+ lgpl3+ public-domain))
  #:use-module (gnu packages)
  #:use-module (gnu packages acl)
  #:use-module (gnu packages algebra)
  #:use-module (gnu packages attr)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages build-tools)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages text-editors)
  #:use-module (gnu packages hurd)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages gettext)
  #:use-module (guix i18n)
  #:use-module (guix utils)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (guix search-paths)
  #:use-module (ice-9 format)
  #:use-module (ice-9 match)
  #:use-module (ice-9 optargs)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (glibc
            libc-for-target
            libc-locales-for-target
            libc-utf8-locales-for-target
            make-ld-wrapper
            libiconv-if-needed

            ;; Beware: the following should not be used the top level to avoid
            ;; introducing circular module dependencies.
            canonical-package
            %final-inputs))

;;; Commentary:
;;;
;;; Base packages of the Guix-based GNU user-land software distribution.
;;;
;;; Code:

(define-public hello
  (package
    (name "hello")
    (version "2.12.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/hello/hello-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "086vqwk2wl8zfs47sq2xpjc9k066ilmb8z6dn0q6ymwjzlm196cd"))))
    (build-system gnu-build-system)
    (synopsis "Hello, GNU world: An example GNU package")
    (description
     "GNU Hello prints the message \"Hello, world!\" and then exits.  It
serves as an example of standard GNU coding practices.  As such, it supports
command-line arguments, multiple languages, and so on.")
    (home-page "https://www.gnu.org/software/hello/")
    (license gpl3+)))

(define-public grep
  (package
   (name "grep")
   (version "3.11")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/grep/grep-"
                                version ".tar.xz"))
            (sha256
             (base32
              "1avf4x8skxbqrjp5j2qr9sp5vlf8jkw2i5bdn51fl3cxx3fsxchx"))
            (patches (search-patches "grep-timing-sensitive-test.patch"))))
   (build-system gnu-build-system)
   (native-inputs (list perl))                   ;some of the tests require it
   (inputs (list pcre2))
   (arguments
    (list #:configure-flags #~(list "--enable-perl-regexp")

          ;; XXX: On 32-bit Hurd platforms, 'time_t' is defined as a 32-bit
          ;; integer in 'hurd_types.defs', so this Gnulib test always fails.
          #:make-flags
          #~#$(if (and (not (%current-target-system))
                       (string=? (%current-system) "i586-gnu"))
                  #~'("XFAIL_TESTS=test-year2038")
                  #~'())

          #:phases
          #~(modify-phases %standard-phases
              (add-after 'install 'fix-egrep-and-fgrep
                ;; Patch 'egrep' and 'fgrep' to execute 'grep' via its
                ;; absolute file name instead of searching for it in $PATH.
                (lambda* (#:key outputs #:allow-other-keys)
                  (let* ((out (assoc-ref outputs "out"))
                         (bin (string-append out "/bin")))
                    (substitute* (list (string-append bin "/egrep")
                                       (string-append bin "/fgrep"))
                      (("^exec grep")
                       (string-append "exec " bin "/grep"))))))
              #$@(if (system-hurd?)
                     #~((add-before 'check 'skip-test
                          (lambda _
                            (substitute* ;; This test hangs
                                '("tests/hash-collision-perf"
                                  ;; This test fails
                                  "tests/file")
                              (("^#!.*" all)
                               (string-append all "exit 77;\n"))))))
                     #~()))))
   (synopsis "Print lines matching a pattern")
   (description
     "grep is a tool for finding text inside files.  Text is found by
matching a pattern provided by the user in one or many files.  The pattern
may be provided as a basic or extended regular expression, or as fixed
strings.  By default, the matching text is simply printed to the screen,
however the output can be greatly customized to include, for example, line
numbers.  GNU grep offers many extensions over the standard utility,
including, for example, recursive directory searching.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/grep/")))

(define-public sed
  (package
   (name "sed")
   (version "4.8")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/sed/sed-" version
                                ".tar.gz"))
            (sha256
             (base32
              "0alqagh0nliymz23kfjg6g9w3cr086k0sfni56gi8fhzqwa3xksk"))
            (patches (search-patches "coreutils-gnulib-tests.patch"))

            ;; Remove this snippet once upstream releases a fixed version.
            ;; This snippet changes Makefile.in, even though the upstream
            ;; patch changes testsuite/local.mk, since we build sed from a
            ;; release tarball.  See: https://bugs.gnu.org/36150
            (snippet
             '(begin
                (substitute* "Makefile.in"
                  (("^  abs_srcdir='\\$\\(abs_srcdir\\)'.*" previous-line)
                   (string-append
                    previous-line
                    "  CONFIG_HEADER='$(CONFIG_HEADER)'\t\t\\\n")))))
            (modules '((guix build utils)))))
   (build-system gnu-build-system)
   (synopsis "Stream editor")
   (native-inputs (list perl))                    ;for tests
   (description
    "Sed is a non-interactive, text stream editor.  It receives a text
input from a file or from standard input and it then applies a series of text
editing commands to the stream and prints its output to standard output.  It
is often used for substituting text patterns in a stream.  The GNU
implementation offers several extensions over the standard utility.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/sed/")))

(define-public tar
  (package
   (name "tar")
   (version "1.34")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/tar/tar-"
                                version ".tar.xz"))
            (sha256
             (base32
              "0a0x87anh9chbi2cgcyy7pmnm5hzk4yd1w2j8gm1wplwhwkbvgk3"))
            (patches (search-patches "tar-skip-unreliable-tests.patch"
                                     "tar-remove-wholesparse-check.patch"))))
   (build-system gnu-build-system)
   ;; Note: test suite requires ~1GiB of disk space.
   (arguments
    `(,@(cond
          ((target-hurd?)
           '(#:make-flags
             (list (string-append
                     "TESTSUITEFLAGS= -k '"
                     "!sparse"
                     ",!renamed dirs in incrementals"
                     ",!--exclude-tag option in incremental pass"
                     ",!incremental dumps with -C"
                     ",!incremental dumps of nested directories"
                     ",!incremental restores with -C"
                     ",!concatenated incremental archives (renames)"
                     ",!renamed directory containing subdirectories"
                     ",!renamed subdirectories"
                     ",!chained renames"
                     ",!Directory"
                     "'"))))
          ;; https://lists.gnu.org/archive/html/bug-tar/2021-10/msg00007.html
          ;; tar-1.34 isn't aware of 64-bit time_t and upstream suggests
          ;; skipping the test for this release on 32-bit systems.
          ((not (target-64bit?))
           '(#:make-flags (list "TESTSUITEFLAGS= -k '!tricky time stamps'")))
          (else '()))
      #:phases (modify-phases %standard-phases
                 (add-before 'build 'set-shell-file-name
                   (lambda* (#:key inputs #:allow-other-keys)
                     ;; Do not use "/bin/sh" to run programs.
                     (let ((bash (assoc-ref inputs "bash")))
                       (substitute* "src/system.c"
                         (("/bin/sh")
                          (string-append bash "/bin/sh")))))))))

   ;; When cross-compiling, the 'set-shell-file-name' phase needs to be able
   ;; to refer to the target Bash.
   (inputs (if (%current-target-system)
               (list bash)
               '()))

   (synopsis "Managing tar archives")
   (description
    "Tar provides the ability to create tar archives, as well as the
ability to extract, update or list files in an existing archive.  It is
useful for combining many files into one larger file, while maintaining
directory structure and file information such as permissions and
creation/modification dates.  GNU tar offers many extensions over the
standard utility.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/tar/")))

;;; TODO: Replace/merge with 'patch' on core-updates.
(define-public patch/pinned
  (hidden-package
   (package
     (name "patch")
     (version "2.7.6")
     (source (origin
               (method url-fetch)
               (uri (string-append "mirror://gnu/patch/patch-"
                                   version ".tar.xz"))
               (sha256
                (base32
                 "1zfqy4rdcy279vwn2z1kbv19dcfw25d2aqy9nzvdkq5bjzd0nqdc"))
               (patches (search-patches "patch-hurd-path-max.patch"))))
     (build-system gnu-build-system)
     (arguments
      ;; Work around a cross-compilation bug whereby libpatch.a would provide
      ;; '__mktime_internal', which conflicts with the one in libc.a.
      (if (%current-target-system)
          `(#:configure-flags '("gl_cv_func_working_mktime=yes"))
          '()))
     (native-inputs (list ed))
     (synopsis "Apply differences to originals, with optional backups")
     (description
      "Patch is a program that applies changes to files based on differences
laid out as by the program \"diff\".  The changes may be applied to one or more
files depending on the contents of the diff file.  It accepts several
different diff formats.  It may also be used to revert previously applied
differences.")
     (license gpl3+)
     (home-page "https://savannah.gnu.org/projects/patch/"))))

(define-public patch
  ;; The latest release is from 2018, and lacks multiple security related
  ;; patches.  Since Fedora carries 23 patches, simply use the latest commit
  ;; until a proper release is made.
  (let ((revision "0")
        (commit "f144b35425d9d7732ea5485034c1a6b7a106ab92")
        (base patch/pinned))
    (package
      (inherit base)
      (name "patch")
      (version (git-version "2.7.6" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://git.savannah.gnu.org/git/patch.git")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1bk38169c0xh01b0q0zmnrjqz8k9byz3arp4q7q66sn6xwf94nvz"))
                (patches (search-patches "patch-hurd-path-max.patch"))))
      (arguments
       (substitute-keyword-arguments (package-arguments base)
         ((#:phases phases '%standard-phases)
          #~(modify-phases #$phases
              (add-after 'unpack 'copy-gnulib-sources
                (lambda _
                  ;; XXX: We copy the source instead of using 'gnulib' as a
                  ;; native input to avoid introducing a dependency cycle.
                  (copy-recursively #+gnulib "gnulib")
                  (setenv "GNULIB_SRCDIR"
                          (string-append (getcwd) "/gnulib/src/gnulib"))))
              (add-after 'copy-gnulib-sources 'update-bootstrap-script
                (lambda _
                  (copy-file "gnulib/src/gnulib/build-aux/bootstrap"
                             "bootstrap")))
              (add-after 'unpack 'patch-configure.ac
                (lambda _
                  (substitute* "configure.ac"
                    ;; The gnulib-provided git-version-gen script has a plain
                    ;; shebang of #!/bin/sh; avoid using it.
                    (("build-aux/git-version-gen" all)
                     (string-append "sh " all)))))))))
      (native-inputs (list autoconf automake bison ed))
      (properties '()))))

(define-public diffutils
  (package
   (name "diffutils")
   (version "3.10")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/diffutils/diffutils-"
                                version ".tar.xz"))
            (sha256
             (base32
              "17nhkdn5a2z6pwcmjs4jas2plg066hbdz06y5vhypr14qwyfkrch"))))
   (build-system gnu-build-system)
   (arguments
    (list
     ;; XXX: On 32-bit Hurd platforms, 'time_t' is defined as a 32-bit
     ;; integer in 'hurd_types.defs', so this Gnulib test always fails.
     #:make-flags
     #~#$(if (and (not (%current-target-system))
                  (string=? (%current-system) "i586-gnu"))
             #~'("XFAIL_TESTS=test-year2038")
             #~'())

     #:phases (if (system-hurd?)
                  #~(modify-phases %standard-phases
                      (add-after 'unpack 'skip-tests
                        (lambda _
                          (substitute* "tests/large-subopt"
                            (("^#!.*" all)
                             (string-append all "exit 77;\n"))))))
                  #~%standard-phases)))
   (native-inputs (list perl))
   (synopsis "Comparing and merging files")
   (description
    "GNU Diffutils is a package containing tools for finding the
differences between files.  The \"diff\" command is used to show how two files
differ, while \"cmp\" shows the offsets and line numbers where they differ.
\"diff3\" allows you to compare three files.  Finally, \"sdiff\" offers an
interactive means to merge two files.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/diffutils/")))

(define-public findutils
  (package
   (name "findutils")
   (version "4.9.0")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/findutils/findutils-"
                                version ".tar.xz"))
            (sha256
             (base32
              "1zk2sighc26bfdsm97bv7cd1cnvq7r4gll4zqpnp0rs3kp0bigx2"))
            (patches (search-patches "findutils-localstatedir.patch"))))
   (build-system gnu-build-system)
   (arguments
    `(#:configure-flags (list
                         ;; Tell 'updatedb' to write to /var.
                         "--localstatedir=/var")
      #:phases (modify-phases %standard-phases
                 (add-before 'check 'adjust-test-shebangs
                   (lambda _
                     (substitute* '("tests/xargs/verbose-quote.sh"
                                    "tests/find/exec-plus-last-file.sh")
                       (("#!/bin/sh")
                        (string-append "#!" (which "sh"))))))
                 ,@(if (system-hurd?)
                       '((add-after 'unpack 'skip-tests
                           (lambda _
                             (substitute*
                                 ;; This test fails non-deterministically
                                 "gnulib-tests/test-strerror_r.c"
                               (("(^| )main *\\(.*" all)
                                (string-append all "{\n  exit (77);//"))))))
                       '()))))
   (synopsis "Operating on files matching given criteria")
   (description
    "Findutils supplies the basic file directory searching utilities of the
GNU system.  It consists of two primary searching utilities: \"find\"
recursively searches for files in a directory according to given criteria and
\"locate\" lists files in a database that match a query.  Two auxiliary tools
are included: \"updatedb\" updates the file name database and \"xargs\" may be
used to apply commands with arbitrarily long arguments.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/findutils/")))

(define-public coreutils
  (package
   (name "coreutils")
   (version "9.1")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/coreutils/coreutils-"
                                version ".tar.xz"))
            (sha256
             (base32
              "08q4b0w7mwfxbqjs712l6wrwl2ijs7k50kssgbryg9wbsw8g98b1"))))
   (build-system gnu-build-system)
   (inputs `(,acl                                 ;TODO: add SELinux
             ,attr                                ;for xattrs in ls, mv, etc
             ,gmp                                 ;bignums in 'expr', yay!

             ;; Do not use libcap when cross-compiling since it's not quite
             ;; cross-compilable; and use it only for supported systems.
             ,@(if (and (not (%current-target-system))
                        (member (%current-system)
                                (package-supported-systems libcap)))
                   `(,libcap)                ;capability support in 'ls', etc.
                   '())))
   (native-inputs
    ;; Perl is needed to run tests in native builds, and to run the bundled
    ;; copy of help2man.  However, don't pass it when cross-compiling since
    ;; that would lead it to try to run programs to get their '--help' output
    ;; for help2man.
    (if (%current-target-system)
        '()
        (list perl)))
   (outputs '("out" "debug"))
   (arguments
    `(#:parallel-build? #f            ; help2man may be called too early
      ,@(if (system-hurd?)
            '(#:make-flags            ; these tests fail deterministically
              (list (string-append "XFAIL_TESTS="
                                   ;; Gnulib tests.
                                   " test-fdutimensat"
                                   " test-futimens"
                                   " test-linkat"
                                   " test-renameat"
                                   " test-renameatu"
                                   " test-utimensat")))
            '())
      #:phases (modify-phases %standard-phases
                 (add-before 'build 'patch-shell-references
                   (lambda _
                     ;; 'split' uses either $SHELL or /bin/sh.  Set $SHELL so
                     ;; that tests pass, since /bin/sh isn't in the chroot.
                     (setenv "SHELL" (which "sh"))

                     (substitute* (find-files "gnulib-tests" "\\.c$")
                       (("/bin/sh") (which "sh")))
                     (substitute* (find-files "tests" "\\.sh$")
                       (("#!/bin/sh") (string-append "#!" (which "sh"))))))
                 (add-after 'unpack 'remove-tests
                   (lambda _
                     ,@(if (system-hurd?)
                           '((substitute*
                                 ;; These tests hang
                                 '("tests/cp/sparse-to-pipe.sh"
                                   "tests/split/fail.sh"
                                   ;; These tests error
                                   "tests/dd/nocache.sh"
                                   ;; These tests fail
                                   "tests/cp/sparse.sh"
                                   "tests/cp/special-f.sh"
                                   "tests/dd/bytes.sh"
                                   "tests/dd/stats.sh"
                                   "tests/ls/dangle.sh"
                                   "tests/ls/follow-slink.sh"
                                   "tests/ls/hyperlink.sh"
                                   "tests/ls/infloop.sh"
                                   "tests/ls/inode.sh"
                                   "tests/ls/selinux-segfault.sh"
                                   "tests/misc/env-S.pl"
                                   "tests/misc/factor-parallel.sh"
                                   "tests/misc/ls-misc.pl"
                                   "tests/misc/nice.sh"
                                   "tests/misc/pwd-long.sh"
                                   "tests/misc/shred-passes.sh"
                                   "tests/misc/stat-slash.sh"
                                   "tests/rm/fail-eperm.xpl"
                                   "tests/split/filter.sh")
                               (("^#!.*" all)
                                (string-append all "exit 77;\n")))
                             (substitute* "gnulib-tests/Makefile.in"
                               ;; This test sometimes fails and sometimes
                               ;; passes, but it does this consistently, so
                               ;; there might be some environmental factor
                               ;; here
                               ((" test-tls\\$\\(EXEEXT\\) ") " ")))
                           '())
                     (substitute* "Makefile.in"
                       ;; fails on filesystems where inotify cannot be used,
                       ;; more info in #47935
                       (("^ *tests/tail-2/inotify-dir-recreate.sh.*") "")))))))
   (synopsis "Core GNU utilities (file, text, shell)")
   (description
    "GNU Coreutils package includes all of the basic command-line tools that
are expected in a POSIX system, excluding shell.  This package is the union of
the GNU fileutils, sh-utils, and textutils packages.  Most of these tools
offer extended functionality beyond that which is outlined in the POSIX
standard.")
   (license gpl3+)
   (home-page "https://www.gnu.org/software/coreutils/")))

(define-public coreutils-minimal
  ;; Coreutils without its optional dependencies.
  (package
    (inherit coreutils)
    (name "coreutils-minimal")
    (outputs '("out"))
    (native-inputs '())
    (inputs '())))

(define-public coreutils-8.30
  ;; XXX: This version is kept just so we can run PRoot tests.
  (hidden-package
   (package
     (inherit coreutils-minimal)
     (version "8.30")
     (source (origin
               (method url-fetch)
               (uri (string-append "mirror://gnu/coreutils/coreutils-"
                                   version ".tar.xz"))
               (sha256
                (base32
                 "0mxhw43d4wpqmvg0l4znk1vm10fy92biyh90lzdnqjcic2lb6cg8"))))
     (arguments
      (substitute-keyword-arguments (package-arguments coreutils-minimal)
        ((#:phases phases '%standard-phases)
         `(modify-phases ,phases
            (add-before 'check 'disable-broken-test
              (lambda _
                ;; This test hits the 127 character shebang li