Subject: Re: bug#40272: linux-module-build-system don't support an inferior package as a kernel

From: Brice Waegeneire <[email-masked]>
Date: Sun, 01 Aug 2021 22:59:01 +0200

Hello Ludo’,

Ludovic Courtès <[email-masked]> writes:

> [...]
> In this case, the problem is that (@ (guix build-system linux-module)
> lower) assumes that ‘linux’ is a <package>:
>
>     (build-inputs `(,@(if source
>                           `(("source" ,source))
>                           '())
>                     ,@native-inputs
>                     ;; TODO: Remove "gmp", "mpfr", "mpc" since they are
>                     ;; only needed to compile the gcc plugins.  Maybe
>                     ;; remove "flex", "bison", "elfutils", "perl",
>                     ;; "openssl".  That leaves very little ("bc", "gcc",
>                     ;; "kmod").
>                     ,@(package-native-inputs linux)   ;<----- HERE
>
> I suppose you could add a special-case for (inferior-package? linux).
> Not pretty, but it’d do the job.

As I said on IRC, I had already tried that without success.  I did the
following change:

--8<---------------cut here---------------start------------->8---
diff --git a/guix/build-system/linux-module.scm b/guix/build-system/linux-module.scm
index fc3d959ce7..c30cac90f9 100644
--- a/guix/build-system/linux-module.scm
+++ b/guix/build-system/linux-module.scm
@@ -21,6 +21,7 @@
   #:use-module (guix store)
   #:use-module (guix utils)
   #:use-module (guix derivations)
+  #:use-module (guix inferior)
   #:use-module (guix search-paths)
   #:use-module (guix build-system)
   #:use-module (guix build-system gnu)
@@ -129,7 +130,10 @@
                     ;; remove "flex", "bison", "elfutils", "perl",
                     ;; "openssl".  That leaves very little ("bc", "gcc",
                     ;; "kmod").
-                    ,@(package-native-inputs linux)
+                    ;; ,@(package-native-inputs linux)
+                    ,@(if (inferior-package? linux)
+                          (inferior-package-native-inputs linux)
+                          (package-native-inputs linux))
                     ,@if target
                           ;; Use the standard cross inputs of
                           ;; 'gnu-build-system'.
--8<---------------cut here---------------end--------------->8---

Which produced this backtrace, which seems to indicate an issue in the
'package->bag' procedure:

--8<---------------cut here---------------start------------->8---
$ COLUMNS=999 ./pre-inst-env  guix build -f ./40272.scm
Backtrace:
In srfi/srfi-1.scm:
   673:15 19 (append-map #<procedure 7f8aebf46440 at guix/scripts/build.scm:608:17 (system)> ("x86_64-linux"))
   586:17 18 (map1 ("x86_64-linux"))
In guix/scripts/build.scm:
   610:20 17 (_ _)
In guix/store.scm:
   1362:4 16 (map/accumulate-builds #<store-connection 256.99 7f8afec1beb0> _ _)
In srfi/srfi-1.scm:
   586:17 15 (map1 (#<package [email-masked] /home/bricewge/project/guix-config/40272.scm:21 7f8aef33aa00>))
In guix/store.scm:
   1320:8 14 (call-with-build-handler #<procedure build-accumulator (continue store things mode)> _)
In guix/scripts/build.scm:
   569:18 13 (_ _)
In guix/packages.scm:
  1177:16 12 (package-derivation _ #<package [email-masked] /home/bricewge/project/guix-config/40272.scm:21 7f8aef33aa00> _ #:graft? _)
  1494:22 11 (thunk)
  1177:16 10 (package->bag _ _ _ #:graft? _)
  1279:21  9 (thunk)
In ice-9/eval.scm:
   293:34  8 (_ #(#(#(#(#(#(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) "ddcci-driver-linux-0.3.3" (#:system "x86_64-linux" #:source #<origin #<<git-reference> url: "https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux.git" commit: "v0.3.3" recursive?: #f> #<content-hash sha256:0vkkja3ykjil783zjpwp0vz7jy2fp9ccazzi3afd4fjk8gldin7f> () 7f8aef024060> #:inputs () #:native-inputs () #:outputs ("out") #:target #f #:tests? #f #:phases (modify-phases %standard-phases (replace (quote build) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote build)) args))) (quote ("ddcci" "ddcci-backlight"))) #t)) (replace (quote install) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote install)) args))) (quote ("ddcci" "ddcci-backlight"))) #t))) #:linux #<inferior-package [email-masked] 7f8aed887420>) #<origin #<<git-reference> url: …> …) …) …) …) …) …))
    159:9  7 (_ #(#(#(#(#(#(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) "ddcci-driver-linux-0.3.3" (#:system "x86_64-linux" #:source #<origin #<<git-reference> url: "https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux.git" commit: "v0.3.3" recursive?: #f> #<content-hash sha256:0vkkja3ykjil783zjpwp0vz7jy2fp9ccazzi3afd4fjk8gldin7f> () 7f8aef024060> #:inputs () #:native-inputs () #:outputs ("out") #:target #f #:tests? #f #:phases (modify-phases %standard-phases (replace (quote build) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote build)) args))) (quote ("ddcci" "ddcci-backlight"))) #t)) (replace (quote install) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote install)) args))) (quote ("ddcci" "ddcci-backlight"))) #t))) #:linux #<inferior-package [email-masked] 7f8aed887420>) #<origin #<<git-reference> url: …> …) …) …) …) …) …))
    159:9  6 (_ #(#(#(#(#(#(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) "ddcci-driver-linux-0.3.3" (#:system "x86_64-linux" #:source #<origin #<<git-reference> url: "https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux.git" commit: "v0.3.3" recursive?: #f> #<content-hash sha256:0vkkja3ykjil783zjpwp0vz7jy2fp9ccazzi3afd4fjk8gldin7f> () 7f8aef024060> #:inputs () #:native-inputs () #:outputs ("out") #:target #f #:tests? #f #:phases (modify-phases %standard-phases (replace (quote build) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote build)) args))) (quote ("ddcci" "ddcci-backlight"))) #t)) (replace (quote install) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote install)) args))) (quote ("ddcci" "ddcci-backlight"))) #t))) #:linux #<inferior-package [email-masked] 7f8aed887420>) #<origin #<<git-reference> url: …> …) …) …) …) …) …))
    159:9  5 (_ #(#(#(#(#(#(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) "ddcci-driver-linux-0.3.3" (#:system "x86_64-linux" #:source #<origin #<<git-reference> url: "https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux.git" commit: "v0.3.3" recursive?: #f> #<content-hash sha256:0vkkja3ykjil783zjpwp0vz7jy2fp9ccazzi3afd4fjk8gldin7f> () 7f8aef024060> #:inputs () #:native-inputs () #:outputs ("out") #:target #f #:tests? #f #:phases (modify-phases %standard-phases (replace (quote build) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote build)) args))) (quote ("ddcci" "ddcci-backlight"))) #t)) (replace (quote install) (lambda args (for-each (lambda (module) (with-directory-excursion module (apply (assoc-ref %standard-phases (quote install)) args))) (quote ("ddcci" "ddcci-backlight"))) #t))) #:linux #<inferior-package [email-masked] 7f8aed887420>) #<origin #<<git-reference> url: …> …) …) …) …) …) …))
   293:34  4 (_ #(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) #<inferior-package [email-masked] 7f8aed887420>))
    159:9  3 (_ #(#(#<directory (guix build-system linux-module) 7f8af0d1ef00>) #<inferior-package [email-masked] 7f8aed887420>))
In ice-9/boot-9.scm:
  1685:16  2 (raise-exception _ #:continuable? _)
  1685:16  1 (raise-exception _ #:continuable? _)
  1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure package-name: Wrong type argument: #<inferior-package [email-masked] 7f8aed887420>
--8<---------------cut here---------------end--------------->8---

> If we want to go further, we’ll have to end up with GOOPS…
> [...]

Building a parent class of <package> and <inferior-package> looks really
involved to just fix this issue.  Is there another way, or are we forced to
use GOOPS in that case?

Cheers,
- Brice