Subject: bug#47502: perl build commencment

From: "[email-masked]" <[email-masked]>
Date: Tue, 30 Mar 2021 16:52:36 +0000 (UTC)

I am trying to build a updated skeleton version of perl in a GUIX_PACKAGE-PATH folder, tweaking as necessary. I set up an inferior to add necessary packages. When I try to bulid the package,  i get this error
            :~/.config/guix/local$ guix build -f perl_barebones.scm -K
Updating channel 'guix' from Git repository at 'https://git.savannah.gnu.org/git/guix.git'...
gnu/packages/commencement.scm:2932:30: error: perl: unbound variable
hint: Did you forget `(use-modules (gnu packages perl))'?
 i Have tried to modify the perl_barebones file so that that doesn't happen but it Appears there isn't a way to make perl available to the commencement file to build the bootstrap perl to build perl. It appears there is a flaw in the commencement file. I tried updating guix, and checking with repl to see if it was something else. https://www.reddit.com/r/GUIX/comments/l5b1r9/guile_question_inheritance/
I've checked, r/GUIX the IRC and mailing list archives, so i'm pretty sure this a bug, or at least not a known issue. I apologize in advance if this a problem with what i did.
perl_barebone.scm full text:

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <[email-masked]>
;;; Copyright © 2013, 2019, 2020 Andreas Enge <[email-masked]>
;;; Copyright © 2015, 2016, 2017, 2019, 2021 Ricardo Wurmus <[email-masked]>
;;; Copyright © 2015, 2016, 2017, 2019, 2020 Eric Bavier <[email-masked]>
;;; Copyright © 2015 Eric Dvorsak <[email-masked]>
;;; Copyright © 2016, 2018 Mark H Weaver <[email-masked]>
;;; Copyright © 2016 Jochem Raat <[email-masked]>
;;; Copyright © 2016, 2017, 2018, 2019, 2020 Efraim Flashner <[email-masked]>
;;; Copyright © 2016 Nikita <[email-masked]>
;;; Copyright © 2016 Alex Sassmannshausen <[email-masked]>
;;; Copyright © 2016, 2018, 2020 Roel Janssen <[email-masked]>
;;; Copyright © 2016 Ben Woodcroft <[email-masked]>
;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
;;; Copyright © 2017 Raoul J.P. Bonnal <[email-masked]>
;;; Copyright © 2017, 2018 Marius Bakke <[email-masked]>
;;; Copyright © 2017 Adriano Peluso <[email-masked]>
;;; Copyright © 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice <[email-masked]>
;;; Copyright © 2017 Leo Famulari <[email-masked]>
;;; Copyright © 2017 Christopher Allan Webber <[email-masked]>
;;; Copyright © 2018, 2019 Oleg Pykhalov <[email-masked]>
;;; Copyright © 2018, 2019 Pierre Neidhardt <[email-masked]>
;;; Copyright © 2018 Kei Kebreau <[email-masked]>
;;; Copyright © 2019 Alex Griffin <[email-masked]>
;;; Copyright © 2019 Mathieu Othacehe <[email-masked]>
;;; Copyright © 2019 Stephen J. Scheck <[email-masked]>
;;; Copyright © 2020 Vincent Legoll <[email-masked]>
;;; Copyright © 2020 Paul Garlick <[email-masked]>
;;; Copyright © 2020 Nicolas Goaziou <[email-masked]>
;;; Copyright © 2020 Malte Frank Gerdes <[email-masked]>
;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
;;;
;;; 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/>.
;;; Test version to have updated package refrences

(define-module (gnu packages perl)
  #:use-module (guix inferior)
  #:use-module (guix channels)
  #:use-module (gnu packages package-management)
  ;; #:use-module (gnu packages perl)
  #:use-module (srfi srfi-1)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system perl)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages gd)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages hurd)
  #:use-module (gnu packages image)
  #:use-module (gnu packages less)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages perl-check)
  #:use-module (gnu packages perl-compression)
  #:use-module (gnu packages perl-web)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages textutils)
  #:use-module (gnu packages video)
  #:use-module (gnu packages web)
  #:use-module (gnu packages xorg))

;;;
;;; Please: Try to add new module packages in alphabetic order.
;;;

;;; In order to make this work outside of the primary channel We need to create a inferior for the channel packages we need.
;;; First we need to define the channel(s)

(define channels
    (list (channel 
        (name `guix)
        (url "https://git.savannah.gnu.org/git/guix.git")
        (commit "414fc58cef4eb9c2cc18a381629d17c5adf76210")
    )))
