Re: Ability to add toplevel commands to ~/.ssh/config v1 APPLIED

Tony O
Xinglu Chen: 1
 gnu: home-services: ssh: Support toplevel options.

 1 files changed, 26 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/23268/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] gnu: home-services: ssh: Support toplevel options. Export this patch

* gnu/home-services/ssh.scm (serialize-field): Add optional keyword
argument ’toplevel?’
(serialize-toplevel-alist): New procedure.
(home-ssh-configuration): Add ‘toplevel-option’ field.

Suggested-by: Tony O <me@fron.io>
Link: https://lists.sr.ht/~abcdw/rde-devel/%3CXNh-7CLvmQPB70oQ7r5c1spO7t8NotWPYKyeKKBqnTF44zmB31BDYAUhUNrUNo9Miftg2MaQxOrMcY33ZuC4kg%3D%3D%40fron.io%3E
Is this what you want?

This config

--8<---------------cut here---------------start------------->8---
(service home-ssh-service-type
                 (forward-agent #f)
                  '((include . "/path/to/file")))
                   '((compression . #f)
                     (server-alive-interval . 0)
                     (server-alive-count-max . 3)
                     (add-keys-to-agent . #t)))))
--8<---------------cut here---------------end--------------->8---

Yields the following in ~/.ssh/config

--8<---------------cut here---------------start------------->8---
Host *
  UserKnownHostsFile ~/.ssh/known_hosts
  ForwardAgent no
  Compression no
  ServerAliveInterval 0
  ServerAliveCountMax 3
  AddKeysToAgent yes
Include /path/to/file
--8<---------------cut here---------------end--------------->8---

 gnu/home-services/ssh.scm | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/gnu/home-services/ssh.scm b/gnu/home-services/ssh.scm
index 0ba945f..fba552b 100644
--- a/gnu/home-services/ssh.scm
+++ b/gnu/home-services/ssh.scm
@@ -34,13 +34,14 @@
  (let ((str (symbol->string field-name)))
    (apply string-append (map string-capitalize (string-split str #\-)))))

(define (serialize-field field-name val)
(define* (serialize-field field-name val #:key (toplevel? #f))
   ((boolean? val) (serialize-boolean field-name val))
   ((list? val) (serialize-list field-name val))
    (let ((field-name (uglify-field-name field-name)))
      (if (member field-name '("Host" "Match"))
      (if (or (member field-name '("Host" "Match"))
          (format #f "~a ~a\n" field-name val)
          (format #f "  ~a ~a\n" field-name val))))))

@@ -53,6 +54,13 @@
(define (serialize-alist field-name val)
  (generic-serialize-alist string-append serialize-field val))

(define (serialize-toplevel-alist field-name val)
   (lambda (field-name val)
     (serialize-field field-name val #:toplevel? #t))

(define (serialize-extra-config field-name val)
  (define serialize-extra-config-entry
@@ -159,6 +167,22 @@ Host *
  AddKeysToAgent yes
  AddressFamily inet
@end example")
   (alist '())
   "Association list of toplevel configuration options.  The configuration below:

    '((include . \"/some/path/to/file\"))))
@end lisp

would this:

Include /some/path/to/file
@end example"
   (ssh-host-or-ssh-match '())
   "List of configurations for other hosts.  Something like this:

base-commit: cd7a30e9f860899a11bfad0e42d283ed746b7250