From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#20239: [PATCH 3/4] services: qemu-binfmt: Extend guix-daemon with extra chroot directories. Date: Tue, 9 Jan 2018 17:14:26 +0100 Message-ID: <20180109161427.28836-4-ludo@gnu.org> References: <87tw6d1j7a.fsf@gnu.org> <20180109161427.28836-1-ludo@gnu.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYwYL-0001GJ-4h for bug-guix@gnu.org; Tue, 09 Jan 2018 11:15:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYwYI-0006tR-Bo for bug-guix@gnu.org; Tue, 09 Jan 2018 11:15:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:34661) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eYwYI-0006tK-8B for bug-guix@gnu.org; Tue, 09 Jan 2018 11:15:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eYwYI-0000aO-33 for bug-guix@gnu.org; Tue, 09 Jan 2018 11:15:02 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20180109161427.28836-1-ludo@gnu.org> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 20239@debbugs.gnu.org Fixes . * gnu/services/virtualization.scm ()[guix-support?]: New field. (qemu-binfmt-guix-chroot): New procedure. (qemu-binfmt-service-type)[extensions]: Add GUIX-SERVICE-TYPE. * doc/guix.texi (Virtualization Services): Document 'guix-support?'. --- doc/guix.texi | 29 +++++++++++++++++++++++++++++ gnu/services/virtualization.scm | 16 ++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5c836ae96..85d95c4da 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -17698,6 +17698,35 @@ This is the configuration for the @code{qemu-binfmt} service. The list of emulated QEMU platforms. Each item must be a @dfn{platform object} as returned by @code{lookup-qemu-platforms} (see below). +@item @code{guix-support?} (default: @code{#f}) +When it is true, QEMU and all its dependencies are added to the build +environment of @command{guix-daemon} (@pxref{Invoking guix-daemon, +@code{--chroot-directory} option}). This allows the @code{binfmt_misc} +handlers to be used within the build environment, which in turn means +that you can transparently build programs for another architecture. + +For example, let's suppose you're on an x86_64 machine and you have this +service: + +@example +(service qemu-binfmt-service-type + (qemu-binfmt-configuration + (platforms (lookup-qemu-platforms "arm")) + (qemu-support? #t))) +@end example + +You can run: + +@example +guix build -s armhf-linux inkscape +@end example + +@noindent +and it will build Inkscape for ARMv7 @emph{as if it were a native +build}, transparently using QEMU to emulate the ARMv7 CPU. Pretty handy +if you'd like to test a package build for an architecture you don't have +access to! + @item @code{qemu} (default: @code{qemu}) The QEMU package to use. @end table diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index ac6afe043..f716de622 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -662,7 +662,9 @@ potential infinite waits blocking libvirt.")) (qemu qemu-binfmt-configuration-qemu (default qemu)) (platforms qemu-binfmt-configuration-platforms - (default '()))) ;safest default + (default '())) ;safest default + (guix-support? qemu-binfmt-configuration-guix-support? + (default #f))) (define (qemu-platform->binfmt qemu platform) "Return a gexp that evaluates to a binfmt string for PLATFORM, using the @@ -724,6 +726,14 @@ given QEMU package." '#$(map qemu-platform-name platforms)) #f))))))) +(define qemu-binfmt-guix-chroot + (match-lambda + ;; Add QEMU and its dependencies to the guix-daemon chroot so that our + ;; binfmt_misc handlers work in the chroot (otherwise 'execve' would fail + ;; with ENOENT.) + (($ qemu platforms guix?) + (if guix? (list qemu) '())))) + (define qemu-binfmt-service-type ;; TODO: Make a separate binfmt_misc service out of this? (service-type (name 'qemu-binfmt) @@ -731,7 +741,9 @@ given QEMU package." (list (service-extension file-system-service-type (const (list %binfmt-file-system))) (service-extension shepherd-root-service-type - qemu-binfmt-shepherd-services))) + qemu-binfmt-shepherd-services) + (service-extension guix-service-type + qemu-binfmt-guix-chroot))) (default-value (qemu-binfmt-configuration)) (description "This service supports transparent emulation of binaries -- 2.15.1