[PATCH 0/3] Add support for loadable modules.

  • Done
  • quality assurance status badge
Details
3 participants
  • Danny Milosavljevic
  • Ludovic Courtès
  • Pierre Neidhardt
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 6 years ago
(address . guix-patches@gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190402192729.5262-1-dannym@scratchpost.org
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(-)
Danny Milosavljevic wrote 6 years ago
[PATCH 1/3] gnu: Add make-linux-module.
(address . 35110@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190402192855.5314-1-dannym@scratchpost.org
* gnu/packages/linux.scm (make-linux-module): New procedure.
---
gnu/packages/linux.scm | 66 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)

Toggle diff (76 lines)
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")
Danny Milosavljevic wrote 6 years ago
[PATCH 2/3] gnu: Add vhba-module-linux-libre.
(address . 35110@debbugs.gnu.org)
20190402192855.5314-2-dannym@scratchpost.org
From: Pierre Neidhardt <mail@ambrevar.xyz>

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

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

Toggle diff (38 lines)
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")
Danny Milosavljevic wrote 6 years ago
[PATCH 3/3] gnu: linux-libre: Disable module versioning.
(address . 35110@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190402192855.5314-3-dannym@scratchpost.org
* 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(-)

Toggle diff (13 lines)
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
Pierre Neidhardt wrote 6 years ago
Re: [PATCH 2/3] gnu: Add vhba-module-linux-libre.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
87r2akyt2f.fsf@ambrevar.xyz
Thanks for looking into this!

Danny Milosavljevic <dannym@scratchpost.org> writes:

Toggle quote (3 lines)
> +(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
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlyj2VgACgkQm9z0l6S7
zH+crgf+NH1pOfDT2HWRKwvfIAibmpqaQ0Ero9JkFrvkUxzo9XEQAuOegPt1RL7P
wNMulVgB0Z49Qc8b3cSTU5hemj9XMlAOwJVRdj4XIFBeRUVvszxc3wMQeK8n4kbz
iDhyHb1vJrACpXeC0i05W5X+6Vo00rM4u9INnPSryvR44QIgJLYULcMu/phIUqaF
SUiA1uT9SkNBGwa268wbtfK9NN13HiV+9rvUvI5hZtC03mrTwMf9HG050WOjVbHE
D5Ti5vlcbsG9OGjgrnMEUNAspJ7bWJvXDXWgkMMPOg+LRkNKnjbL5EXuEugr9Vh/
4fV4EQHwip+OU7HFwVQ3C1M7qQQhhg==
=pVfy
-----END PGP SIGNATURE-----

Danny Milosavljevic wrote 6 years ago
(name . Pierre Neidhardt)(address . mail@ambrevar.xyz)(address . 35110@debbugs.gnu.org)
20190403003606.44e77e50@scratchpost.org
See PATCH 1/3, Message ID <20190402192855.5314-1-dannym@scratchpost.org>
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlyj49YACgkQ5xo1VCww
uqW18wf8DqNUr9lQYfGZfTxpfSkUIRWeReARFCidzKL93C+/MAxZNoVCFfwwvKsi
TovbFDS3FPQMqc3MlLfAlsv/ykAqYegxChCBI780QFjc7Dep67KItF+/Cgm1//0f
kTefcEBgu9grQg6ElrP0CoZ8bti1A5hDwFa2l/lw1qnu0a/cQrv4rXFP8XQ2+A3f
ywbF1Ebt7SwzAE5UjrAWXuJSdnR6LWsX1onO3xjRzj1IIrRiHd9M00rRxf/CfM1s
gXJsy6NO6qFv26eeouPuOsfs5C+B2PLvLQhngF9ZHMESGxA86b2u0bDgHQuGew7u
PdZisF4DqyX3Vu9uVKv4Tnqwe6X8cQ==
=Luhp
-----END PGP SIGNATURE-----


Pierre Neidhardt wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 35110@debbugs.gnu.org)
87o95nziqv.fsf@ambrevar.xyz
Brilliant! Thank you so much for this!

--
Pierre Neidhardt
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlykV1gACgkQm9z0l6S7
zH9eVAgAg4wISRapEzvJGV4Gxzbs8eDfnPwERaoscWfRecNBv3dohFd5BQq49lT0
bqjA9yDTnYU0JHJ4VLjm7SvbrkdAvwcywpAccJ+0hTJsVn7dqkC0HwXfCBoyYKwh
Ce3wtymvPZwPteFOpYQ9wGnIRSBf7sa3k+UXExl5oj/k52cRq/oR4WLGBcQsAIQZ
4gVZVNPlzJLq0J/tlWsWsfFsPwoWvYPu7prTzTWjgNMCjcT8gbPgBX4EmsDjvfKl
Zanl3zlOtbPyedUanyGmq/7FpIAHVASA485TLJYzVsWEv9+vQ27fm6FfEGoG8kT4
JX6LsuHvKRKYflG5ZnT3mMoz4Uhr9A==
=pMSt
-----END PGP SIGNATURE-----

Ludovic Courtès wrote 6 years ago
Re: [bug#35110] [PATCH 1/3] gnu: Add make-linux-module.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 35110@debbugs.gnu.org)
87wokargjc.fsf@gnu.org
Hi Danny,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (2 lines)
> * 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.

Toggle quote (2 lines)
> +;; FIXME: Remove CONFIG_MODULE_SRCVERSION_ALL=y from our configs.

What does that flag do?

Toggle quote (7 lines)
> + (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’.
Danny Milosavljevic wrote 6 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 35110@debbugs.gnu.org)
20190403224823.66d25e12@scratchpost.org
Hi Ludo,

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

Toggle quote (2 lines)
> Would it make sense to turn it into a ‘linux-module-build-system’?

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

Toggle quote (2 lines)
>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!)

Toggle quote (7 lines)
> 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.

Toggle quote (2 lines)
> 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.

Toggle quote (2 lines)
> 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.
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlylHBcACgkQ5xo1VCww
uqUqZwf/WcWRyzwxBFMSnEU+KT9yHCOedS8pqdhNK7iNhphWjXPg3/lrvAzws8KD
8p83YPYT2jG51W8hAFw/f7yzBt1GcKOLOyxSp0lIbmMyVaW3Bxx+wukhhQYPhJt/
G5PE07PQseDT2woONEEiyd/KGjZwMysO/hIyDCW80LwlFaARAeHKemyrFzKWRxlt
2Jm1HZ05kbncRolofpH//QlcnaTv2wRv5FpfxpSDK5eZJfD3tQ0RYrR4j31GfPR5
7yQId9WOHP6H168fhjzs80hKrc+kHjFXTLfOg9UT4bzN0E5KvFfeAaIHOzF2H+SU
0rUWjyt68pVcssBibzsHnPDtzA9Jyg==
=pI7R
-----END PGP SIGNATURE-----


Ludovic Courtès wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 35110@debbugs.gnu.org)
87ef6ius6l.fsf@gnu.org
Hi Danny,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (14 lines)
> On Wed, 03 Apr 2019 22:16:07 +0200
> Ludovic Courtès <ludo@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?

Toggle quote (3 lines)
> 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.

Toggle quote (17 lines)
>> > +;; 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.

Toggle quote (9 lines)
> 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’.
Danny Milosavljevic wrote 6 years ago
[PATCH v2 0/2] Add support for loadable modules.
(address . 35110@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190405110550.24168-1-dannym@scratchpost.org
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
Danny Milosavljevic wrote 6 years ago
[PATCH v2 1/2] Add (guix build-system linux-module).
(address . 35110@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190405110550.24168-2-dannym@scratchpost.org
* 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

Toggle diff (280 lines)
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@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@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
Danny Milosavljevic wrote 6 years ago
[PATCH v2 2/2] gnu: Add vhba-module.
(address . 35110@debbugs.gnu.org)
20190405110550.24168-3-dannym@scratchpost.org
From: Pierre Neidhardt <mail@ambrevar.xyz>

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

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

Toggle diff (40 lines)
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")
Ludovic Courtès wrote 6 years ago
Re: [bug#35110] [PATCH v2 1/2] Add (guix build-system linux-module).
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 35110@debbugs.gnu.org)
87ftqo3jel.fsf@gnu.org
Hi Danny,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

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

Awesome!

Toggle quote (8 lines)
> +(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’.
Ludovic Courtès wrote 6 years ago
Re: [bug#35110] [PATCH v2 2/2] gnu: Add vhba-module.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
87bm1c3je0.fsf@gnu.org
Danny Milosavljevic <dannym@scratchpost.org> skribis:

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

LGTM, thanks!

Ludo'.
Danny Milosavljevic wrote 6 years ago
Re: [bug#35110] [PATCH v2 1/2] Add (guix build-system linux-module).
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 35110-done@debbugs.gnu.org)
20190411175347.3820b0d9@scratchpost.org
Hi Ludo,

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

Toggle quote (5 lines)
> > +(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.

Toggle quote (2 lines)
> Could you also add a note in doc/guix.texi under “Build Systems”?

Did so.

Pushed!
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlyvYwsACgkQ5xo1VCww
uqUv/gf+NkXYIKRvSg6YVRAw7IoEL9Ab+H28wQ2hkC1NkTED8R6oBNFpME497sMe
ZRA5Vu2xZVMPf0U0wlt2EXaQ+nz1o6aAPRkruFqsOteTtrclRGt5LmIR2EjYDaQs
xLOEPqcOJ9Pozzh6a2NqANYmnRD4cLB+Q5rE0RhOk2cK4G/dKooZVDfopwSSXz6L
kkLMs6OV7hDGj6BfBzpqrIW6LQuF3dIr6HNg2GZiBY59mlG2npbQqf4tgpw1r662
FPmimjIswZ+AJOFCqBqB0l/qE+U1Bou36CNAMkTodIZxvOe9H8M6953Plwu9hD4m
0v1rtNDwPCYUKpfbmF+uWy3HZrfmJQ==
=E1Jd
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 35110@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 35110
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help