help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: local emacsclient to remote emacs server


From: Felix Dietrich
Subject: Re: local emacsclient to remote emacs server
Date: Sun, 27 Mar 2022 05:58:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

t@fullmeta.me writes:

> I would like to be able to use said remote machine for all my dev
> work. Of course the selling point of Guix is that you can setup
> reproducible and minimal execution environments for your code and
> hacking - think Virtualenv pushed to its logical conclusion. So,
> typically I'd do the following:
>
> 1. mkdir myproj
> 2. drop a manifest.scm or guix.scm script inside that has input packages and 
> sets up services, possibly entire OS definition in system.scm
> 3. spawn this programmed environment `guix shell -D -f guix.scm` or
> inside a container `guix shell -c` or if I really need to be close to
> production or run services spawn entire OS in a container `guix system
> -c system.scm`
> 4. start Emacs inside that environment
>
> Now, do you see the problem with TRAMP? TRAMP is essentially an SSH
> session spawned from local Emacs already running. It ends up talking
> to your login shell over ssh basically. […] There needs to be some
> kind of "hop" or additional step after TRAMP establishes an ssh
> connection that puts its shell in appropriate environment. Is there a
> way to do that?

I played around with Guix and Tramp a little over the last days.  Canʼt
say that I am not still confused, and canʼt really explain much of the
working of the following snippet, but maybe it can still serve you as a
base for your customisations – at least until someone comes up with a
proper solution.

  #+begin_src emacs-lisp
    (connection-local-set-profile-variables 'guix-shell-own-path-profile
      '((tramp-remote-path . (tramp-own-remote-path))))
  
    (connection-local-set-profiles
     '(:application tramp :protocol "guix-shell")
     'guix-shell-own-path-profile)
  
    (require 'tramp)
    (add-to-list 'tramp-methods
                 `("guix-shell"
                   (tramp-login-program "guix")
                   (tramp-login-args (("shell")
                                      ("-m")
                                      ("projects/%u/manifest.scm")))
                   (tramp-remote-shell "/bin/sh")
                   (tramp-remote-shell-args ("-c"))
                   (tramp-remote-shell-login (""))
                   ))
  #+end_src
  
With this evaluated, you can change to a Guix shell environment on a
remote host using:

    /ssh:me@remotehost|guix-shell:myproj@remotehost:/path/

As you can see this uses the user part of a tramp file name to select
the environment.  I first tried to use the host part, but it seems that
this part has to be the same on each hop (I received an error about
non-matching host parts).  If you look at the ‘tramp-login-args’ defined
above, this uses a predefined directory “projects” under which are
stored the environments in sub-directories.  This is the part you need
to adjust if you rather need to use the “-D” and “-f” switches to “guix
shell”.  ‘tramp-remote-shell-login’ is set to the empty string so that
tramp does not call /bin/shell with the “-l” switch, which would remove
the environment variables set up by “guix shell”.  Without
‘tramp-remote-shell’ and ‘tramp-remote-shell-args’ I received an error
(I believe it stated something like: “(stringp nil)”.).  I do not know
why.  Setting of the connection local variable ‘tramp-remote-path’ is
needed to instructed tramp to not override the PATH environment variable
with paths from ‘tramp-remote-path’ that tramp can determine to be
existing.

As I have indicated, I mostly fiddled with the values until something
seemed to work; it might no actually work correctly or be correct.  So:
no warranty ;).  It is also not general at all.

-- 
Felix Dietrich



reply via email to

[Prev in Thread] Current Thread [Next in Thread]