GNU bug report logs - #35110
[PATCH 0/3] Add support for loadable modules.

Previous Next

Package: guix-patches;

Reported by: Danny Milosavljevic <dannym <at> scratchpost.org>

Date: Tue, 2 Apr 2019 19:28:01 UTC

Severity: normal

Tags: patch

Done: Danny Milosavljevic <dannym <at> scratchpost.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35110 in the body.
You can then email your comments to 35110 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 19:28:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Danny Milosavljevic <dannym <at> scratchpost.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 02 Apr 2019 19:28:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: guix-patches <at> gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH 0/3] Add support for loadable modules.
Date: Tue,  2 Apr 2019 21:27:29 +0200
Danny Milosavljevic (2):
  gnu: Add make-linux-module.
  gnu: linux-libre: Disable module versioning.

Pierre Neidhardt (1):
  gnu: Add vhba-module-linux-libre.

 .../aux-files/linux-libre/5.0-x86_64.conf     |  2 +-
 gnu/packages/linux.scm                        | 94 +++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)





Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 19:30:03 GMT) Full text and rfc822 format available.

Message #8 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH 1/3] gnu: Add make-linux-module.
Date: Tue,  2 Apr 2019 21:28:53 +0200
* gnu/packages/linux.scm (make-linux-module): New procedure.
---
 gnu/packages/linux.scm | 66 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 9e4261eb02..55a314258f 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -415,6 +415,72 @@ for ARCH and optionally VARIANT, or #f if there is no such configuration."
 It has been modified to remove all non-free binary blobs.")
     (license license:gpl2)))
 
