guix_mirror_bot pushed a commit to branch master
in repository guix.

commit 8126d92c91e88565afcaaa6963eb90760374d81e
Author: Jelle Licht <[email protected]>
AuthorDate: Thu Oct 15 14:28:10 2026 +0200

    tests: store: Skip kvm GID test when newgidmap cannot map it.
    
    * tests/store.scm (kvm-gid-mappable?): New procedure.
    ("kvm GID is mapped"): Skip unless the "kvm" GID is in the user's
    /etc/subgid ranges since 'newgidmap' refuses to map it otherwise.
---
 tests/store.scm | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tests/store.scm b/tests/store.scm
index ba634ce2205..fce6f444401 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -33,6 +33,9 @@
   #:use-module ((guix serialization)
                 #:hide (store-path read-string))
   #:use-module (guix build utils)
+  #:use-module ((gnu build accounts)
+                #:select (read-subgid subid-entry-name
+                          subid-entry-start subid-entry-count))
   #:use-module ((gnu build linux-container)
                 #:select (unprivileged-user-namespace-supported?))
   #:use-module (guix gexp)
@@ -515,11 +518,29 @@
     (build-derivations %store (list d))
     (call-with-input-file (derivation->output-path d) read)))
 
+(define (kvm-gid-mappable?)
+  "Return true if the daemon can map the \"kvm\" GID for the current user: the
+user must have \"kvm\" among its supplementary groups, and 'newgidmap' requires
+an /etc/subgid range for that user that includes it."
+  (let ((kvm  (group:gid (getgrnam "kvm")))
+        (uid  (getuid))
+        (user (passwd:name (getpwuid (getuid)))))
+    (and (member kvm (vector->list (getgroups)))
+         (any (lambda (entry)
+                (and (member (subid-entry-name entry)
+                             (list user (number->string uid)))
+                     (<= (subid-entry-start entry)
+                         kvm
+                         (+ (subid-entry-start entry)
+                            (subid-entry-count entry) -1))))
+              (read-subgid)))))
+
 (unless (and (unprivileged-user-namespace-supported?)
              (false-if-exception
               (= (stat:gid (stat "/dev/kvm"))
                  (group:gid (getgrnam "kvm"))))
-             (= 1 (status:exit-val (system* "newgidmap"))))
+             (= 1 (status:exit-val (system* "newgidmap")))
+             (false-if-exception (kvm-gid-mappable?)))
   (test-skip 1))
 (test-assert "kvm GID is mapped"
   ;; Ensure that the "kvm" GID is mapped into the build user namespace such

Reply via email to