From: https://issues.guix.gnu.org/72395

From ecdbe1915ce12e411816a7da2b59d48a6619630d Mon Sep 17 00:00:00 2001
Message-ID: <ecdbe1915ce12e411816a7da2b59d48a6619630d.1722425704.git.soeren@soeren-tempel.net>
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren@soeren-tempel.net>
Date: Wed, 31 Jul 2024 05:14:05 +0200
Subject: [PATCH] syscalls: Support musl libc in openpty and login-tty

Contrary to glibc, musl does not define the openpty and login-tty
function in libutil.so. In fact, libutil.so does not exist on musl-based
Linux distributions.  Therefore, on musl-based systems we don't have
to pass any #:library keyword argument to syscall->procedure.
---
 guix/build/syscalls.scm | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 39bcffd516..b92b6955a4 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -2382,8 +2382,10 @@ (define terminal-string-width
         string-length)))                      ;using a statically-linked Guile
 
 (define openpty
-  (let ((proc (syscall->procedure int "openpty" '(* * * * *)
-                                  #:library "libutil")))
+  (let ((proc (if musl-libc?
+                (syscall->procedure int "openpty" '(* * * * *)
+                                    #:library "libutil")
+                (syscall->procedure int "openpty" '(* * * * *)))))
     (lambda ()
       "Return two file descriptors: one for the pseudo-terminal control side,
 and one for the controlled side."
@@ -2404,8 +2406,10 @@ (define openpty
           (values (* head) (* inferior)))))))
 
 (define login-tty
-  (let* ((proc (syscall->procedure int "login_tty" (list int)
-                                   #:library "libutil")))
+  (let* ((proc (if musl-libc?
+                 (syscall->procedure int "login_tty" (list int)
+                                     #:library "libutil")
+                 (syscall->procedure int "login_tty" (list int)))))
     (lambda (fd)
       "Make FD the controlling terminal of the current process (with the
 TIOCSCTTY ioctl), redirect standard input, standard output and standard error

base-commit: 01d4363168ed10ea223047f7a7b83201f161ec0b