(use-modules (gnu packages perl))

(define inferior 
    (inferior-for-channels channels)
)
(packages->manifest
    (list (first (lookup-inferior-packages inferior "perl")
    (lookup-inferior-packages inferior "readline")
    (lookup-inferior-packages inferior "bash")
    ))
)

(define-public perl
  ;; Yeah, Perl...  It is required early in the bootstrap process by Linux.
  (package
    (name "perl")
    (version "5.32.1")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://cpan/src/5.0/perl-"
                                 version ".tar.gz"))
             (sha256
              (base32
               "0b7brakq9xs4vavhg391as50nbhzryc7fy5i65r81bnq3j897dh3"))
             (patches (search-patches
                       "perl-no-sys-dirs.patch"
                       "perl-autosplit-default-time.patch"
                       "perl-deterministic-ordering.patch"
                       "perl-reproducible-build-date.patch"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f
       #:configure-flags
       (let ((out  (assoc-ref %outputs "out"))
             (libc (assoc-ref %build-inputs "libc")))
         (list
          (string-append "-Dprefix=" out)
          (string-append "-Dman1dir=" out "/share/man/man1")
          (string-append "-Dman3dir=" out "/share/man/man3")
          "-de" "-Dcc=gcc"
          "-Uinstallusrbinperl"
          "-Dinstallstyle=lib/perl5"
          "-Duseshrplib"
          (string-append "-Dlocincpth=" libc "/include")
          (string-append "-Dloclibpth=" libc "/lib")
          "-Dusethreads"))
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'setup-configure
           (lambda _
             ;; Use the right path for `pwd'.
             ;; TODO: use coreutils from INPUTS instead of 'which'
             ;; in next rebuild cycle, see fixup below.
             (substitute* "dist/PathTools/Cwd.pm"
               (("/bin/pwd")
                (which "pwd")))

             ;; Build in GNU89 mode to tolerate C++-style comment in libc's
             ;; <bits/string3.h>.
             (substitute* "cflags.SH"
               (("-std=c89")
                "-std=gnu89"))
             #t))
         ,@(if (%current-target-system)
               `((add-after 'unpack 'unpack-cross
                   (lambda* (#:key native-inputs inputs #:allow-other-keys)
                     (let ((cross-checkout
                            (assoc-ref native-inputs "perl-cross"))
                           (cross-patch
                            (assoc-ref native-inputs "perl-cross-patch")))
                       (rename-file "Artistic" "Artistic.perl")
                       (rename-file "Copying" "Copying.perl")
                       (copy-recursively cross-checkout ".")
                       (format #t "Applying ~a\n" cross-patch)
                       (invoke "patch" "-p1" "-i" cross-patch))
                     (let ((bash (assoc-ref inputs "bash")))
                       (substitute* '("Makefile.config.SH"
                                      "cnf/config.guess"
                                      "cnf/config.sub"
                                      "cnf/configure"
                                      "cnf/configure_misc.sh"
                                      "miniperl_top")
                         (("! */bin/sh") (string-append "! " bash "/bin/bash"))
                         ((" /bin/sh") (string-append bash "/bin/bash")))
                       (substitute* '("ext/Errno/Errno_pm.PL")
                         (("\\$cpp < errno.c") "$Config{cc} -E errno.c")))
                       #t))
                 (replace 'configure
                   (lambda* (#:key configure-flags outputs inputs #:allow-other-keys)
                     (let* ((out (assoc-ref outputs "out"))
                            (store-directory (%store-directory))
                            (configure-flags
                             (cons*
                              ;; `perl-cross' confuses target and host
                              (string-append "--target=" ,(%current-target-system))
                              (string-append "--prefix=" out)
                              (string-append "-Dcc=" ,(%current-target-system) "-gcc")
                              "-Dbyteorder=1234"
                              (filter (negate
                                       (lambda (x) (or (string-prefix? "-d" x)
                                                       (string-prefix? "-Dcc=" x))))
                                      configure-flags)))
                            (bash (assoc-ref inputs "bash"))
                            (coreutils (assoc-ref inputs "coreutils")))
                       (format (current-error-port)
                               "running ./configure ~a\n" (string-join configure-flags))
                       (apply invoke (cons "./configure" configure-flags))
                       (substitute* "config.sh"
                         (((string-append store-directory "/[^/]*-bash-[^/]*"))
                          bash))
                       (substitute* '("config.h")
                         (("^#define SH_PATH .*")
                          (string-append  "#define SH_PATH \"" bash "/bin/bash\"\n")))
                       ;;TODO: fix this in setup-configure next rebuild cycle
                       (substitute* "dist/PathTools/Cwd.pm"
                         (((string-append store-directory "/[^/]*-coreutils-[^/]*"))
                          coreutils))
                       #t)))
                 (add-after 'build 'touch-non-built-files-for-install
                   (lambda _
                     ;; `make install' wants to install these although they do
                     ;; not get built...
                     (with-directory-excursion "cpan"
                       (mkdir-p "Pod-Usage/blib/script")
                       (mkdir-p "Pod-Parser/blib/script")
                       (for-each (lambda (file)
                                   (call-with-output-file file
                                     (lambda (port) (display "" port))))
                                 '("Pod-Usage/blib/script/pod2text"
                                   "Pod-Usage/blib/script/pod2usage"
                                   "Pod-Checker/blib/script/podchecker"
                                   "Pod-Parser/blib/script/podselect")))
                     #t)))
               `((replace 'configure
                   (lambda* (#:key configure-flags #:allow-other-keys)
                     (format #t "Perl configure flags: ~s~%" configure-flags)
                     (apply invoke "./Configure" configure-flags)))))
         (add-after 'install 'remove-extra-references
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let* ((out     (assoc-ref outputs "out"))
                    (libc    (assoc-ref inputs
                                        ,(if (%current-target-system)
                                             "cross-libc" "libc")))
                    (config1 (car (find-files (string-append out "/lib/perl5")
                                              "^Config_heavy\\.pl$")))
                    (config2 (find-files (string-append out "/lib/perl5")
                                         "^Config\\.pm$")))
               ;; Force the library search path to contain only libc because
               ;; it is recorded in Config.pm and Config_heavy.pl; we don't
               ;; want to keep a reference to everything that's in
               ;; $LIBRARY_PATH at build time (GCC, Binutils, bzip2, file,
               ;; etc.)
               (substitute* config1
                 (("^incpth=.*$")
                  (string-append "incpth='" libc "/include'\n"))
                 (("^(libpth|plibpth|libspath)=.*$" _ variable)
                  (string-append variable "='" libc "/lib'\n")))

               (for-each (lambda (file)
                           (substitute* config2
                             (("libpth => .*$")
                              (string-append "libpth => '" libc
                                             "/lib',\n"))))
                         config2)
               #t))))))
    (inputs
     (if (%current-target-system)
         `(("bash" ,bash-minimal)
           ("coreutils" ,coreutils))
         '()))
    (native-inputs
     (if (%current-target-system)
         `(("perl-cross"
            ,(origin
               (method git-fetch)
               (uri (git-reference
                     (url "https://github.com/arsv/perl-cross")
                     (commit "1.3.5")))
               (file-name (git-file-name "perl-cross" "1.3.5"))
               (sha256
                (base32 "09ggs8m8qya92klmjqs5z6c0q2rqfyv60ip1zvaczz4r5dmnzili"))))
           ("perl-cross-patch" ,@(search-patches "perl-cross.patch")))
         '()))
    (native-search-paths (list (search-path-specification
                                (variable "PERL5LIB")
                                (files '("lib/perl5/site_perl")))))
    (synopsis "Implementation of the Perl programming language")
    (description
     "Perl is a general-purpose programming language originally developed for
text manipulation and now used for a wide range of tasks including system
administration, web development, network programming, GUI development, and
more.")
    (home-page "https://www.perl.org/")
    (license license:gpl1+)))                          ; or "Artistic"
(define-public perl-ipc-system-simple
  (package
    (name "perl-ipc-system-simple")
    (version "1.30")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "mirror://cpan/authors/id/J/JK/JKEENAN/IPC-System-Simple-"
                    version ".tar.gz"))
              (sha256
               (base32
                "17msx650m9r3m6j5r3mr742vism1nxda7p4g0l9yapjh5cigbri2"))))
    (build-system perl-build-system)
    (home-page "https://metacpan.org/release/IPC-System-Simple")
    (synopsis "Run commands simply, with detailed diagnostics")
    (description "Calling Perl's in-built @code{system} function is easy,
determining if it was successful is hard.  Let's face it, @code{$?} isn't the
nicest variable in the world to play with, and even if you do check it,
producing a well-formatted error string takes a lot of work.

@code{IPC::System::Simple} takes the hard work out of calling external
commands.")
    (license (package-license perl))))
perl
perl-ipc-system-simple