From patchwork Sun Feb 24 16:18:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 1232 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 13C5E16C96; Sun, 24 Feb 2019 16:20:10 +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 AF41416C20 for ; Sun, 24 Feb 2019 16:20:09 +0000 (GMT) Received: from localhost ([127.0.0.1]:53044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVd-0002OV-0p for patchwork@mira.cbaines.net; Sun, 24 Feb 2019 11:20:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVX-0002O8-9k for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxwVW-0005ir-Bg for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxwVW-0005iP-6E for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gxwVV-0003Ft-Te for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#34638] [PATCH 1/4] utils: Add #:base-directory to call-with-temporary-directory. References: <875zt9go87.fsf@cbaines.net> In-Reply-To: <875zt9go87.fsf@cbaines.net> Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Feb 2019 16:20:01 +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.155102514112404 (code B ref 34638); Sun, 24 Feb 2019 16:20:01 +0000 Received: (at 34638) by debbugs.gnu.org; 24 Feb 2019 16:19:01 +0000 Received: from localhost ([127.0.0.1]:50383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUX-0003Dt-0u for submit@debbugs.gnu.org; Sun, 24 Feb 2019 11:19:01 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:52268 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUU-0003DU-Qd for 34638@debbugs.gnu.org; Sun, 24 Feb 2019 11:18:59 -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 88ADB16C20 for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:56 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id bddd0a77 for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:55 +0000 (UTC) From: Christopher Baines Date: Sun, 24 Feb 2019 16:18:52 +0000 Message-Id: <20190224161855.2632-1-mail@cbaines.net> X-Mailer: git-send-email 2.20.1 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 This allows more easily creating temporary directories within a specific directory. This is motivated by using this in inferior-eval-with-store. * guix/utils.scm (call-with-temporary-directory): Add optional keyword argument, base-directory. --- guix/utils.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guix/utils.scm b/guix/utils.scm index ed1a418cca..abeb156f40 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -620,10 +620,10 @@ call." (false-if-exception (close out)) (false-if-exception (delete-file template)))))) -(define (call-with-temporary-directory proc) +(define* (call-with-temporary-directory proc #:key base-directory) "Call PROC with a name of a temporary directory; close the directory and delete it when leaving the dynamic extent of this call." - (let* ((directory (or (getenv "TMPDIR") "/tmp")) + (let* ((directory (or base-directory (getenv "TMPDIR") "/tmp")) (template (string-append directory "/guix-directory.XXXXXX")) (tmp-dir (mkdtemp! template))) (dynamic-wind From patchwork Sun Feb 24 16:18:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 1234 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 6712316C97; Sun, 24 Feb 2019 16:20:16 +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 EC13B16C20 for ; Sun, 24 Feb 2019 16:20:15 +0000 (GMT) Received: from localhost ([127.0.0.1]:53059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVj-0002SQ-Gx for patchwork@mira.cbaines.net; Sun, 24 Feb 2019 11:20:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVZ-0002Ob-LS for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxwVY-0005l7-0C for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36848) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxwVX-0005ku-OK 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-0003GF-IC for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#34638] [PATCH 2/4] linux-container: Add 'start-child-in-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.155102514612441 (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]:50389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUc-0003EV-2W for submit@debbugs.gnu.org; Sun, 24 Feb 2019 11:19:06 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:52266 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUU-0003DT-QZ 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 017B616C4B for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:56 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id f8498cad for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:55 +0000 (UTC) From: Christopher Baines Date: Sun, 24 Feb 2019 16:18:53 +0000 Message-Id: <20190224161855.2632-2-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 This new procedure is similar to open-pipe* in (ice-9 popen), but using run-container from (gnu build linux-container). * gnu/build/linux-container.scm (start-child-in-container): New procedure. --- gnu/build/linux-container.scm | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index 65e1325577..63c83902e4 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -32,6 +32,7 @@ setgroups-supported? %namespaces run-container + start-child-in-container call-with-container container-excursion container-excursion*)) @@ -210,6 +211,87 @@ corresponds to the symbols in NAMESPACES." ('net CLONE_NEWNET)) namespaces))) +(define* (start-child-in-container command + #:key read? write? + (root 'temporary) + (mounts '()) + (namespaces %namespaces) + (host-uids 1) + (extra-environment-variables '())) + (define (with-root-directory f) + (if (eq? root 'temporary) + (call-with-temporary-directory f) + (f root))) + + ;; (ice-9 popen) internals + (define make-rw-port (@@ (ice-9 popen) make-rw-port)) + (define pipe-guardian (@@ (ice-9 popen) pipe-guardian)) + (define make-pipe-info (@@ (ice-9 popen) make-pipe-info)) + + ;; car is the inport port, cdr is the output port. You write to the output + ;; port, and read from the input port. + (define child-to-parent-pipe + (if read? + (pipe) + #f)) + + (define parent-to-child-pipe + (if write? + (pipe) + #f)) + + (define (run-program) + (when read? + (match child-to-parent-pipe + ((input-port . output-port) + ;; close the output part of the child-to-parent-pipe, as this is used + ;; by the parent process + (close-port input-port) + + ;; Make the input part of the child-to-parent-pipe the standard + ;; output of this process + (dup2 (fileno output-port) 1)))) + + (when write? + (match parent-to-child-pipe + ((input-port . output-port) + ;; close the input part of the parent-to-child-pipe, as this is used + ;; by the parent processs + (close-port output-port) + + ;; Make the output part of the parent-to-child-pipe the standard + ;; input of this process + (dup2 (fileno input-port) 0)))) + + ;; TODO Maybe close all file descriptors, as start_child in Guile does? + + (for-each putenv extra-environment-variables) + + (apply execlp command)) + + (with-root-directory + (lambda (root) + (let ((pid (run-container root mounts namespaces host-uids run-program))) + ;; Catch SIGINT and kill the container process. + (sigaction SIGINT + (lambda (signum) + (false-if-exception + (kill pid SIGKILL)))) + + (let* ((read-port (and=> child-to-parent-pipe car)) + (write-port (and=> parent-to-child-pipe cdr)) + + (port (or (and read-port write-port + (make-rw-port read-port write-port)) + read-port + write-port)) + (pipe-info (make-pipe-info pid))) + + (pipe-guardian pipe-info) + (%set-port-property! port 'popen-pipe-info pipe-info) + + port))))) + (define (run-container root mounts namespaces host-uids thunk) "Run THUNK in a new container process and return its PID. ROOT specifies the root directory for the container. MOUNTS is a list of From patchwork Sun Feb 24 16:18:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 1235 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 E35A016C96; Sun, 24 Feb 2019 16:20:17 +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 823BA16C20 for ; Sun, 24 Feb 2019 16:20:17 +0000 (GMT) Received: from localhost ([127.0.0.1]:53070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVl-0002Vt-39 for patchwork@mira.cbaines.net; Sun, 24 Feb 2019 11:20:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxwVY-0002OI-B8 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 1gxwVW-0005jh-VQ for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxwVW-0005jO-M8 for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gxwVW-0003G0-Gm for guix-patches@gnu.org; Sun, 24 Feb 2019 11:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#34638] [PATCH 3/4] inferior: Add a shared-directory field to Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Feb 2019 16:20:02 +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.155102514112416 (code B ref 34638); Sun, 24 Feb 2019 16:20:02 +0000 Received: (at 34638) by debbugs.gnu.org; 24 Feb 2019 16:19:01 +0000 Received: from localhost ([127.0.0.1]:50385 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUX-0003E1-C8 for submit@debbugs.gnu.org; Sun, 24 Feb 2019 11:19:01 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:52264 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gxwUU-0003DS-O2 for 34638@debbugs.gnu.org; Sun, 24 Feb 2019 11:18:59 -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 49ABE16C96 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 ccada29c for <34638@debbugs.gnu.org>; Sun, 24 Feb 2019 16:18:55 +0000 (UTC) From: Christopher Baines Date: Sun, 24 Feb 2019 16:18:54 +0000 Message-Id: <20190224161855.2632-3-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 | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/guix/inferior.scm b/guix/inferior.scm index 027418a98d..cf72454426 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -97,14 +97,15 @@ ;; Inferior Guix process. (define-record-type - (inferior pid socket close version packages table) + (inferior pid socket close shared-directory version packages table) inferior? - (pid inferior-pid) - (socket inferior-socket) - (close inferior-close-socket) ;procedure - (version inferior-version) ;REPL protocol version - (packages inferior-package-promise) ;promise of inferior packages - (table inferior-package-table)) ;promise of vhash + (pid inferior-pid) + (socket inferior-socket) + (close inferior-close-socket) ;procedure + (shared-directory inferior-shared-directory) + (version inferior-version) ;REPL protocol version + (packages inferior-package-promise) ;promise of inferior packages + (table inferior-package-table)) ;promise of vhash (define (inferior-pipe directory command) "Return an input/output pipe on the Guix instance in DIRECTORY. This runs @@ -136,7 +137,7 @@ it's an old Guix." ((@ (guix scripts repl) machine-repl)))))) pipe))) -(define* (port->inferior pipe #:optional (close close-port)) +(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 inferior." @@ -144,7 +145,8 @@ inferior." (match (read pipe) (('repl-version 0 rest ...) - (letrec ((result (inferior 'pipe pipe close (cons 0 rest) + (letrec ((result (inferior 'pipe pipe close shared-directory + (cons 0 rest) (delay (%inferior-packages result)) (delay (%inferior-package-table result))))) (inferior-eval '(use-modules (guix)) result) @@ -162,7 +164,7 @@ equivalent. Return #f if the inferior could not be launched." (define pipe (inferior-pipe directory command)) - (port->inferior pipe close-pipe)) + (port->inferior pipe #f close-pipe)) (define (close-inferior inferior) "Close INFERIOR." @@ -479,7 +481,8 @@ thus be the code of a one-argument procedure that accepts a store." ((client . address) (proxy client (store-connection-socket store)))) (close-port socket) - (read-inferior-response inferior))))) + (read-inferior-response inferior))) + #:base-directory (inferior-shared-directory inferior))) (define* (inferior-package-derivation store package #:optional 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