Check the @samp{Share SSH connections if possible} control for that
session.
+@end table
+
+@noindent
+The following methods allow to access containers in different ways:
+@table @asis
@item @option{docker}
@cindex method @option{docker}
@cindex @option{docker} method
This is an optional method, @ref{Optional methods}. It does not
support user names.
+@item @option{nspawn}
+@cindex method @option{nspawn}
+@cindex @option{nspawn} method
+
+Integration of @code{systemd-nspawn} instances. The host name is the
+instance name, as returned by @samp{machinectl list --all}.
+
+This is an optional method, @ref{Optional methods}.
@end table
@trampfn{smb,daniel%BIZARRE@@melancholia,/daniel$$/.emacs}
@end example
-where user @code{daniel} connects as a domain user to the SMB host
-@code{melancholia} in the MS Windows domain @code{BIZARRE} to edit
-@file{.emacs} located in the home directory (share @code{daniel$}).
+where user @samp{daniel} connects as a domain user to the SMB host
+@samp{melancholia} in the MS Windows domain @samp{BIZARRE} to edit
+@file{.emacs} located in the home directory (share @samp{daniel$}).
Alternatively, for local WINS users (as opposed to domain users),
substitute the domain name with the name of the local host in
@trampfn{smb,daniel%MELANCHOLIA@@melancholia,/daniel$$/.emacs}
@end example
-where user @code{daniel} connects as local user to the SMB host
-@code{melancholia} in the local domain @code{MELANCHOLIA} to edit
-@file{.emacs} located in the home directory (share @code{daniel$}).
+where user @samp{daniel} connects as local user to the SMB host
+@samp{melancholia} in the local domain @samp{MELANCHOLIA} to edit
+@file{.emacs} located in the home directory (share @samp{daniel$}).
The domain name and user name are optional for @command{smbclient}
authentication. When user name is not specified, @command{smbclient}
@end group
@end lisp
-With all defaults set, @samp{@trampfn{-,,}} will connect @value{tramp}
-to John's home directory on @code{target} via @code{ssh}.
+With all defaults set, @file{@trampfn{-,,}} will connect @value{tramp}
+to John's home directory on @samp{target} via method @option{ssh}.
@end defopt
@defopt tramp-default-host-alist
name combinations. The alist can hold multiple values. While
@code{tramp-default-host} is sufficient in most cases, some methods,
like @option{adb}, require defaults overwritten.
+
+The default host name for @option{nspawn} is @samp{.host}. Therefore,
+@file{@trampfn{nspawn,,}} and @file{@trampfn{sudo,,}} have the same
+effect.
@end defopt
the user that you want to use, and @samp{node} is the name of the
hadoop server.
-@item tramp-nspawn
-@cindex method @option{nspawn}
-@cindex @option{nspawn} method
-Access to environments provided by systemd-nspawn. A file is accessed
-via @file{@trampfn{nspawn,user@@container,/path/to/file}}, where
-@samp{user} is the (optional) user that you want to use, and
-@samp{container} is the container to connect to. systemd-nspawn and
-its container utilities often require super user access to run, use
-multi-hop file names with @option{doas} or @option{sudo} to raise your
-privileges.
-
@item vagrant-tramp
@cindex method @option{vagrant}
@cindex @option{vagrant} method
machine melancholia#4711 port davs login daniel%BIZARRE password geheim
@end example
-For the methods @option{doas}, @option{sudo} and @option{sudoedit} the
-password of the user requesting the connection is needed, and not the
-password of the target user@footnote{On the local host, @code{run0}
-uses a graphical password agent.}. If these connections happen on the
-local host, an entry with the local user and local host is used:
+For the methods @option{doas}, @option{sudo}, @option{sudoedit} and
+@option{nspawn} the password of the user requesting the connection is
+needed, and not the password of the target user@footnote{On the local
+host, @code{run0} uses a graphical password agent.}. If these
+connections happen on the local host, an entry with the local user and
+local host is used:
@example
machine @var{host} port sudo login @var{user} password secret
shell does not recognize the export command as entered in
@file{.profile}.
-Likewise, (@code{~}) character in paths will cause errors because
-Bourne shell does not do (@code{~}) character expansions.
+Likewise, (@samp{~}) character in paths will cause errors because
+Bourne shell does not do (@samp{~}) character expansions.
One approach to avoiding these incompatibilities is to make all
commands in @file{~/.shrc} and @file{~/.profile} Bourne shell
or @t{"--paranoia"}. See the @samp{encfs(1)} man page for details.
However, @value{tramp} must adapt these configuration sets. The
-@code{chainedNameIV} configuration option must be disabled; otherwise
+@option{chainedNameIV} configuration option must be disabled; otherwise
@value{tramp} couldn't handle file name encryption transparently.
@end defopt
@table @file
@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}.emacs
For the file @file{.emacs} located in the home directory, on the host
-@code{melancholia}, using method @code{ssh}.
+@samp{melancholia}, using method @option{ssh}.
@item @value{prefix}ssh@value{postfixhop}melancholia.danann.net@value{postfix}.emacs
For the file @file{.emacs} specified using the fully qualified domain name of
For the file @file{.emacs} specified using the @file{~}, which is expanded.
@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~daniel/.emacs
-For the file @file{.emacs} located in @code{daniel}'s home directory
-on the host, @code{melancholia}. The @file{~<user>} construct is
+For the file @file{.emacs} located in @samp{daniel}'s home directory
+on the host, @samp{melancholia}. The @file{~<user>} construct is
expanded to the home directory of that user on the remote host.
@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}/etc/squid.conf
-For the file @file{/etc/squid.conf} on the host @code{melancholia}.
+For the file @file{/etc/squid.conf} on the host @samp{melancholia}.
@end table
behavior: @file{@trampfn{method,user@@host,path/to/file}}.
@file{@trampfn{ssh,daniel@@melancholia,.emacs}} is for file
-@file{.emacs} in @code{daniel}'s home directory on the host,
-@code{melancholia}, accessing via method @code{ssh}.
+@file{.emacs} in @samp{daniel}'s home directory on the host,
+@samp{melancholia}, accessing via method @option{ssh}.
For specifying port numbers, affix @file{#<port>} to the host
name. For example: @file{@trampfn{ssh,daniel@@melancholia#42,.emacs}}.
This remote file name syntax is similar to the syntax used by Ange FTP@.
A remote file name has the form
-@code{@value{prefix}user@@host@value{postfix}path/to/file}. The
-@code{user@@} part is optional, and the method is determined by
+@file{@value{prefix}user@@host@value{postfix}path/to/file}. The
+@samp{user@@} part is optional, and the method is determined by
@ref{Default Method}.
@item @code{separate}
@include trampver.texi
This remote file name syntax originated in the XEmacs text editor.
A remote file name has the form
-@code{@trampfn{method,user@@host,path/to/file}}. The @code{method}
-and @code{user@@} parts are optional.
+@file{@trampfn{method,user@@host,path/to/file}}. The @samp{method}
+and @samp{user@@} parts are optional.
@clear separate
@set unified
@include trampver.texi
@code{tramp-default-proxies-alist}. The following file name expands
to user @samp{root} on host @samp{remotehost}, starting with an
@option{ssh} session on host @samp{remotehost}:
-@samp{@trampfn{ssh@value{postfixhop}%h|su,remotehost,}}.
+@file{@trampfn{ssh@value{postfixhop}%h|su,remotehost,}}.
On the other hand, if a trailing hop does not specify a host name, the
host name of the previous hop is reused. Therefore, the following
file name is equivalent to the previous example:
-@samp{@trampfn{ssh@value{postfixhop}remotehost|su,,}}.
+@file{@trampfn{ssh@value{postfixhop}remotehost|su,,}}.
@defopt tramp-completion-multi-hop-methods
When this list includes the last method in a multi-hop connection, the
@defopt tramp-file-name-with-method
The method @code{tramp-revert-buffer-with-sudo} shows an alternate
-buffer. It defaults to @code{sudo}, other valid methods are
-@code{su}, @code{doas}, @code{run0}, and @code{ksu}.
+buffer. It defaults to @option{sudo}, other valid methods are
+@option{su}, @option{doas}, @option{run0}, and @option{ksu}.
@lisp
(customize-set-variable 'tramp-file-name-with-method "doas")
local host that the remote host can redirect X11 window
interactions. If querying for a recognizable name is not possible for
whatever reason, then replace @code{(getenv "DISPLAY")} with a
-hard-coded, fixed name. Note that using @code{:0} for X11 display name
+hard-coded, fixed name. Note that using @samp{:0} for X11 display name
here will not work as expected.
@vindex ForwardX11@r{, ssh option}
source via @code{tramp-rename-files}. @code{source} is a regular
expressions, which matches a remote file name. @code{target} must be
a directory name, which could be remote (including remote directories
-@value{tramp} infers by default, such as @samp{@trampfn{method,user@@host,}}).
+@value{tramp} infers by default, such as @file{@trampfn{method,user@@host,}}).
@code{target} can contain the patterns @code{%m}, @code{%u} or
@code{%h}, which are replaced by the method name, user name or host
@end lisp
routes all connections to a host in @samp{company.org} via
-@samp{@trampfn{ssh,multi.hop,}}, which might be useful when using
+@file{@trampfn{ssh,multi.hop,}}, which might be useful when using
Emacs outside the company network.
@lisp
;; C-x C-f /flatpak:SANDBOX:/path/to/file
;;
;; Where:
-;; SANDBOX is the running sandbox to connect to.
-;; It could be an application ID, an instance ID, or a PID.
+;; SANDBOX is the running sandbox to connect to.
+;; It could be an application ID, an instance ID, or a PID.
;;
;;
;;
;; C-x C-f /apptainer:INSTANCE:/path/to/file
;;
;; Where:
-;; INSTANCE is the running instance to connect to.
+;; INSTANCE is the running instance to connect to.
+;;
+;;
+;;
+;; Open a file on a running systemd-nspawn container:
+;;
+;; C-x C-f /nspawn:USER@CONTAINER:/path/to/file
+;;
+;; Where:
+;; USER is the user on the container to connect as (optional)
+;; CONTAINER is the container to connect to
;;; Code:
:type '(choice (const "apptainer")
(string)))
+(defcustom tramp-nspawn-program "machinectl"
+ "Name of the machinectl program."
+ :group 'tramp
+ :version "30.1"
+ :type '(choice (const "machinectl")
+ (string)))
+
;;;###tramp-autoload
(defconst tramp-docker-method "docker"
"Tramp method name to use to connect to Docker containers.")
(defconst tramp-apptainer-method "apptainer"
"Tramp method name to use to connect to Apptainer instances.")
+;;;###tramp-autoload
+(defconst tramp-nspawn-method "nspawn"
+ "Tramp method name to use to connect to systemd-nspawn containers.")
+
;;;###tramp-autoload
(defmacro tramp-skeleton-completion-function (method &rest body)
"Skeleton for `tramp-*-completion-function' with multi-hop support.
lines)))
(mapcar (lambda (name) (list nil name)) names))))
+(defun tramp-nspawn--completion-function (method)
+ "List systemd-nspawn containers available for connection.
+
+This function is used by `tramp-set-completion-function', please
+see its function help for a description of the format."
+ (tramp-skeleton-completion-function method
+ (when-let ((raw-list
+ (shell-command-to-string (concat program " list --all -q")))
+ ;; Ignore header line.
+ (lines (cdr (split-string raw-list "\n")))
+ (first-words (mapcar (lambda (line) (car (split-string line)))
+ lines))
+ (machines (seq-take-while (lambda (name) name) first-words)))
+ (mapcar (lambda (m) (list nil m)) machines))))
+
;;;###tramp-autoload
(defvar tramp-default-remote-shell) ;; Silence byte compiler.
tramp-apptainer-method
`((tramp-apptainer--completion-function ,tramp-apptainer-method))))
+;; todo: check tramp-async-args and tramp-direct-async
+;;;###tramp-autoload
+(defun tramp-enable-nspawn-method ()
+ "Enable connection to nspawn containers."
+ (add-to-list 'tramp-methods
+ `(,tramp-nspawn-method
+ (tramp-login-program ,tramp-nspawn-program)
+ (tramp-login-args (("shell")
+ ("-q")
+ ("--uid" "%u")
+ ("%h")))
+ (tramp-remote-shell ,tramp-default-remote-shell)
+ (tramp-remote-shell-login ("-l"))
+ (tramp-remote-shell-args ("-i" "-c"))))
+
+ (add-to-list 'tramp-default-host-alist `(,tramp-nspawn-method nil ".host"))
+ (add-to-list 'tramp-completion-multi-hop-methods tramp-nspawn-method)
+
+ (tramp-set-completion-function
+ tramp-nspawn-method
+ `((tramp-nspawn--completion-function ,tramp-nspawn-method))))
+
;; Default connection-local variables for Tramp.
(defconst tramp-kubernetes-connection-local-default-variables