diff options
| author | raid5atemyhomework <raid5atemyhomework@protonmail.com> | 2021-03-22 11:23:32 +0800 |
|---|---|---|
| committer | Danny Milosavljevic <dannym@scratchpost.org> | 2021-05-11 16:13:48 +0200 |
| commit | a3df382525ac515d1aa083f7f5bd3bd31eb1df40 (patch) | |
| tree | ceaa4eaf3a5c2d2a85e64ca83b7d23a9e9d306ed /gnu | |
| parent | bddad00bffc5837e89942756fa5b7234f63f1f47 (diff) | |
gnu: Allow services to install kernel-loadable modules.
* gnu/system.scm (operating-system-directory-base-entries): Remove code
to handle generation of "kernel" for linux-libre kernels.
(operating-system-default-essential-services): Instantiate
linux-builder-service-type.
(package-for-kernel): Move ...
* gnu/services.scm: ... to here.
(linux-builder-service-type): New variable.
(linux-builder-configuration): New type.
(linux-loadable-module-service-type): New variable.
* gnu/tests/linux-modules.scm (run-loadable-kernel-modules-test): Move
code to ...
(run-loadable-kernel-modules-test-base): ... new procedure here.
(run-loadable-kernel-modules-service-test): New procedure.
(%test-loadable-kernel-modules-service-0): New variable.
(%test-loadable-kernel-modules-service-1): New variable.
(%test-loadable-kernel-modules-service-2): New variable.
* doc/guix.texi: Document linux-loadable-module-service-type.
Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org>
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/services.scm | 90 | ||||
| -rw-r--r-- | gnu/system.scm | 34 | ||||
| -rw-r--r-- | gnu/tests/linux-modules.scm | 80 |
3 files changed, 169 insertions, 35 deletions
diff --git a/gnu/services.scm b/gnu/services.scm index e7da0a026d8..8d413e198e6 100644 --- a/gnu/services.scm +++ b/gnu/services.scm | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com> | 3 | ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com> |
| 4 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> | 4 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> |
| 5 | ;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net> | 5 | ;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net> |
| 6 | ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> | ||
| 6 | ;;; | 7 | ;;; |
| 7 | ;;; This file is part of GNU Guix. | 8 | ;;; This file is part of GNU Guix. |
| 8 | ;;; | 9 | ;;; |
| @@ -34,6 +35,8 @@ | |||
| 34 | #:use-module (guix diagnostics) | 35 | #:use-module (guix diagnostics) |
| 35 | #:autoload (guix openpgp) (openpgp-format-fingerprint) | 36 | #:autoload (guix openpgp) (openpgp-format-fingerprint) |
| 36 | #:use-module (guix modules) | 37 | #:use-module (guix modules) |
| 38 | #:use-module (guix packages) | ||
| 39 | #:use-module (guix utils) | ||
| 37 | #:use-module (gnu packages base) | 40 | #:use-module (gnu packages base) |
| 38 | #:use-module (gnu packages bash) | 41 | #:use-module (gnu packages bash) |
| 39 | #:use-module (gnu packages hurd) | 42 | #:use-module (gnu packages hurd) |
| @@ -107,6 +110,12 @@ | |||
| 107 | profile-service-type | 110 | profile-service-type |
| 108 | firmware-service-type | 111 | firmware-service-type |
| 109 | gc-root-service-type | 112 | gc-root-service-type |
| 113 | linux-builder-service-type | ||
| 114 | linux-builder-configuration | ||
| 115 | linux-builder-configuration? | ||
| 116 | linux-builder-configuration-kernel | ||
| 117 | linux-builder-configuration-modules | ||
| 118 | linux-loadable-module-service-type | ||
| 110 | 119 | ||
| 111 | %boot-service | 120 | %boot-service |
| 112 | %activation-service | 121 | %activation-service |
| @@ -883,6 +892,87 @@ as Wifi cards."))) | |||
| 883 | will not be reclaimed by the garbage collector.") | 892 | will not be reclaimed by the garbage collector.") |
| 884 | (default-value '()))) | 893 | (default-value '()))) |
| 885 | 894 | ||
| 895 | ;; Configuration for the Linux kernel builder. | ||
| 896 | (define-record-type* <linux-builder-configuration> | ||
| 897 | linux-builder-configuration | ||
| 898 | make-linux-builder-configuration | ||
| 899 | linux-builder-configuration? | ||
| 900 | this-linux-builder-configuration | ||
| 901 | |||
| 902 | (kernel linux-builder-configuration-kernel) ; package | ||
| 903 | (modules linux-builder-configuration-modules (default '()))) ; list of packages | ||
| 904 | |||
| 905 | (define (package-for-kernel target-kernel module-package) | ||
| 906 | "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if | ||
| 907 | possible (that is if there's a LINUX keyword argument in the build system)." | ||
| 908 | (package | ||
| 909 | (inherit module-package) | ||
| 910 | (arguments | ||
| 911 | (substitute-keyword-arguments (package-arguments module-package) | ||
| 912 | ((#:linux kernel #f) | ||
| 913 | target-kernel))))) | ||
| 914 | |||
| 915 | (define (linux-builder-configuration->system-entry config) | ||
| 916 | "Return the kernel entry of the 'system' directory." | ||
| 917 | (let* ((kernel (linux-builder-configuration-kernel config)) | ||
| 918 | (modules (linux-builder-configuration-modules config)) | ||
| 919 | (kernel (profile | ||
| 920 | (content (packages->manifest | ||
| 921 | (cons kernel | ||
| 922 | (map (lambda (module) | ||
| 923 | (cond | ||
| 924 | ((package? module) | ||
| 925 | (package-for-kernel kernel module)) | ||
| 926 | ;; support (,package "kernel-module-output") | ||
| 927 | ((and (list? module) (package? (car module))) | ||
| 928 | (cons (package-for-kernel kernel | ||
| 929 | (car module)) | ||
| 930 | (cdr module))) | ||
| 931 | (else | ||
| 932 | module))) | ||
| 933 | modules)))) | ||
| 934 | (hooks (list linux-module-database))))) | ||
| 935 | (with-monad %store-monad | ||
| 936 | (return `(("kernel" ,kernel)))))) | ||
| 937 | |||
| 938 | (define linux-builder-service-type | ||
| 939 | (service-type (name 'linux-builder) | ||
| 940 | (extensions | ||
| 941 | (list (service-extension system-service-type | ||
| 942 | linux-builder-configuration->system-entry))) | ||
| 943 | (default-value '()) | ||
| 944 | (compose identity) | ||
| 945 | (extend (lambda (config modifiers) | ||
| 946 | (if (null? modifiers) | ||
| 947 | config | ||
| 948 | ((apply compose modifiers) config)))) | ||
| 949 | (description "Builds the linux-libre kernel profile, containing | ||
| 950 | the kernel itself and any linux-loadable kernel modules. This can be extended | ||
| 951 | with a function that accepts the current configuration and returns a new | ||
| 952 | configuration."))) | ||
| 953 | |||
| 954 | (define (linux-loadable-module-builder-modifier modules) | ||
| 955 | "Extends linux-builder-service-type by appending the given MODULES to the | ||
| 956 | configuration of linux-builder-service-type." | ||
| 957 | (lambda (config) | ||
| 958 | (linux-builder-configuration | ||
| 959 | (inherit config) | ||
| 960 | (modules (append (linux-builder-configuration-modules config) | ||
| 961 | modules))))) | ||
| 962 | |||
| 963 | (define linux-loadable-module-service-type | ||
| 964 | (service-type (name 'linux-loadable-modules) | ||
| 965 | (extensions | ||
| 966 | (list (service-extension linux-builder-service-type | ||
| 967 | linux-loadable-module-builder-modifier))) | ||
| 968 | (default-value '()) | ||
| 969 | (compose concatenate) | ||
| 970 | (extend append) | ||
| 971 | (description "Adds packages and package outputs as modules | ||
| 972 | included in the booted linux-libre profile. Other services can extend this | ||
| 973 | service type to add particular modules to the set of linux-loadable modules."))) | ||
| 974 | |||
| 975 | |||
| 886 | 976 | ||
| 887 | ;;; | 977 | ;;; |
| 888 | ;;; Service folding. | 978 | ;;; Service folding. |
diff --git a/gnu/system.scm b/gnu/system.scm index 5bf2a852729..7cc4f134b71 100644 --- a/gnu/system.scm +++ b/gnu/system.scm | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <jannek@gnu.org> | 13 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <jannek@gnu.org> |
| 14 | ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il> | 14 | ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il> |
| 15 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> | 15 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> |
| 16 | ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> | ||
| 16 | ;;; | 17 | ;;; |
| 17 | ;;; This file is part of GNU Guix. | 18 | ;;; This file is part of GNU Guix. |
| 18 | ;;; | 19 | ;;; |
| @@ -601,16 +602,6 @@ OS." | |||
| 601 | (file-append (operating-system-kernel os) | 602 | (file-append (operating-system-kernel os) |
| 602 | "/" (system-linux-image-file-name)))) | 603 | "/" (system-linux-image-file-name)))) |
| 603 | 604 | ||
| 604 | (define (package-for-kernel target-kernel module-package) | ||
| 605 | "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if | ||
| 606 | possible (that is if there's a LINUX keyword argument in the build system)." | ||
| 607 | (package | ||
| 608 | (inherit module-package) | ||
| 609 | (arguments | ||
| 610 | (substitute-keyword-arguments (package-arguments module-package) | ||
| 611 | ((#:linux kernel #f) | ||
| 612 | target-kernel))))) | ||
| 613 | |||
| 614 | (define %default-modprobe-blacklist | 605 | (define %default-modprobe-blacklist |
| 615 | ;; List of kernel modules to blacklist by default. | 606 | ;; List of kernel modules to blacklist by default. |
| 616 | '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574> | 607 | '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574> |
| @@ -628,23 +619,12 @@ value of the SYSTEM-SERVICE-TYPE service." | |||
| 628 | (let* ((locale (operating-system-locale-directory os)) | 619 | (let* ((locale (operating-system-locale-directory os)) |
| 629 | (kernel (operating-system-kernel os)) | 620 | (kernel (operating-system-kernel os)) |
| 630 | (hurd (operating-system-hurd os)) | 621 | (hurd (operating-system-hurd os)) |
| 631 | (modules (operating-system-kernel-loadable-modules os)) | ||
| 632 | (kernel (if hurd | ||
| 633 | kernel | ||
| 634 | (profile | ||
| 635 | (content (packages->manifest | ||
| 636 | (cons kernel | ||
| 637 | (map (lambda (module) | ||
| 638 | (if (package? module) | ||
| 639 | (package-for-kernel kernel | ||
| 640 | module) | ||
| 641 | module)) | ||
| 642 | modules)))) | ||
| 643 | (hooks (list linux-module-database))))) | ||
| 644 | (initrd (and (not hurd) (operating-system-initrd-file os))) | 622 | (initrd (and (not hurd) (operating-system-initrd-file os))) |
| 645 | (params (operating-system-boot-parameters-file os))) | 623 | (params (operating-system-boot-parameters-file os))) |
| 646 | `(("kernel" ,kernel) | 624 | `(,@(if hurd |
| 647 | ,@(if hurd `(("hurd" ,hurd)) '()) | 625 | `(("hurd" ,hurd) |
| 626 | ("kernel" ,kernel)) | ||
| 627 | '()) | ||
| 648 | ("parameters" ,params) | 628 | ("parameters" ,params) |
| 649 | ,@(if initrd `(("initrd" ,initrd)) '()) | 629 | ,@(if initrd `(("initrd" ,initrd)) '()) |
| 650 | ("locale" ,locale)))) ;used by libc | 630 | ("locale" ,locale)))) ;used by libc |
| @@ -664,6 +644,10 @@ bookkeeping." | |||
| 664 | (host-name (host-name-service (operating-system-host-name os))) | 644 | (host-name (host-name-service (operating-system-host-name os))) |
| 665 | (entries (operating-system-directory-base-entries os))) | 645 | (entries (operating-system-directory-base-entries os))) |
| 666 | (cons* (service system-service-type entries) | 646 | (cons* (service system-service-type entries) |
| 647 | (service linux-builder-service-type | ||
| 648 | (linux-builder-configuration | ||
| 649 | (kernel (operating-system-kernel os)) | ||
| 650 | (modules (operating-system-kernel-loadable-modules os)))) | ||
| 667 | %boot-service | 651 | %boot-service |
| 668 | 652 | ||
| 669 | ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that | 653 | ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that |
diff --git a/gnu/tests/linux-modules.scm b/gnu/tests/linux-modules.scm index 953b132ef7b..30d8eae03b8 100644 --- a/gnu/tests/linux-modules.scm +++ b/gnu/tests/linux-modules.scm | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2 | ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org> |
| 3 | ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> | 3 | ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> |
| 4 | ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> | 4 | ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> |
| 5 | ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> | ||
| 5 | ;;; | 6 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 7 | ;;; This file is part of GNU Guix. |
| 7 | ;;; | 8 | ;;; |
| @@ -34,7 +35,10 @@ | |||
| 34 | #:use-module (guix utils) | 35 | #:use-module (guix utils) |
| 35 | #:export (%test-loadable-kernel-modules-0 | 36 | #:export (%test-loadable-kernel-modules-0 |
| 36 | %test-loadable-kernel-modules-1 | 37 | %test-loadable-kernel-modules-1 |
| 37 | %test-loadable-kernel-modules-2)) | 38 | %test-loadable-kernel-modules-2 |
| 39 | %test-loadable-kernel-modules-service-0 | ||
| 40 | %test-loadable-kernel-modules-service-1 | ||
| 41 | %test-loadable-kernel-modules-service-2)) | ||
| 38 | 42 | ||
| 39 | ;;; Commentary: | 43 | ;;; Commentary: |
| 40 | ;;; | 44 | ;;; |
| @@ -66,17 +70,11 @@ that MODULES are actually loaded." | |||
| 66 | (member module modules string=?)) | 70 | (member module modules string=?)) |
| 67 | '#$modules)))))) | 71 | '#$modules)))))) |
| 68 | 72 | ||
| 69 | (define* (run-loadable-kernel-modules-test module-packages module-names) | 73 | (define* (run-loadable-kernel-modules-test-base base-os module-names) |
| 70 | "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES | 74 | "Run a test of BASE-OS, verifying that MODULE-NAMES are loaded in memory." |
| 71 | are loaded in memory." | ||
| 72 | (define os | 75 | (define os |
| 73 | (marionette-operating-system | 76 | (marionette-operating-system |
| 74 | (operating-system | 77 | base-os |
| 75 | (inherit (simple-operating-system)) | ||
| 76 | (services (cons (service kernel-module-loader-service-type module-names) | ||
| 77 | (operating-system-user-services | ||
| 78 | (simple-operating-system)))) | ||
| 79 | (kernel-loadable-modules module-packages)) | ||
| 80 | #:imported-modules '((guix combinators)))) | 78 | #:imported-modules '((guix combinators)))) |
| 81 | (define vm (virtual-machine os)) | 79 | (define vm (virtual-machine os)) |
| 82 | (define (test script) | 80 | (define (test script) |
| @@ -98,6 +96,36 @@ are loaded in memory." | |||
| 98 | (gexp->derivation "loadable-kernel-modules" | 96 | (gexp->derivation "loadable-kernel-modules" |
| 99 | (test (modules-loaded?-program os module-names)))) | 97 | (test (modules-loaded?-program os module-names)))) |
| 100 | 98 | ||
| 99 | (define* (run-loadable-kernel-modules-test module-packages module-names) | ||
| 100 | "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES | ||
| 101 | are loaded in memory." | ||
| 102 | (run-loadable-kernel-modules-test-base | ||
| 103 | (operating-system | ||
| 104 | (inherit (simple-operating-system)) | ||
| 105 | (services (cons (service kernel-module-loader-service-type module-names) | ||
| 106 | (operating-system-user-services | ||
| 107 | (simple-operating-system)))) | ||
| 108 | (kernel-loadable-modules module-packages)) | ||
| 109 | module-names)) | ||
| 110 | |||
| 111 | (define* (run-loadable-kernel-modules-service-test module-packages module-names) | ||
| 112 | "Run a test of an OS having MODULE-PACKAGES, which are loaded by creating a | ||
| 113 | service that extends LINUXL-LOADABLE-MODULE-SERVICE-TYPE. Then verify that | ||
| 114 | MODULE-NAMES are loaded in memory." | ||
| 115 | (define module-installing-service-type | ||
| 116 | (service-type | ||
| 117 | (name 'module-installing-service) | ||
| 118 | (extensions (list (service-extension linux-loadable-module-service-type | ||
| 119 | (const module-packages)))) | ||
| 120 | (default-value #f))) | ||
| 121 | (run-loadable-kernel-modules-test-base | ||
| 122 | (operating-system | ||
| 123 | (inherit (simple-operating-system)) | ||
| 124 | (services (cons* (service module-installing-service-type) | ||
| 125 | (operating-system-user-services | ||
| 126 | (simple-operating-system))))) | ||
| 127 | module-names)) | ||
| 128 | |||
| 101 | (define %test-loadable-kernel-modules-0 | 129 | (define %test-loadable-kernel-modules-0 |
| 102 | (system-test | 130 | (system-test |
| 103 | (name "loadable-kernel-modules-0") | 131 | (name "loadable-kernel-modules-0") |
| @@ -129,3 +157,35 @@ with two extra modules.") | |||
| 129 | (package-arguments | 157 | (package-arguments |
| 130 | ddcci-driver-linux)))))) | 158 | ddcci-driver-linux)))))) |
| 131 | '("acpi_call" "ddcci"))))) | 159 | '("acpi_call" "ddcci"))))) |
| 160 | |||
| 161 | (define %test-loadable-kernel-modules-service-0 | ||
| 162 | (system-test | ||
| 163 | (name "loadable-kernel-modules-service-0") | ||
| 164 | (description "Tests loadable kernel modules extensible service with no | ||
| 165 | extra modules.") | ||
| 166 | (value (run-loadable-kernel-modules-service-test '() '())))) | ||
| 167 | |||
| 168 | (define %test-loadable-kernel-modules-service-1 | ||
| 169 | (system-test | ||
| 170 | (name "loadable-kernel-modules-service-1") | ||
| 171 | (description "Tests loadable kernel modules extensible service with one | ||
| 172 | extra module.") | ||
| 173 | (value (run-loadable-kernel-modules-service-test | ||
| 174 | (list ddcci-driver-linux) | ||
| 175 | '("ddcci"))))) | ||
| 176 | |||
| 177 | (define %test-loadable-kernel-modules-service-2 | ||
| 178 | (system-test | ||
| 179 | (name "loadable-kernel-modules-service-2") | ||
| 180 | (description "Tests loadable kernel modules extensible service with two | ||
| 181 | extra modules.") | ||
| 182 | (value (run-loadable-kernel-modules-service-test | ||
| 183 | (list acpi-call-linux-module | ||
| 184 | (package | ||
| 185 | (inherit ddcci-driver-linux) | ||
| 186 | (arguments | ||
| 187 | `(#:linux #f | ||
| 188 | ,@(strip-keyword-arguments '(#:linux) | ||
| 189 | (package-arguments | ||
| 190 | ddcci-driver-linux)))))) | ||
| 191 | '("acpi_call" "ddcci"))))) | ||