+;; FIXME: Remove CONFIG_MODULE_SRCVERSION_ALL=y from our configs.
+(define (make-linux-module linux module)
+  "Given a LINUX package and a MODULE package, build MODULE using LINUX."
+  (let ((linux-source
+         (package
+           (inherit linux)
+           (name "linux-source")
+           (arguments
+             (substitute-keyword-arguments (package-arguments linux)
+              ((#:phases phases)
+               `(modify-phases ,phases
+                  (replace 'build
+                    (lambda _
+                      (invoke "make" "modules_prepare")))
+                  (delete 'strip) ; faster.
+                  (replace 'install
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      (let* ((out (assoc-ref outputs "out"))
+                             (out-lib-build (string-append out "/lib/modules/build")))
+                        ; TODO: Only preserve the minimum, i.e. [Kbuild], Kconfig, scripts, include, ".config".
+                        (copy-recursively "." out-lib-build)
+                        #t))))))))))
+    (package
+      (inherit module)
+      (name (string-append (package-name module) "-" (package-name linux)))
+      (native-inputs
+       `(("linux-source" ,linux-source)
+         ("kmod" ,kmod)
+         ;("elfutils" ,elfutils)  ; Needed to enable CONFIG_STACK_VALIDATION
+         ("gcc" ,gcc-7)
+         ,@(package-native-inputs module)))
+      (arguments
+        (substitute-keyword-arguments
+         (default-keyword-arguments (package-arguments module)
+          `(#:phases #f
+            #:make-flags '()))
+         ((#:phases phases)
+          `(modify-phases ,phases
+             (replace 'build
+               (lambda* (#:key inputs make-flags #:allow-other-keys)
+                 (apply invoke "make" "-C"
+                        (string-append (assoc-ref inputs "linux-source")
+                                       "/lib/modules/build")
+                        (string-append "M=" (getcwd))
+                        make-flags)))
+         ;; This block was copied from make-linux-libre--only took the
+         ;; "modules_install" part.
+         (replace 'install
+           (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
+             (let* ((out    (assoc-ref outputs "out"))
+                    (moddir (string-append out "/lib/modules"))
+                    (kmod   (assoc-ref (or native-inputs inputs) "kmod")))
+               ;; Install kernel modules
+               (mkdir-p moddir)
+               (invoke "make"
+                       "-C"
+                       (string-append (assoc-ref inputs "linux-source")
+                                      "/lib/modules/build")
+                       (string-append "M=" (getcwd))
+                       (string-append "DEPMOD=" kmod "/bin/depmod")
+                       (string-append "MODULE_DIR=" moddir)
+                       (string-append "INSTALL_PATH=" out)
+                       (string-append "INSTALL_MOD_PATH=" out)
+                       "INSTALL_MOD_STRIP=1"
+                       "modules_install")))))))))))
+
 (define %linux-libre-version "5.0.5")
 (define %linux-libre-hash "1yivxqprxfzhzid4qv9hpnb5i38kijrj2g2pyzz7niliya1c58li")
 




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 19:30:04 GMT) Full text and rfc822 format available.

Message #11 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>,
 Pierre Neidhardt <mail <at> ambrevar.xyz>
Subject: [PATCH 2/3] gnu: Add vhba-module-linux-libre.
Date: Tue,  2 Apr 2019 21:28:54 +0200
From: Pierre Neidhardt <mail <at> ambrevar.xyz>

* gnu/packages/linux.scm (vhba-module): New variable.
(vhba-module-linux-libre): New variable.  Export it.

Signed-off-by: Danny Milosavljevic <dannym <at> scratchpost.org>
---
 gnu/packages/linux.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 55a314258f..a2adb9b13d 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -495,6 +495,34 @@ It has been modified to remove all non-free binary blobs.")
                     #:patches %linux-libre-5.0-patches
                     #:configuration-file kernel-config))
 
+(define vhba-module
+  (package
+    (name "vhba-module")
+    (version "20170610")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "http://downloads.sourceforge.net/cdemu/vhba-module-"
+                    version ".tar.bz2"))
+              (sha256
+               (base32
+                "1v6r0bgx0a65vlh36b1l2965xybngbpga6rp54k4z74xk0zwjw3r"))))
+    (build-system gnu-build-system)
+    (arguments
+     ;; TODO: No tests?
+     `(#:tests? #f
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'configure))))
+    (home-page "https://cdemu.sourceforge.io/")
+    (synopsis "Kernel module that emulates SCSI devices")
+    (description "VHBA module provides a Virtual (SCSI) HBA, which is the link
+between the CDemu userspace daemon and linux kernel.")
+    (license license:gpl2+)))
+
+(define-public vhba-module-linux-libre
+  (make-linux-module linux-libre vhba-module))
+
 (define %linux-libre-4.19-version "4.19.32")
 (define %linux-libre-4.19-hash "19bryl8nmnnnrfh91pc8q9yiayh5ca2nb6b32qyx6riahc5dy0i9")
 




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 19:30:04 GMT) Full text and rfc822 format available.

Message #14 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH 3/3] gnu: linux-libre: Disable module versioning.
Date: Tue,  2 Apr 2019 21:28:55 +0200
* gnu/packages/aux-files/linux-libre/5.0-x86_64.conf: Remove
CONFIG_MODULE_SRCVERSION_ALL.
---
 gnu/packages/aux-files/linux-libre/5.0-x86_64.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnu/packages/aux-files/linux-libre/5.0-x86_64.conf b/gnu/packages/aux-files/linux-libre/5.0-x86_64.conf
index 9e1a7eff0e..193413110f 100644
--- a/gnu/packages/aux-files/linux-libre/5.0-x86_64.conf
+++ b/gnu/packages/aux-files/linux-libre/5.0-x86_64.conf
@@ -794,7 +794,7 @@ CONFIG_MODULES=y
 CONFIG_MODULE_UNLOAD=y
 # CONFIG_MODULE_FORCE_UNLOAD is not set
 CONFIG_MODVERSIONS=y
-CONFIG_MODULE_SRCVERSION_ALL=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
 # CONFIG_MODULE_SIG is not set
 # CONFIG_MODULE_COMPRESS is not set
 CONFIG_MODULES_TREE_LOOKUP=y




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 21:52:01 GMT) Full text and rfc822 format available.

Message #17 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Pierre Neidhardt <mail <at> ambrevar.xyz>
To: Danny Milosavljevic <dannym <at> scratchpost.org>, 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: Re: [PATCH 2/3] gnu: Add vhba-module-linux-libre.
Date: Tue, 02 Apr 2019 23:51:20 +0200
[Message part 1 (text/plain, inline)]
Thanks for looking into this!

Danny Milosavljevic <dannym <at> scratchpost.org> writes:

> +(define-public vhba-module-linux-libre
> +  (make-linux-module linux-libre vhba-module))

What is make-linux-module?  I cannot find it on master :p

-- 
Pierre Neidhardt
https://ambrevar.xyz/
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Tue, 02 Apr 2019 22:37:01 GMT) Full text and rfc822 format available.

Message #20 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: Pierre Neidhardt <mail <at> ambrevar.xyz>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [PATCH 2/3] gnu: Add vhba-module-linux-libre.
Date: Wed, 3 Apr 2019 00:36:06 +0200
[Message part 1 (text/plain, inline)]
See PATCH 1/3, Message ID <20190402192855.5314-1-dannym <at> scratchpost.org>
[Message part 2 (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Wed, 03 Apr 2019 06:50:02 GMT) Full text and rfc822 format available.

Message #23 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Pierre Neidhardt <mail <at> ambrevar.xyz>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [PATCH 2/3] gnu: Add vhba-module-linux-libre.
Date: Wed, 03 Apr 2019 08:48:56 +0200
[Message part 1 (text/plain, inline)]
Brilliant!  Thank you so much for this!

-- 
Pierre Neidhardt
https://ambrevar.xyz/
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Wed, 03 Apr 2019 20:17:02 GMT) Full text and rfc822 format available.

Message #26 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH 1/3] gnu: Add make-linux-module.
Date: Wed, 03 Apr 2019 22:16:07 +0200
Hi Danny,

Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> * gnu/packages/linux.scm (make-linux-module): New procedure.

Neat!

Would it make sense to turn it into a ‘linux-module-build-system’?  That
would avoid having to create a package object that cannot be built, just
to pass it to ‘make-linux-module’.  ‘linux-libre’ and ‘kmod’ would be
implicit inputs.

> +;; FIXME: Remove CONFIG_MODULE_SRCVERSION_ALL=y from our configs.

What does that flag do?

> +      (name (string-append (package-name module) "-" (package-name linux)))
> +      (native-inputs
> +       `(("linux-source" ,linux-source)
> +         ("kmod" ,kmod)
> +         ;("elfutils" ,elfutils)  ; Needed to enable CONFIG_STACK_VALIDATION
> +         ("gcc" ,gcc-7)

Is it OK to use the default GCC?

Other than that it looks really cool!

Thank you,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Wed, 03 Apr 2019 20:49:01 GMT) Full text and rfc822 format available.

Message #29 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH 1/3] gnu: Add make-linux-module.
Date: Wed, 3 Apr 2019 22:48:23 +0200
[Message part 1 (text/plain, inline)]
Hi Ludo,

On Wed, 03 Apr 2019 22:16:07 +0200
Ludovic Courtès <ludo <at> gnu.org> wrote:

> Would it make sense to turn it into a ‘linux-module-build-system’?  

I started on it but haven't finished it yet.

>That would avoid having to create a package object that cannot be built, just

It can be built, it's just not very useful standalone because it only contains
the source code and a few build artifacts (only the ones required to start
building a module).  On the other hand it can be substituted and that's nice
(if we can cut down the source code a lot, that is).

I don't understand how a build system would enable us to remove this step.
(If it can, that's cool!)

> to pass it to ‘make-linux-module’.  ‘linux-libre’ and ‘kmod’ would be
> implicit inputs.
> 
> > +;; FIXME: Remove CONFIG_MODULE_SRCVERSION_ALL=y from our configs.  
> 
> What does that flag do?

It adds a field "srcversion" to the ELF file of the module which is a hash of
all the source files used to build it.

Instead of removing it, we can also merge bug# 35111 instead and use that.

Otherwise, the problem is that if CONFIG_MODULE_SRCVERSION_ALL is set and
bug# 35111 not merged, one cannot build standalone modules because those
would require the file "Module.symvers" of the completely built kernel
to be available.

Linux would also write a new file "Module.symvers" in the MODPOST step of
the build of the module.

> Is it OK to use the default GCC?

Definitely not.  It has to be exactly the same gcc as used in building the
Linux kernel.

> Other than that it looks really cool!

It's just a quick hack.

I've started with the build system but it was too much work and I didn't
understand the mechanisms well enough.

For example, the lowest maintenance overhead would be to somehow have
most of linux-libre's phases be injected into the module package and have
both build in one build environment.  I.e. the module would have a package
which would actually have phases 'unpack 'prepare-linux 'build 'check 'install
where all the phases except for 'prepare-linux would be module-specific and
'prepare-linux would unpack the linux source and do everything just
like the linux-libre package would have done, up until the 'build phase.
It turned out that's too complicated to get to work for me for now.
[Message part 2 (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Thu, 04 Apr 2019 07:49:02 GMT) Full text and rfc822 format available.

Message #32 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH 1/3] gnu: Add make-linux-module.
Date: Thu, 04 Apr 2019 09:48:34 +0200
Hi Danny,

Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> On Wed, 03 Apr 2019 22:16:07 +0200
> Ludovic Courtès <ludo <at> gnu.org> wrote:
>
>> Would it make sense to turn it into a ‘linux-module-build-system’?  
>
> I started on it but haven't finished it yet.
>
>>That would avoid having to create a package object that cannot be built, just
>
> It can be built, it's just not very useful standalone because it only contains
> the source code and a few build artifacts (only the ones required to start
> building a module).  On the other hand it can be substituted and that's nice
> (if we can cut down the source code a lot, that is).

Can it be built (I’m talking about the ‘vhba-module’ package that you
sent)?  I’d expect it to look for the Linux makefile snippet and to fail
at that point, no?

> I don't understand how a build system would enable us to remove this step.
> (If it can, that's cool!)

We’d directly write:

  (define-public vhba-module
    (package
      (name "vhba-module")
      ;; …
      (build-system linux-module-build-system))

and that would abstract away the choice of dependencies (linux-libre,
kmod, GCC) and the set of build phases.

>> > +;; FIXME: Remove CONFIG_MODULE_SRCVERSION_ALL=y from our configs.  
>> 
>> What does that flag do?
>
> It adds a field "srcversion" to the ELF file of the module which is a hash of
> all the source files used to build it.
>
> Instead of removing it, we can also merge bug# 35111 instead and use that.
>
> Otherwise, the problem is that if CONFIG_MODULE_SRCVERSION_ALL is set and
> bug# 35111 not merged, one cannot build standalone modules because those
> would require the file "Module.symvers" of the completely built kernel
> to be available.
>
> Linux would also write a new file "Module.symvers" in the MODPOST step of
> the build of the module.

OK.  Sounds like we should merge #35111 then.

> For example, the lowest maintenance overhead would be to somehow have
> most of linux-libre's phases be injected into the module package and have
> both build in one build environment.  I.e. the module would have a package
> which would actually have phases 'unpack 'prepare-linux 'build 'check 'install
> where all the phases except for 'prepare-linux would be module-specific and
> 'prepare-linux would unpack the linux source and do everything just
> like the linux-libre package would have done, up until the 'build phase.
> It turned out that's too complicated to get to work for me for now.

What about factorizing these phases in a new (guix build
linux-module-build-system) module, which would export them as
‘%standard-phases’?  Then packages using ‘linux-module-build-system’
would use these phases by default, like we do for the other build
systems.

Does that make sense?

Thank you,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Fri, 05 Apr 2019 11:07:02 GMT) Full text and rfc822 format available.

Message #35 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH v2 0/2] Add support for loadable modules.
Date: Fri,  5 Apr 2019 13:05:48 +0200
Danny Milosavljevic (1):
  Add (guix build-system linux-module).

Pierre Neidhardt (1):
  gnu: Add vhba-module.

 Makefile.am                              |   2 +
 gnu/packages/linux.scm                   |  23 ++++
 guix/build-system/linux-module.scm       | 166 +++++++++++++++++++++++
 guix/build/linux-module-build-system.scm |  82 +++++++++++
 4 files changed, 273 insertions(+)
 create mode 100644 guix/build-system/linux-module.scm
 create mode 100644 guix/build/linux-module-build-system.scm





Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Fri, 05 Apr 2019 11:07:02 GMT) Full text and rfc822 format available.

Message #38 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH v2 1/2] Add (guix build-system linux-module).
Date: Fri,  5 Apr 2019 13:05:49 +0200
* guix/build/linux-module-build-system.scm: New file.
* guix/build-system/linux-module.scm: New file.
* Makefile.am (MODULES): Add them.
---
 Makefile.am                              |   2 +
 guix/build-system/linux-module.scm       | 166 +++++++++++++++++++++++
 guix/build/linux-module-build-system.scm |  82 +++++++++++
 3 files changed, 250 insertions(+)
 create mode 100644 guix/build-system/linux-module.scm
 create mode 100644 guix/build/linux-module-build-system.scm

diff --git a/Makefile.am b/Makefile.am
index c331da7267..ea07632526 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -120,6 +120,7 @@ MODULES =					\
   guix/build-system/gnu.scm			\
   guix/build-system/guile.scm			\
   guix/build-system/haskell.scm			\
+  guix/build-system/linux-module.scm		\
   guix/build-system/perl.scm			\
   guix/build-system/python.scm			\
   guix/build-system/ocaml.scm			\
@@ -172,6 +173,7 @@ MODULES =					\
   guix/build/texlive-build-system.scm		\
   guix/build/waf-build-system.scm		\
   guix/build/haskell-build-system.scm		\
+  guix/build/linux-module-build-system.scm	\
   guix/build/store-copy.scm			\
   guix/build/utils.scm				\
   guix/build/union.scm				\
diff --git a/guix/build-system/linux-module.scm b/guix/build-system/linux-module.scm
new file mode 100644
index 0000000000..3ed3351353
--- /dev/null
+++ b/guix/build-system/linux-module.scm
@@ -0,0 +1,166 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Danny Milosavljevic <dannym <at> scratchpost.org>
+;;;
+;;; 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 (guix build-system linux-module)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix derivations)
+  #:use-module (guix search-paths)
+  #:use-module (guix build-system)
+  #:use-module (guix build-system gnu)
+  #:use-module (guix packages)
+  #:use-module (ice-9 match)
+  #:export (%linux-module-build-system-modules
+            linux-module-build
+            linux-module-build-system))
+
+;; Commentary:
+;;
+;; Code:
+
+(define %linux-module-build-system-modules
+  ;; Build-side modules imported by default.
+  `((guix build linux-module-build-system)
+    ,@%gnu-build-system-modules))
+
+(define (default-linux)
+  "Return the default Linux package."
+
+  ;; Do not use `@' to avoid introducing circular dependencies.
+  (let ((module (resolve-interface '(gnu packages linux))))
+    (module-ref module 'linux-libre)))
+
+(define (default-kmod)
+  "Return the default kmod package."
+
+  ;; Do not use `@' to avoid introducing circular dependencies.
+  (let ((module (resolve-interface '(gnu packages linux))))
+    (module-ref module 'kmod)))
+
+(define (default-gcc)
+  "Return the default gcc package."
+
+  ;; Do not use `@' to avoid introducing circular dependencies.
+  (let ((module (resolve-interface '(gnu packages gcc))))
+    (module-ref module 'gcc-7)))
+
+(define (make-linux-module-builder linux)
+  (package
+    (inherit linux)
+    (name (string-append (package-name linux) "-module-builder"))
+    (arguments
+     (substitute-keyword-arguments (package-arguments linux)
+      ((#:phases phases)
+       `(modify-phases ,phases
+          (replace 'build
+            (lambda _
+              (invoke "make" "modules_prepare")))
+          (delete 'strip) ; faster.
+          (replace 'install
+            (lambda* (#:key outputs #:allow-other-keys)
+              (let* ((out (assoc-ref outputs "out"))
+                     (out-lib-build (string-append out "/lib/modules/build")))
+                ; TODO: Only preserve the minimum, i.e. [Kbuild], Kconfig, scripts, include, ".config".
+                (copy-recursively "." out-lib-build)
+                #t)))))))))
+
+(define* (lower name
+                #:key source inputs native-inputs outputs
+                system target
+                (linux (default-linux))
+                #:allow-other-keys
+                #:rest arguments)
+  "Return a bag for NAME."
+  (define private-keywords
+    '(#:source #:target #:gcc #:kmod #:linux #:inputs #:native-inputs))
+
+  (and (not target)                               ;XXX: no cross-compilation
+       (bag
+         (name name)
+         (system system)
+         (host-inputs `(,@(if source
+                              `(("source" ,source))
+                              '())
+                        ,@inputs
+                        ,@(standard-packages)))
+         (build-inputs `(("linux" ,linux) ; for "Module.symvers".
+                         ("linux-module-builder"
+                         ,(make-linux-module-builder linux))
+                         ,@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)))
+         (outputs outputs)
+         (build linux-module-build)
+         (arguments (strip-keyword-arguments private-keywords arguments)))))
+
+(define* (linux-module-build store name inputs
+                             #:key
+                             (search-paths '())
+                             (tests? #t)
+                             (phases '(@ (guix build linux-module-build-system)
+                                         %standard-phases))
+                             (outputs '("out"))
+                             (system (%current-system))
+                             (guile #f)
+                             (imported-modules
+                              %linux-module-build-system-modules)
+                             (modules '((guix build linux-module-build-system)
+                                        (guix build utils))))
+  "Build SOURCE using LINUX, and with INPUTS."
+  (define builder
+    `(begin
+       (use-modules ,@modules)
+       (linux-module-build #:name ,name
+                     #:source ,(match (assoc-ref inputs "source")
+                                      (((? derivation? source))
+                                       (derivation->output-path source))
+                                      ((source)
+                                       source)
+                                      (source
+                                        source))
+                     #:search-paths ',(map search-path-specification->sexp
+                                           search-paths)
+                     #:phases ,phases
+                     #:system ,system
+                     #:tests? ,tests?
+                     #:outputs %outputs
+                     #:inputs %build-inputs)))
+
+  (define guile-for-build
+    (match guile
+      ((? package?)
+       (package-derivation store guile system #:graft? #f))
+      (#f                                         ; the default
+       (let* ((distro (resolve-interface '(gnu packages commencement)))
+              (guile  (module-ref distro 'guile-final)))
+         (package-derivation store guile system #:graft? #f)))))
+
+  (build-expression->derivation store name builder
+                                #:system system
+                                #:inputs inputs
+                                #:modules imported-modules
+                                #:outputs outputs
+                                #:guile-for-build guile-for-build))
+
+(define linux-module-build-system
+  (build-system
+    (name 'linux-module)
+    (description "The Linux module build system")
+    (lower lower)))
+
+;;; linux-module.scm ends here
diff --git a/guix/build/linux-module-build-system.scm b/guix/build/linux-module-build-system.scm
new file mode 100644
index 0000000000..2da1d32652
--- /dev/null
+++ b/guix/build/linux-module-build-system.scm
@@ -0,0 +1,82 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Danny Milosavljevic <dannym <at> scratchpost.org>
+;;;
+;;; 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 (guix build linux-module-build-system)
+  #:use-module ((guix build gnu-build-system) #:prefix gnu:)
+  #:use-module (guix build utils)
+  #:use-module (ice-9 ftw)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+  #:export (%standard-phases
+            linux-module-build))
+
+;; Commentary:
+;;
+;; Builder-side code of linux-module build.
+;;
+;; Code:
+
+(define* (configure #:key inputs #:allow-other-keys)
+  #t)
+;  (let ((source (string-append (assoc-ref inputs "linux")
+;                               "/Module.symvers")))
+;    (if (file-exists? source)
+;        (install-file source out-lib-build))
+;    #t))
+
+(define* (build #:key inputs make-flags #:allow-other-keys)
+  (apply invoke "make" "-C"
+         (string-append (assoc-ref inputs "linux-module-builder")
+                        "/lib/modules/build")
+         (string-append "M=" (getcwd))
+         (or make-flags '())))
+
+;; This block was copied from make-linux-libre--only took the "modules_install"
+;; part.
+(define* (install #:key inputs native-inputs outputs #:allow-other-keys)
+  (let* ((out (assoc-ref outputs "out"))
+         (moddir (string-append out "/lib/modules"))
+         (kmod (assoc-ref (or native-inputs inputs) "kmod")))
+    ;; Install kernel modules
+    (mkdir-p moddir)
+    (invoke "make" "-C"
+            (string-append (assoc-ref inputs "linux-module-builder")
+                           "/lib/modules/build")
+            (string-append "M=" (getcwd))
+            (string-append "DEPMOD=" kmod "/bin/depmod")
+            (string-append "MODULE_DIR=" moddir)
+            (string-append "INSTALL_PATH=" out)
+            (string-append "INSTALL_MOD_PATH=" out)
+            "INSTALL_MOD_STRIP=1"
+            "modules_install")))
+
+(define %standard-phases
+  (modify-phases gnu:%standard-phases
+    (replace 'configure configure)
+    (replace 'build build)
+    (replace 'install install)))
+
+(define* (linux-module-build #:key inputs (phases %standard-phases)
+                       #:allow-other-keys #:rest args)
+  "Build the given package, applying all of PHASES in order, with a Linux kernel in attendance."
+  (apply gnu:gnu-build
+         #:inputs inputs #:phases phases
+         args))
+
+;;; linux-module-build-system.scm ends here




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Fri, 05 Apr 2019 11:07:03 GMT) Full text and rfc822 format available.

Message #41 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: 35110 <at> debbugs.gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>,
 Pierre Neidhardt <mail <at> ambrevar.xyz>
Subject: [PATCH v2 2/2] gnu: Add vhba-module.
Date: Fri,  5 Apr 2019 13:05:50 +0200
From: Pierre Neidhardt <mail <at> ambrevar.xyz>

* gnu/packages/linux.scm (vhba-module): New variable.

Signed-off-by: Danny Milosavljevic <dannym <at> scratchpost.org>
---
 gnu/packages/linux.scm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index e4f6e241ec..52ae0387d1 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -118,6 +118,7 @@
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system python)
   #:use-module (guix build-system trivial)
+  #:use-module (guix build-system linux-module)
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module ((guix licenses) #:prefix license:)
@@ -438,6 +439,28 @@ It has been modified to remove all non-free binary blobs.")
                     #:patches %linux-libre-5.0-patches
                     #:configuration-file kernel-config))
 
+(define-public vhba-module
+  (package
+    (name "vhba-module")
+    (version "20170610")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "http://downloads.sourceforge.net/cdemu/vhba-module-"
+                    version ".tar.bz2"))
+              (sha256
+               (base32
+                "1v6r0bgx0a65vlh36b1l2965xybngbpga6rp54k4z74xk0zwjw3r"))))
+    (build-system linux-module-build-system)
+    (arguments
+     ;; TODO: No tests?
+     `(#:tests? #f))
+    (home-page "https://cdemu.sourceforge.io/")
+    (synopsis "Kernel module that emulates SCSI devices")
+    (description "VHBA module provides a Virtual (SCSI) HBA, which is the link
+between the CDemu userspace daemon and linux kernel.")
+    (license license:gpl2+)))
+
 (define %linux-libre-4.19-version "4.19.33")
 (define %linux-libre-4.19-hash "147ksl3ksxdv2ifr18cbzq4647n9d7yr7kbxg02sljia7z3b70cm")
 




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Thu, 11 Apr 2019 10:51:02 GMT) Full text and rfc822 format available.

Message #44 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 35110 <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH v2 1/2] Add (guix build-system linux-module).
Date: Thu, 11 Apr 2019 12:50:42 +0200
Hi Danny,

Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> * guix/build/linux-module-build-system.scm: New file.
> * guix/build-system/linux-module.scm: New file.
> * Makefile.am (MODULES): Add them.

Awesome!

> +(define* (configure #:key inputs #:allow-other-keys)
> +  #t)
> +;  (let ((source (string-append (assoc-ref inputs "linux")
> +;                               "/Module.symvers")))
> +;    (if (file-exists? source)
> +;        (install-file source out-lib-build))
> +;    #t))

I think you should either remove this comment or add an explanation
and/or a TODO.

Could you also add a note in doc/guix.texi under “Build Systems”?

Otherwise LGTM, thank you!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#35110; Package guix-patches. (Thu, 11 Apr 2019 10:52:02 GMT) Full text and rfc822 format available.

Message #47 received at 35110 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: Pierre Neidhardt <mail <at> ambrevar.xyz>, 35110 <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH v2 2/2] gnu: Add vhba-module.
Date: Thu, 11 Apr 2019 12:51:03 +0200
Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> From: Pierre Neidhardt <mail <at> ambrevar.xyz>
>
> * gnu/packages/linux.scm (vhba-module): New variable.
>
> Signed-off-by: Danny Milosavljevic <dannym <at> scratchpost.org>

LGTM, thanks!

Ludo'.




Reply sent to Danny Milosavljevic <dannym <at> scratchpost.org>:
You have taken responsibility. (Thu, 11 Apr 2019 15:54:02 GMT) Full text and rfc822 format available.

Notification sent to Danny Milosavljevic <dannym <at> scratchpost.org>:
bug acknowledged by developer. (Thu, 11 Apr 2019 15:54:02 GMT) Full text and rfc822 format available.

Message #52 received at 35110-done <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 35110-done <at> debbugs.gnu.org
Subject: Re: [bug#35110] [PATCH v2 1/2] Add (guix build-system linux-module).
Date: Thu, 11 Apr 2019 17:53:47 +0200
[Message part 1 (text/plain, inline)]
Hi Ludo,

On Thu, 11 Apr 2019 12:50:42 +0200
Ludovic Courtès <ludo <at> gnu.org> wrote:

> > +(define* (configure #:key inputs #:allow-other-keys)

> I think you should either remove this comment or add an explanation
> and/or a TODO.

Added TODO.

> Could you also add a note in doc/guix.texi under “Build Systems”?

Did so.

Pushed!
[Message part 2 (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 10 May 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 325 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.