Subject: [PATCH 2/4] gnu: Add kmod-minimal-static.

From: Danny Milosavljevic <[email-masked]>
Date: Sun, 25 Feb 2018 12:48:14 +0100

* gnu/packages/linux.scm (kmod-minimal/static): New variable.
---
 gnu/packages/linux.scm | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 1f8bf3050..b2e47f79a 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -1994,6 +1994,50 @@ from the module-init-tools project.")
                      #t))
                  %standard-phases)))))
 
+(define-public kmod-minimal/static
+  (static-package
+   (package (inherit kmod-minimal)
+    (name "kmod-minimal-static")
+    (version "13")
+    (source (origin
+              (method url-fetch)
+              (uri
+               (string-append "mirror://kernel.org/linux/utils/kernel/kmod/"
+                              "kmod-" version ".tar.xz"))
+              (sha256
+               (base32
+                "0mkrklih0f33c3zc4mkk9qqbzy36r18mj9xffd4wi61gpamx6dkc"))
+              (patches (search-patches "kmod-13-module-directory.patch"))))
+    (arguments
+     (substitute-keyword-arguments
+       (package-arguments (static-package kmod-minimal))
+       ((#:configure-flags flags ''())
+        `(cons* "--disable-manpages" "--disable-static" "--disable-shared" ,flags))
+       ((#:make-flags flags ''())
+        `(cons* "LDFLAGS=-all-static" ,flags))
+       ((#:phases phases '%standard-phases)
+        `(modify-phases ,phases
+          (delete 'install-license-files)
+          (add-after 'unpack 'patch-kmod
+           (lambda _
+             ;; Reduce size by 200 kiB.
+             (substitute* "tools/kmod.c"
+              (("[&]kmod_cmd_compat_lsmod,") "")
+              (("[&]kmod_cmd_compat_rmmod,") "")
+              (("[&]kmod_cmd_compat_insmod,") "")
+              (("[&]kmod_cmd_compat_modinfo,") ""))
+             #t))
+          (replace 'install
+            (lambda* (#:key outputs #:allow-other-keys)
+              (let* ((out (assoc-ref outputs "out"))
+                     (bin (string-append out "/bin")))
+                (install-file "tools/kmod" bin)
+                (for-each
+                 (lambda (tool)
+                   (symlink "kmod" (string-append bin "/" tool)))
+                 '("modprobe" "depmod"))
+                #t))))))))))
+
 (define-public eudev
   ;; The post-systemd fork, maintained by Gentoo.
   (package