From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id ABm9Brrm8WTq6gAA9RJhRA:P1 (envelope-from ) for ; Fri, 01 Sep 2023 15:27:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id ABm9Brrm8WTq6gAA9RJhRA (envelope-from ) for ; Fri, 01 Sep 2023 15:27:22 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BBC0E5657F for ; Fri, 1 Sep 2023 15:27:21 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=D6UgRoIQ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1693574841; a=rsa-sha256; cv=none; b=FirodKFizKTgwuwMiT37Xr8xKvzEdDFpNlFkUrcQQE6CfD+qvMtBd/UMorajGB3nC9B0kw U0xHa7xnZYx4rjySXgcwdBEn6cyAtJnd/apH07L123AkTpqNHh3Sta5eMLB2swLqc8o8vv KQ5R0eP5VgWhVxXYP47S8d7Q9YyWeLG0ymcSRLV47RX4ukf0aN4ritP5Eiu3zlNM5zJLFC S12vXyUfuvGqC7Z1mL3eke228cgaEbrlViVteXyrHus0z95hoV8jNi+2uGjFNUxGVfAf4T es+lCJalj6gU383xXwH0r0tr8RriUMdt4b3jSq+GpMoxYVReUYBtWJqh4/6tfg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=D6UgRoIQ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1693574841; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=VyL4pPZy03dX9IZElkzUd9AO1PgBySH6zoMzwdzZuW8=; b=PlE+1a6H+bVvC9A28s59AfosZarXwh9D+12xf05rjKdH00AK9WJUh6gcTQiwx3mpqWH5tM N3fXqyY+f0/khqrF7nzUsc95v/TYwZjlE2RDftEDXTGjJZIyIzjrtdTfEmXd2BN6jsymRr TdBKuX0NsmmG6a4Nm2BA0FpHw5AG8Y+NMmhHLte618wj4KVf6o93Nq5Ths/Sl6dZd69tfN t/D6tzJBRWnBuIgisUV8DkLZBYcdXsCR3INz0UqTqOn86a99YDwtEPUxQcszeUUqQyHw0X 1LM+bdCZ4KgPgCRe33kcjybtv0fYLPfpwQ+Af1xY8xaB6kY1jcX/omJCRLQOJA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qc4B4-0001gB-39; Fri, 01 Sep 2023 09:27:12 -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 ) id 1qc4Ao-0001e3-5J for guix-patches@gnu.org; Fri, 01 Sep 2023 09:26:55 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qc4An-0006Fp-0U for guix-patches@gnu.org; Fri, 01 Sep 2023 09:26:53 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qc4Aw-0005ap-5K for guix-patches@gnu.org; Fri, 01 Sep 2023 09:27:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62848] [PATCH] environment: Add --remote option and emacsclient-eshell backend. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 01 Sep 2023 13:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62848 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Antero Mejr Cc: ludo@gnu.org, 62848@debbugs.gnu.org Received: via spool by 62848-submit@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 ) id 1qc4AH-0005Zt-TU for submit@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 ) id 1qc4AF-0005Zf-Vy for 62848@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@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 References: <20230415014430.15466-1-antero@mailbox.org> Date: Fri, 01 Sep 2023 09:26:03 -0400 In-Reply-To: <20230415014430.15466-1-antero@mailbox.org> (Antero Mejr's message of "Sat, 15 Apr 2023 01:44:30 +0000") Message-ID: <877cpa3tzo.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.12 X-Spam-Score: -5.12 X-Migadu-Queue-Id: BBC0E5657F X-Migadu-Scanner: mx2.migadu.com X-TUID: Vnv1u1F4OKdO Hi Antero, Antero Mejr 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