Subject: Incorrect handling of -L flag on guix system commands

From: Sergio Pastor Pérez <[email-masked]>
Date: Mon, 09 Oct 2023 12:16:50 +0200

Good morning.

I've noticed that in system configurations split into different modules,
when using the -L flag, the `guix system build` command incorrectly
issues some errors. The error is ignored and the system is built
successfully.

For example, given a base system and 2 systems that inherit from it, the
error appears when building any of them:
--8<---------------cut here---------------start------------->8---
λ ls
base-system.scm  bordercollie.scm  sheepbook.scm
--8<---------------cut here---------------end--------------->8---

base-system.scm:
--8<---------------cut here---------------start------------->8---
(define-module (base-system)
  #:use-module (gnu))
...
(define-public %base-system
  (operating-system
   ...))
--8<---------------cut here---------------end--------------->8---

bordercollie.scm:
--8<---------------cut here---------------start------------->8---
(define-module (bordercollie)
  #:use-module (base-system)
  ...)
(operating-system
  (inherit %base-system)
  ...)
--8<---------------cut here---------------end--------------->8---

sheepbook.scm:
--8<---------------cut here---------------start------------->8---
(define-module (sheepbook)
  #:use-module (base-system)
  ...)
(operating-system
  (inherit %base-system)
  ...)
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
λ guix system build -L . bordercollie.scm 
error: %useful-gnome-extensions: unbound variable
hint: Did you forget `(use-modules (base-system))'?

/gnu/store/gf21yc9ii1cfd3ki9hnn8ac5d65923ir-system
--8<---------------cut here---------------end--------------->8---

As you can see this command has built successfully. Note that in this
particular case the error says that the unbound variable is
`%useful-gnome-extensions'. It will complain always about the first
think it encounters.

On the other hand relying on the `GUILE_LOAD_PATH', instead of using the
'-L' flag, removes the error:
--8<---------------cut here---------------start------------->8---
λ GUILE_LOAD_PATH=$(pwd):$GUILE_LOAD_PATH guix system build bordercollie.scm
/gnu/store/gf21yc9ii1cfd3ki9hnn8ac5d65923ir-system
--8<---------------cut here---------------end--------------->8---

I've noticed that for the error to appear, there has to be 2 systems
inheriting from the `base-system` module. If I remove `bordercollie.scm`
or `sheepbook.scm`, the other will build without issuing the error.

Regards,
Sergio.