Configuring Emacs TRAMP to enter Guix container

Hi all, I’m new to Emacs and Guix. I found out recently that Emacs has a package named TRAMP which allows you to work in remote systems. I was wondering how to use it to go into a Guix container built with guix system container.

I’m running it on a NixOS host, as I have a bit of config that I want to migrate using a container, before installing Guix on bare-metal. I got the container working, I’m just not sure how to use TRAMP to enter it.

Additional information, guix system container prints two recommended commands,
sudo guix container exec <PID-HERE> /run/current-system/profile/bin/bash --login and sudo nsenter -at <PID-HERE>.
Neither worked, but sudo nsenter -at <PID-HERE> /run/current-system/profile/bin/bash --login does work.

TRAMP seems to have some concept of “methods”, I’m just not sure how it nor how Linux namespaces work. sudo lsns does give a bunch of “namespaces” (whatever that means) that have the same PID as what is shown by guix container, I’m just unsure how to make use of it.

Solved it! Took a look at how lxc-tramp works.

(add-to-list 'tramp-remote-path "/run/current-system/profile/bin/")
(add-to-list 'tramp-methods
	     '("guixcontainer"
	       (tramp-login-program "nsenter")
	       (tramp-login-args (("-a" "-t" "%h")
				  ("/run/current-system/profile/bin/bash" "--login")))
	       (tramp-remote-shell "/run/current-system/profile/bin/bash")
	       (tramp-remote-shell-args ("-c"))))

One issue I had for a while was tramp constantly saying ls not found, but adding the Guix system profile bin directory to tramp-remote-path fixes it.

An additional issue I faced was that Eshell would be broken, but in really weird ways (such as not having anything other than /bin in $PATH and any attempts to modify it silently failing). Looking into the docs I found that the the service responsible for symlinking /usr/bin/env was part of %base-services. But the services were explicitly overidden to not include anything other than the guix daemon, in the docker-image.tmpl which I used. After fixing that, Eshell worked like a charm.

Edit: No, it doesn’t.