X-Loop: help-debbugs@HIDDEN Subject: [bug#62848] [PATCH] environment: Add --remote option and emacsclient-eshell backend. Resent-From: Antero Mejr <antero@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: ludo@HIDDEN, guix-patches@HIDDEN Resent-Date: Sat, 15 Apr 2023 01:45:01 +0000 Resent-Message-ID: <handler.62848.B.168152308910697 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 62848 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62848 <at> debbugs.gnu.org Cc: ludo@HIDDEN X-Debbugs-Original-To: guix-patches@HIDDEN X-Debbugs-Original-Xcc: ludo@HIDDEN Received: via spool by submit <at> debbugs.gnu.org id=B.168152308910697 (code B ref -1); Sat, 15 Apr 2023 01:45:01 +0000 Received: (at submit) by debbugs.gnu.org; 15 Apr 2023 01:44:49 +0000 Received: from localhost ([127.0.0.1]:47975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1pnUy8-0002mS-Ss for submit <at> debbugs.gnu.org; Fri, 14 Apr 2023 21:44:49 -0400 Received: from lists.gnu.org ([209.51.188.17]:43362) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <antero@HIDDEN>) id 1pnUy6-0002mK-La for submit <at> debbugs.gnu.org; Fri, 14 Apr 2023 21:44:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <antero@HIDDEN>) id 1pnUy6-0007jQ-8E for guix-patches@HIDDEN; Fri, 14 Apr 2023 21:44:46 -0400 Received: from mout-p-103.mailbox.org ([2001:67c:2050:0:465::103]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from <antero@HIDDEN>) id 1pnUy3-0002Nn-SQ for guix-patches@HIDDEN; Fri, 14 Apr 2023 21:44:45 -0400 Received: from smtp2.mailbox.org (unknown [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4Pyx2D2K26z9sTW for <guix-patches@HIDDEN>; Sat, 15 Apr 2023 03:44:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1681523076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Fud33XhSKWquFwTA+snCKPbCHOnxcbM8c4LOw0T+0SU=; b=Zf1U5knKOqI6c4Mj5cRHqXkUESgh9JF9oTigLLoOdwgZXR2utP9MrHdbpWIZfiYd2S3QVc 4/uENfs5yFJIwiNzZ3DOM6jS0JMhJabEDgTipr4Fyb1myP7J0ACVr1bdGAIvoH40vXMeb/ k+bFnD74zYdV98Rr4FS9QLyB/hBbFhQ+hUuVG6jBU13d0GmQT2CnusNJJQQmztC3I3RQzv A1zIuF8eptMfhnrg8XeVOCi8IDz9IhfbFhOHcVDLWyHyV8Ma4m7+Uz5lQv36QhYGEzVqgB A+J8L67cCRhqpqp5SVkE6fMhwL1asdJROGX4j2T74FRzReXYEs6I2NKxDFxyYQ== From: Antero Mejr <antero@HIDDEN> Date: Sat, 15 Apr 2023 01:44:30 +0000 Message-Id: <20230415014430.15466-1-antero@HIDDEN> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-RS-ID: 0565ed057fd7a0bc191 X-MBO-RS-META: mc1tk1zd54a5s58i1r1j3c6awn5cpibg Received-SPF: pass client-ip=2001:67c:2050:0:465::103; envelope-from=antero@HIDDEN; helo=mout-p-103.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.3 (--) * guix/scripts/environment.scm (launch-environment/eshell): New procedure. (guix-environment*): Add logic for remote backend switching. (%options): Add --remote and --list-remote-backends options. (show-environment-options-help): Add help text for new options. * guix/profiles.scm (load-profile)[getenv-proc, setenv-proc, unsetenv-proc]: New optional keyword arguments. (purify-environment)[unsetenv-proc]: New argument. * doc/guix.texi(Invoking guix shell): Document --remote and --list-remote-backends options. --- "guix shell" doesn't support eshell due to eshell's quirks. This change makes environments/profiles more network transparent to support eshell, and maybe other remote environments in the future. doc/guix.texi | 17 ++++++++ guix/profiles.scm | 30 ++++++++------ guix/scripts/environment.scm | 80 ++++++++++++++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 15 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index adb1975935..f609e0c9b6 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6245,6 +6245,23 @@ environment. @itemx -s @var{system} Attempt to build for @var{system}---e.g., @code{i686-linux}. +@item --remote=@var{backend}[=@var{args}] +Create an environment over a remote connection using @var{backend}, +optionally passing @var{args} to the backend. + +This option causes the @option{--container} option to be ignored. + +When @var{backend} is @code{emacsclient-eshell}, a new eshell buffer +with the Guix environment will be opened. An Emacs server must already +be running, and the @code{emacsclient} program must be available. Due +to the way @code{eshell} handles commands, the @var{command} argument, +if specified, will run in the initial @code{eshell} environment instead +of the Guix @code{eshell} environment. + +@item --list-remote-backends +Display the @var{backend} options for @code{guix shell --remote=BACKEND} +and exit. + @item --container @itemx -C @cindex container diff --git a/guix/profiles.scm b/guix/profiles.scm index 03333785f9..1bf6783eea 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -2062,10 +2062,10 @@ (define %precious-variables ;; Environment variables in the default 'load-profile' white list. '("HOME" "USER" "LOGNAME" "DISPLAY" "XAUTHORITY" "TERM" "TZ" "PAGER")) -(define (purify-environment white-list white-list-regexps) +(define (purify-environment white-list white-list-regexps unsetenv-proc) "Unset all environment variables except those that match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE-LIST." - (for-each unsetenv + (for-each unsetenv-proc (remove (lambda (variable) (or (member variable white-list) (find (cut regexp-exec <> variable) @@ -2077,23 +2077,29 @@ (define (purify-environment white-list white-list-regexps) (define* (load-profile profile #:optional (manifest (profile-manifest profile)) #:key pure? (white-list-regexps '()) - (white-list %precious-variables)) + (white-list %precious-variables) + (getenv-proc getenv) (setenv-proc setenv) + (unsetenv-proc unsetenv)) "Set the environment variables specified by MANIFEST for PROFILE. When PURE? is #t, unset the variables in the current environment except those that match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE-LIST. Otherwise, augment existing environment variables with additional search -paths." +paths. +GETENV-PROC is a one-argument procedure that returns an env var value. +SETENV-PROC is a two-argument procedure the sets environment variables. +UNSETENV-PROC is a one-argument procedure that unsets environment variables. +Change those procedures to load a profile over a remote connection." (when pure? - (purify-environment white-list white-list-regexps)) + (purify-environment white-list white-list-regexps unsetenv-proc)) (for-each (match-lambda ((($ <search-path-specification> variable _ separator) . value) - (let ((current (getenv variable))) - (setenv variable - (if (and current (not pure?)) - (if separator - (string-append value separator current) - value) - value))))) + (let ((current (getenv-proc variable))) + (setenv-proc variable + (if (and current (not pure?)) + (if separator + (string-append value separator current) + value) + value))))) (profile-search-paths profile manifest))) (define (profile-regexp profile) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ebfc05731c..7e67cf1d1d 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -53,6 +53,7 @@ (define-module (guix scripts environment) #:autoload (gnu packages bootstrap) (bootstrap-executable %bootstrap-guile) #:autoload (gnu packages package-management) (guix) #:use-module (ice-9 match) + #:use-module (ice-9 popen) #:autoload (ice-9 rdelim) (read-line) #:use-module (ice-9 vlist) #:autoload (web uri) (string->uri uri-scheme) @@ -104,6 +105,13 @@ (define (show-environment-options-help) (display (G_ " -r, --root=FILE make FILE a symlink to the result, and register it as a garbage collector root")) + (display (G_ " + --remote=BACKEND[=ARGS] + create environment over a remote connection by + passing ARGS to BACKEND")) + (display (G_ " + --list-remote-backends + list available remote backends and exit")) (display (G_ " -C, --container run command within an isolated container")) (display (G_ " @@ -283,6 +291,13 @@ (define %options (option '("bootstrap") #f #f (lambda (opt name arg result) (alist-cons 'bootstrap? #t result))) + (option '("remote") #t #f + (lambda (opt name arg result) + (alist-cons 'remote arg result))) + (option '("list-remote-backends") #f #f + (lambda args + (display "emacsclient-eshell\n") + (exit 0))) (append %transformation-options %standard-build-options @@ -715,6 +730,50 @@ (define* (launch-environment/fork command profile manifest ((_ . status) status))))) +(define* (launch-environment/eshell args command profile manifest + #:key pure? (white-list '())) + "Create an new eshell buffer with an environment containing PROFILE, +with the search paths specified by MANIFEST. When PURE?, pre-existing +environment variables are cleared before setting the new ones, except those +matching the regexps in WHITE-LIST." + + (define (escape in) + (string-append "\"" (string-replace-substring in "\"" "\\\"") "\"")) + + (define* (ec cmd #:optional (check? #f)) + (let* ((cmd (string-append "emacsclient " args " -e " (escape cmd))) + (port (open-input-pipe cmd)) + (str (read-line port)) + (code (status:exit-val (close-pipe port)))) + (if (and check? (or (not (eqv? code 0)) (eof-object? str))) + (leave + (G_ "Emacs server connection failed. Is the server running?~%"))) + str)) + + (let ((buf (ec "(buffer-name (eshell t))" #t))) + (define (ec-buf cmd) + (ec (string-append "(with-current-buffer " buf " " cmd ")"))) + + (load-profile + profile manifest #:pure? pure? #:white-list-regexps white-list + #:setenv-proc (lambda (var val) + (ec-buf + (if (string=? var "PATH") + ;; TODO: TRAMP support? + (string-append "(eshell-set-path " (escape val) ")") + (string-append "(setenv " (escape var) " " + (escape val) ")")))) + #:unsetenv-proc (lambda (var) + (ec-buf + (string-append "(setenv " (escape var) ")")))) + + (match command + ((program . args) + (ec-buf + (string-append + "(eshell-command " + (escape (string-append program " " (string-join args)))")")))))) + (define* (launch-environment/container #:key command bash user user-mappings profile manifest link-profile? network? map-cwd? emulate-fhs? nesting? @@ -1081,7 +1140,10 @@ (define (guix-environment* opts) '("/bin/sh") (list %default-shell)))) (mappings (pick-all opts 'file-system-mapping)) - (white-list (pick-all opts 'inherit-regexp))) + (white-list (pick-all opts 'inherit-regexp)) + (remote (match (string-split (assoc-ref opts 'remote) #\=) + ((x) (cons x "")) + ((x . y) (cons x (string-join y)))))) (define store-needed? ;; Whether connecting to the daemon is needed. @@ -1119,6 +1181,10 @@ (define-syntax-rule (with-store/maybe store exp ...) (when (pair? symlinks) (leave (G_ "'--symlink' cannot be used without '--container~%'")))) + (when (and remote (not (member (car remote) '("emacsclient-eshell")))) + (leave + (G_ "Invalid remote backend, see --list-remote-backends for options.~%'"))) + (with-store/maybe store (with-status-verbosity (assoc-ref opts 'verbosity) (define manifest-from-opts @@ -1172,15 +1238,23 @@ (define manifest (mwhen (assoc-ref opts 'check?) (return - (if container? + (if (or container? remote) (warning (G_ "'--check' is unnecessary \ -when using '--container'; doing nothing~%")) +when using '--container' or '--remote'; doing nothing~%")) (validate-child-shell-environment profile manifest)))) (cond ((assoc-ref opts 'search-paths) (show-search-paths profile manifest #:pure? pure?) (return #t)) + (remote + (match (car remote) + ("emacsclient-eshell" + (return + (launch-environment/eshell (cdr remote) + command profile manifest + #:white-list white-list + #:pure? pure?))))) (container? (let ((bash-binary (if bootstrap? -- 2.39.2
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Antero Mejr <antero@HIDDEN> Subject: bug#62848: Acknowledgement ([PATCH] environment: Add --remote option and emacsclient-eshell backend.) Message-ID: <handler.62848.B.168152308910697.ack <at> debbugs.gnu.org> References: <20230415014430.15466-1-antero@HIDDEN> X-Gnu-PR-Message: ack 62848 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 62848 <at> debbugs.gnu.org Date: Sat, 15 Apr 2023 01:45:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. As you requested using X-Debbugs-CC, your message was also forwarded to ludo@HIDDEN (after having been given a bug report number, if it did not have one). Your message has been sent to the package maintainer(s): guix-patches@HIDDEN If you wish to submit further information on this problem, please send it to 62848 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 62848: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D62848 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: [bug#62848] [PATCH] environment: Add --remote option and emacsclient-eshell backend. Resent-From: Maxim Cournoyer <maxim.cournoyer@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: guix-patches@HIDDEN Resent-Date: Fri, 01 Sep 2023 13:27:02 +0000 Resent-Message-ID: <handler.62848.B62848.169357478221450 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 62848 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Antero Mejr <antero@HIDDEN> Cc: ludo@HIDDEN, 62848 <at> debbugs.gnu.org Received: via spool by 62848-submit <at> debbugs.gnu.org id=B62848.169357478221450 (code B ref 62848); Fri, 01 Sep 2023 13:27:02 +0000 Received: (at 62848) by debbugs.gnu.org; 1 Sep 2023 13:26:22 +0000 Received: from localhost ([127.0.0.1]:60092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1qc4AH-0005Zt-TU for submit <at> debbugs.gnu.org; Fri, 01 Sep 2023 09:26:22 -0400 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]:61494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <maxim.cournoyer@HIDDEN>) id 1qc4AF-0005Zf-Vy for 62848 <at> debbugs.gnu.org; Fri, 01 Sep 2023 09:26:20 -0400 Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-4132c2cee1dso12580101cf.2 for <62848 <at> debbugs.gnu.org>; Fri, 01 Sep 2023 06:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693574765; x=1694179565; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=VyL4pPZy03dX9IZElkzUd9AO1PgBySH6zoMzwdzZuW8=; b=D6UgRoIQVrZJkOfL8RJRRasEiBvWO2fwmhYBEh/AwZmGbysrgvnZfQzHraS6SqCmc9 cO9OPB7v1vYaOd6FQqRVJGwSVgdCACD4BFFe52qcz2ocUrlxNS3n2OoWJ9PL6j2rzTQF xC+YCDi5PiQzWu9M09VK6ZEIjWvKmbF7tksK/qQacHanmSwZgRmdMuv4C4fUFZfsOFAx LUcirFMnan9zwkM9S+c3JkLZpyOmYl4u4h0PeaFm2kHst7sclxDsA4SFBEAZsJ0NdwZQ YmThA3QNaKHNSojvFI8367aOtfXxI91Zg46BUYVFAmxbU7FTrwD6HlevcARtyUlyoJjN ig6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693574765; x=1694179565; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VyL4pPZy03dX9IZElkzUd9AO1PgBySH6zoMzwdzZuW8=; b=lk78Mp5YzRGmssXfQBW2YxrhCph4f5XEt1Uleq80x6udewPLU91cMa+dotcoBliHwo 9Zdp7QtCF19s4GcH2hR4IKDcgwC8LIpxp+r1Z7YzCB79ChhKshEd9yefJC7S505M2ax+ eUw7uySfQJIfyxpP6Ly7FkLCB/e9bVLZK+klXm7b9NpYNXV9+/G2zX75nOPFSxjbuJD0 0fxoTuY2HaI3jvHYYD2P2rsBh8lNglunam5uKiGrqGsBqBAXCDf7G5LrWfqTLynSy5cw n1r02gAHaJ2GM8/BBLscJTW0YSUEq2CVhZAsY0rNDMPGEw/Sl/Bxre0bsqR7DCQwmQpY AKXg== X-Gm-Message-State: AOJu0YxpCu2phvtvY/Gik3dc1b70DshxLdflvEGIp+H8g4t5PgJM6Uvj l6lFhDpswBQ1BUQfi1Ns+Ss= X-Google-Smtp-Source: AGHT+IEyDWtwPXU1URnnba0iWfJ+iEA2xhVH31j2VUFlw969ed6x4B88NzCQ7JaUDuRnstuoJGZ0zg== X-Received: by 2002:a05:6214:5c43:b0:64f:8bb4:9586 with SMTP id lz3-20020a0562145c4300b0064f8bb49586mr2175012qvb.61.1693574765117; Fri, 01 Sep 2023 06:26:05 -0700 (PDT) Received: from hurd (dsl-154-228.b2b2c.ca. [66.158.154.228]) by smtp.gmail.com with ESMTPSA id a4-20020a0ce344000000b0064f4ac061b0sm1438255qvm.12.2023.09.01.06.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:26:04 -0700 (PDT) From: Maxim Cournoyer <maxim.cournoyer@HIDDEN> References: <20230415014430.15466-1-antero@HIDDEN> Date: Fri, 01 Sep 2023 09:26:03 -0400 In-Reply-To: <20230415014430.15466-1-antero@HIDDEN> (Antero Mejr's message of "Sat, 15 Apr 2023 01:44:30 +0000") Message-ID: <877cpa3tzo.fsf@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Hi Antero, Antero Mejr <antero@HIDDEN> writes: > * guix/scripts/environment.scm (launch-environment/eshell): New procedure. > (guix-environment*): Add logic for remote backend switching. > (%options): Add --remote and --list-remote-backends options. > (show-environment-options-help): Add help text for new options. > * guix/profiles.scm (load-profile)[getenv-proc, setenv-proc, unsetenv-proc]: > New optional keyword arguments. > (purify-environment)[unsetenv-proc]: New argument. > * doc/guix.texi(Invoking guix shell): Document --remote and > --list-remote-backends options. This looks interesting! [...] > +(define* (launch-environment/eshell args command profile manifest > + #:key pure? (white-list '())) Maybe use the modern allow-list / block-list terminology. > + "Create an new eshell buffer with an environment containing PROFILE, > +with the search paths specified by MANIFEST. When PURE?, pre-existing > +environment variables are cleared before setting the new ones, except those > +matching the regexps in WHITE-LIST." > + > + (define (escape in) > + (string-append "\"" (string-replace-substring in "\"" "\\\"") "\"")) > + > + (define* (ec cmd #:optional (check? #f)) ^ Shouldn't we always check for errors? When is it useful to let them through? > + (let* ((cmd (string-append "emacsclient " args " -e " (escape cmd))) Instead of having to escape stuff, it'd be better to avoid using a shell for the invocation by opening the pipe with (open-pipe* OPEN_READ prog arg ...). There's an example if you grep for 'with-input-pipe-to-string' in the update-guix-package.scm file. This should make the rest of the code more readable. > + (port (open-input-pipe cmd)) > + (str (read-line port)) > + (code (status:exit-val (close-pipe port)))) > + (if (and check? (or (not (eqv? code 0)) (eof-object? str))) ^ (zero? code) > + (leave > + (G_ "Emacs server connection failed. Is the server running?~%"))) > + str)) > + > + (let ((buf (ec "(buffer-name (eshell t))" #t))) > + (define (ec-buf cmd) > + (ec (string-append "(with-current-buffer " buf " " cmd ")"))) > + > + (load-profile > + profile manifest #:pure? pure? #:white-list-regexps white-list > + #:setenv-proc (lambda (var val) > + (ec-buf > + (if (string=? var "PATH") > + ;; TODO: TRAMP support? > + (string-append "(eshell-set-path " (escape val) ")") > + (string-append "(setenv " (escape var) " " > + (escape val) ")")))) > + #:unsetenv-proc (lambda (var) > + (ec-buf > + (string-append "(setenv " (escape var) ")")))) > + > + (match command > + ((program . args) > + (ec-buf > + (string-append > + "(eshell-command " > + (escape (string-append program " " (string-join args)))")")))))) > + > (define* (launch-environment/container #:key command bash user user-mappings > profile manifest link-profile? network? > map-cwd? emulate-fhs? nesting? > @@ -1081,7 +1140,10 @@ (define (guix-environment* opts) > '("/bin/sh") > (list %default-shell)))) > (mappings (pick-all opts 'file-system-mapping)) > - (white-list (pick-all opts 'inherit-regexp))) > + (white-list (pick-all opts 'inherit-regexp)) > + (remote (match (string-split (assoc-ref opts 'remote) #\=) > + ((x) (cons x "")) Why is this needed? > + ((x . y) (cons x (string-join y)))))) If using open-pipe* as suggested above, all the arguments could be kept as a list. > > (define store-needed? > ;; Whether connecting to the daemon is needed. > @@ -1119,6 +1181,10 @@ (define-syntax-rule (with-store/maybe store exp ...) > (when (pair? symlinks) > (leave (G_ "'--symlink' cannot be used without '--container~%'")))) > > + (when (and remote (not (member (car remote) '("emacsclient-eshell")))) > + (leave > + (G_ "Invalid remote backend, see --list-remote-backends for options.~%'"))) This code and the --list-remote-backends associated procedure could share a same %supported-backends list containing currently just '("emacsclient-eshell"). > (with-store/maybe store > (with-status-verbosity (assoc-ref opts 'verbosity) > (define manifest-from-opts > @@ -1172,15 +1238,23 @@ (define manifest > > (mwhen (assoc-ref opts 'check?) > (return > - (if container? > + (if (or container? remote) > (warning (G_ "'--check' is unnecessary \ > -when using '--container'; doing nothing~%")) > +when using '--container' or '--remote'; doing nothing~%")) > (validate-child-shell-environment profile manifest)))) > > (cond > ((assoc-ref opts 'search-paths) > (show-search-paths profile manifest #:pure? pure?) > (return #t)) > + (remote > + (match (car remote) > + ("emacsclient-eshell" > + (return > + (launch-environment/eshell (cdr remote) > + command profile manifest > + #:white-list white-list > + #:pure? pure?))))) > (container? > (let ((bash-binary > (if bootstrap? It'd be nice to have a functional test for it; some inspiration could be taken from tests/build-emacs-utils.scm, which skips the test if emacs is not available. Thanks for this contribution! Could you please send a v2 taking into account the above comments? -- Thanks, Maxim
Received: (at control) by debbugs.gnu.org; 5 Sep 2023 11:37:23 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue Sep 05 07:37:23 2023 Received: from localhost ([127.0.0.1]:54551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1qdUN1-0003TO-J1 for submit <at> debbugs.gnu.org; Tue, 05 Sep 2023 07:37:23 -0400 Received: from mira.cbaines.net ([212.71.252.8]:42886) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <mail@HIDDEN>) id 1qdUMz-0003TF-K1 for control <at> debbugs.gnu.org; Tue, 05 Sep 2023 07:37:22 -0400 Received: from localhost (unknown [217.155.61.229]) by mira.cbaines.net (Postfix) with ESMTPSA id 72E1C27BBE2 for <control <at> debbugs.gnu.org>; Tue, 5 Sep 2023 12:37:20 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 54bc693a for <control <at> debbugs.gnu.org>; Tue, 5 Sep 2023 11:37:20 +0000 (UTC) From: Christopher Baines <mail@HIDDEN> To: control <at> debbugs.gnu.org Subject: tag 62848 moreinfo Date: Tue, 05 Sep 2023 11:37:20 +0000 Message-ID: <87zg20n95b.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) tags 62848 + moreinfo quit
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.