Subject: Importing a toolchain packages causes top-level dependency cycles

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 03 Sep 2023 10:39:22 -0400

Hello,

Attempting to add a new (gnu packages ergodox) module, it fails with the
following error:

--8<---------------cut here---------------start------------->8---
[ 11%] LOAD     guix/store/deduplication.scm
[ 11%] LOAD     guix/store/roots.scm
[ 11%] LOAD     guix/config.scm
[ 11%] LOAD     guix/tests.scm
ice-9/eval.scm:293:34: error: cross-gcc: unbound variable
hint: Did you forget `(use-modules (gnu packages cross-base))'?

make[2]: *** [Makefile:6997: make-core-go] Error 1
make[2]: Leaving directory '/home/maxim/src/guix'
make[1]: *** [Makefile:6083: all-recursive] Error 1
make[1]: Leaving directory '/home/maxim/src/guix'
make: *** [Makefile:4197: all] Error 2
--8<---------------cut here---------------end--------------->8---

Which looks like a circular dependency problem at the top level.  Here's
the content of gnu/packages/ergodox.scm:

--8<---------------cut here---------------start------------->8---
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 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/>.

(define-module (gnu packages ergodox)
  #:use-module (gnu packages avr)
  #:use-module (guix build-system gnu)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages))

(define (make-ergodox-firmware layout)
  (let ((revision "0")
        (commit "89b7e2bfdafb2a87e0248846d5c95cc5e9a27858"))
    (package
      (name (string-append "ergodox-firmware-" layout))
      (version (git-version "1" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/benblazak/ergodox-firmware")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1gy2332kdqk8bjzpcsripx10896rbvgl0ic7r344kmpiwdgm9480"))))
      (build-system gnu-build-system)
      (arguments
       (list #:make-flags #~(list (string-append "LAYOUT=" layout))
             #:phases #~(modify-phases %standard-phases
                          (add-after 'unpack 'chdir
                            (lambda _
                              (chdir "src")))
                          ;; The Makefile-based build system lacks configure
                          ;; and install targets.
                          (delete 'configure)
                          (replace 'install
                            (lambda _
                              (install-file "firmware.hex" #$output)
                              (install-file "firmware.eep" #$output))))))
      (native-inputs (list avr-toolchain))
      (home-page "http://www.ergodox.io")
      (synopsis "Firmware for the ErgoDox keyboard")
      (description (format #f "This package contains the original firmware for
the ErgoDox keyboard, built using the ~a firmware.  It contains two files: the
@file{firmware.hex} and the @file{firmware.eep} files, which can be loaded to
a target using the @code{teensy-loader-cli} package." layout))
      (license license:expat))))

(define-public ergodox-firmware-colemak-jc-mod
  (make-ergodox-firmware "colemak-jc-mod"))

(define-public ergodox-firmware-colemak-symbol-mod
  (make-ergodox-firmware "colemak-symbol-mod"))

(define-public ergodox-firmware-dvorak-kinesis-mod
  (make-ergodox-firmware "dvorak-kinesis-mod"))

(define-public ergodox-firmware-qwerty-kinesis-mod
  (make-ergodox-firmware "qwerty-kinesis-mod"))

(define-public ergodox-firmware-workman-p-kinesis-mod
  (make-ergodox-firmware "workman-p-kinesis-mod"))
--8<---------------cut here---------------end--------------->8---

Commenting out the '(native-inputs (list avr-toolchain))' line resolves
the problem, but obviously breaks the package, which requires avr-gcc
and friends.

Another similar report was made in
<https://lists.gnu.org/archive/html/help-guix/2023-01/msg00013.html>.

-- 
Thanks,
Maxim