From patchwork Sun Feb 24 16:18:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 1233 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D7A3A16C97; Sun, 24 Feb 2019 16:20:12 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 7DBB516C20 for ; Sun, 24 Feb 2019 16:20:12 +0000 (GMT) Received: from localhost ([127.0.0.1]:53052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVf-0002Pe-Vu for patchwork@mira.cbaines.net; Sun, 24 Feb 2019 11:20:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVY-0002OJ-PS for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxwVX-0005ko-Hd for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxwVX-0005kP-A3 for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gxwVX-0003G8-1w for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#34638] [PATCH 4/4] inferior: Add 'open-inferior/container'. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Feb 2019 16:20:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34638 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 34638@debbugs.gnu.org Received: via spool by 34638-submit@debbugs.gnu.org id=B34638.155102514612434 (code B ref 34638); Sun, 24 Feb 2019 16:20:03 +0000 Received: (at 34638) by debbugs.gnu.org; 24 Feb 2019 16:19:06 +0000 Received: from localhost ([127.0.0.1]:50387 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUb-0003ET-P5 for submit@debbugs.gnu.org; Sun, 24 Feb 2019 11:19:06 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:52262 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUU-0003DQ-O0 for 34638@debbugs.gnu.org; Sun, 24 Feb 2019 11:19:00 -0500 Received: from localhost (cpc102582-walt20-2-0-cust14.13-2.cable.virginm.net [86.27.34.15]) by mira.cbaines.net (Postfix) with ESMTPSA id 9449B16C97 for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:57 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 510293e9 for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:55 +0000 (UTC) From: Christopher Baines Date: Sun, 24 Feb 2019 16:18:55 +0000 Message-Id: <20190224161855.2632-4-mail@cbaines.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190224161855.2632-1-mail@cbaines.net> References: <20190224161855.2632-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches --- guix/inferior.scm | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/guix/inferior.scm b/guix/inferior.scm index cf72454426..a5f773c147 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -40,6 +40,9 @@ #:use-module (guix store) #:use-module (guix derivations) #:use-module (guix base32) + #:use-module (gnu system file-systems) + #:use-module (gnu build linux-container) + #:use-module (guix build syscalls) #:use-module (gcrypt hash) #:autoload (guix cache) (maybe-remove-expired-cache-entries) #:autoload (guix ui) (show-what-to-build*) @@ -54,6 +57,7 @@ #:use-module ((rnrs bytevectors) #:select (string->utf8)) #:export (inferior? open-inferior + open-inferior/container port->inferior close-inferior inferior-eval @@ -137,6 +141,67 @@ it's an old Guix." ((@ (guix scripts repl) machine-repl)))))) pipe))) +(define* (open-inferior/container store guix-store-item + #:key + (command "bin/guix") + (share-host-network? #f) + (extra-shared-directories '()) + (extra-environment-variables '())) + (define requisite-store-items + (requisites store (list guix-store-item))) + + (define shared-directory + (mkdtemp! (string-append (or (getenv "TMPDIR") "/tmp") + "/guix-inferior.XXXXXX"))) + + (define mappings + (append + (map (lambda (dir) + (file-system-mapping + (source dir) + (target dir) + (writable? #f))) + `(;; Share a directory, used in inferior-eval-with-store + ,shared-directory + ,@requisite-store-items + ,@extra-shared-directories)) + (if share-host-network? + %network-file-mappings + '()))) + + (define mounts + (append %container-file-systems + (map file-system-mapping->bind-mount + mappings))) + + (define (inferior-pipe/container store + guix-store-item + shared-directory + command) + (start-child-in-container + (list (string-append guix-store-item "/bin/guix") + ;; TODO I'm not sure why "repl" is duplicated in the following + ;; command + "repl" "repl" "-t" "machine") + #:read? #t + #:write? #t + #:mounts mounts + #:namespaces (if share-host-network? + (delq 'net %namespaces) + %namespaces) + #:extra-environment-variables + `(;; Set HOME, so that the (guix profiles) module can be loaded, without it + ;; trying to read from /etc/passwd + "HOME=/tmp" + ,@extra-environment-variables))) + + (port->inferior (inferior-pipe/container store + guix-store-item + shared-directory + command) + shared-directory + close-pipe)) + (define* (port->inferior pipe shared-directory #:optional (close close-port)) "Given PIPE, an input/output port, return an inferior that talks over PIPE. PIPE is closed with CLOSE when 'close-inferior' is called on the returned