unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#62401] [PATCH] home: Add home-syncthing-service-type.
@ 2023-03-23  8:10 Sergey Trofimov
  2023-03-28 15:58 ` Ludovic Courtès
       [not found] ` <87edp8g88j.fsf@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Sergey Trofimov @ 2023-03-23  8:10 UTC (permalink / raw)
  To: 62401; +Cc: Sergey Trofimov, paren, andrew, ludo

* gnu/home/services/syncthing.scm
(home-syncthing-service-type): New variable.
(home-syncthing-configuration): New procedure.
* gnu/services/syncthing.scm
(syncthing-shepherd-service): Adapt to be used as a home service.
* doc/guix.texi: Ditto.
---
 doc/guix.texi                   | 42 ++++++++++++++++++++++++++++-
 gnu/home/services/syncthing.scm | 48 +++++++++++++++++++++++++++++++++
 gnu/services/syncthing.scm      | 15 +++++++----
 3 files changed, 99 insertions(+), 6 deletions(-)
 create mode 100644 gnu/home/services/syncthing.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index dfdb26103a..a2fe2514db 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -20735,7 +20735,7 @@ List of command-line arguments passing to @code{syncthing} binary.
 Sum of logging flags, see
 @uref{https://docs.syncthing.net/users/syncthing.html#cmdoption-logflags, Syncthing documentation logflags}.
 
-@item @code{user} (default: @var{#f})
+@item @code{user}
 The user as which the Syncthing service is to be run.
 This assumes that the specified user exists.
 
@@ -41790,6 +41790,7 @@ services)}.
 * Sound: Sound Home Services.   Dealing with audio.
 * Messaging: Messaging Home Services.   Services for managing messaging.
 * Media: Media Home Services.   Services for managing media.
+* Networking: Networking Home Services.
 @end menu
 @c In addition to that Home Services can provide
 
@@ -42978,6 +42979,45 @@ kodi} for more information.
 @end table
 @end deftp
 
+@node Networking Home Services
+@subsection Networking Home Services
+
+@cindex syncthing
+With the @code{(gnu home services syncthing)} service, you can configure
+@uref{https://github.com/syncthing/syncthing, Syncthing} to run upon
+login.
+
+Here is an example of a service and its configuration that you could add
+to the @code{services} field of your @code{home-environment}:
+
+@lisp
+(service home-syncthing-service-type
+  (home-syncthing-configuration
+   (arguments '("--paused"))))
+@end lisp
+
+@defvar home-syncthing-service-type
+This is the type of the @code{syncthing} home service, whose value is an
+@code{home-syncthing-configuration} object.
+@end defvar
+
+@deftp {Data Type} home-syncthing-configuration
+Data type representing the configuration for @code{home-syncthing-service-type}.
+
+@table @asis
+@item @code{syncthing} (default: @var{syncthing})
+@code{syncthing} package to use.
+
+@item @code{arguments} (default: @var{'()})
+List of command-line arguments passing to @code{syncthing} binary.
+
+@item @code{logflags} (default: @var{0})
+Sum of logging flags, see
+@uref{https://docs.syncthing.net/users/syncthing.html#cmdoption-logflags, Syncthing documentation logflags}.
+
+@end table
+@end deftp
+
 @node Invoking guix home
 @section Invoking @command{guix home}
 
diff --git a/gnu/home/services/syncthing.scm b/gnu/home/services/syncthing.scm
new file mode 100644
index 0000000000..928a23986b
--- /dev/null
+++ b/gnu/home/services/syncthing.scm
@@ -0,0 +1,48 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
+;;; Copyright © 2023 Sergey Trofimov <sarg@sarg.org.ru>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu home services syncthing)
+  #:use-module (gnu services)
+  #:use-module (gnu services syncthing)
+  #:use-module (gnu services shepherd)
+  #:use-module (gnu home services shepherd)
+
+  #:export (home-syncthing-service-type
+            home-syncthing-configuration))
+
+(define syncthing-home-shepherd-service
+  (lambda (configuration)
+    (map (lambda (srv) (shepherd-service (inherit srv) (requirement '())))
+         ((@@ (gnu services syncthing) syncthing-shepherd-service) configuration))))
+
+(define-syntax-rule (home-syncthing-configuration args ...)
+  (syncthing-configuration
+   (user #f)
+   args ...))
+
+(define home-syncthing-service-type
+  (service-type (name 'syncthing)
+                (extensions (list (service-extension home-shepherd-service-type
+                                                     syncthing-home-shepherd-service)))
+                (default-value (home-syncthing-configuration))
+                (description
+                 "Run @uref{https://github.com/syncthing/syncthing, Syncthing}
+decentralized continuous file system synchronization.")))
+
+;;; syncthing.scm ends here
diff --git a/gnu/services/syncthing.scm b/gnu/services/syncthing.scm
index 7c3d5b027d..960f0a1db8 100644
--- a/gnu/services/syncthing.scm
+++ b/gnu/services/syncthing.scm
@@ -43,8 +43,7 @@ (define-record-type* <syncthing-configuration>
              (default '()))
   (logflags  syncthing-configuration-logflags  ;number
              (default 0))
-  (user      syncthing-configuration-user      ;string
-             (default #f))
+  (user      syncthing-configuration-user)     ;string
   (group     syncthing-configuration-group     ;string
              (default "users"))
   (home      syncthing-configuration-home      ;string
@@ -55,9 +54,12 @@ (define syncthing-shepherd-service
     (($ <syncthing-configuration> syncthing arguments logflags user group home)
      (list
       (shepherd-service
-       (provision (list (string->symbol (string-append "syncthing-" user))))
+       (provision (list
+                   (or (and user (string->symbol (string-append "syncthing-" user)))
+                       'syncthing)))
        (documentation "Run syncthing.")
        (requirement '(loopback))
+       (modules '((srfi srfi-1) (shepherd support)))
        (start #~(make-forkexec-constructor
                  (append (list (string-append #$syncthing "/bin/syncthing")
                                "-no-browser"
@@ -65,9 +67,12 @@ (define syncthing-shepherd-service
                                (string-append "-logflags=" (number->string #$logflags)))
                          '#$arguments)
                  #:user #$user
-                 #:group #$group
+                 #:group (and #$user #$group)
                  #:environment-variables
-                 (append (list (string-append "HOME=" (or #$home (passwd:dir (getpw #$user))))
+                 (append (list (string-append "HOME="
+                                              (or #$home
+                                                  (and #$user (passwd:dir (getpw #$user)))
+                                                  user-homedir))
                                "SSL_CERT_DIR=/etc/ssl/certs"
                                "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt")
                          (remove (lambda (str)
-- 
2.39.2





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#62401] [PATCH] home: Add home-syncthing-service-type.
  2023-03-23  8:10 [bug#62401] [PATCH] home: Add home-syncthing-service-type Sergey Trofimov
@ 2023-03-28 15:58 ` Ludovic Courtès
  2023-03-28 19:29   ` Sergey Trofimov
       [not found] ` <87edp8g88j.fsf@gnu.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2023-03-28 15:58 UTC (permalink / raw)
  To: Sergey Trofimov; +Cc: paren, 62401, andrew

Hi,

Sergey Trofimov <sarg@sarg.org.ru> skribis:

> * gnu/home/services/syncthing.scm
> (home-syncthing-service-type): New variable.
> (home-syncthing-configuration): New procedure.
> * gnu/services/syncthing.scm
> (syncthing-shepherd-service): Adapt to be used as a home service.
> * doc/guix.texi: Ditto.

Nice!

Note: You can just say “New file” for a new file; however please specify
the name of the node added to the manual, for clarity.

> +(define syncthing-home-shepherd-service
> +  (lambda (configuration)
> +    (map (lambda (srv) (shepherd-service (inherit srv) (requirement '())))
> +         ((@@ (gnu services syncthing) syncthing-shepherd-service) configuration))))

You could do that without resorting to @@, by using ‘find’ on the
extensions of ‘syncthing-service-type’.

> diff --git a/gnu/services/syncthing.scm b/gnu/services/syncthing.scm
> index 7c3d5b027d..960f0a1db8 100644
> --- a/gnu/services/syncthing.scm
> +++ b/gnu/services/syncthing.scm
> @@ -43,8 +43,7 @@ (define-record-type* <syncthing-configuration>
>               (default '()))
>    (logflags  syncthing-configuration-logflags  ;number
>               (default 0))
> -  (user      syncthing-configuration-user      ;string
> -             (default #f))
> +  (user      syncthing-configuration-user)     ;string

This means that users of ‘syncthing-service-type’ will now have to
provide a value for ‘user’, which wasn’t the case until now.  Is this
change necessary?

The rest looks reasonable to me.  My main concern is whether it would
make sense to automate system->home service translation.  I’ll expand on
that separately.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#62401] [PATCH] home: Add home-syncthing-service-type.
  2023-03-28 15:58 ` Ludovic Courtès
@ 2023-03-28 19:29   ` Sergey Trofimov
  2023-03-29 16:35     ` Bruno Victal
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Trofimov @ 2023-03-28 19:29 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: paren, 62401, andrew


Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Sergey Trofimov <sarg@sarg.org.ru> skribis:
>
>> * gnu/home/services/syncthing.scm
>> (home-syncthing-service-type): New variable.
>> (home-syncthing-configuration): New procedure.
>> * gnu/services/syncthing.scm
>> (syncthing-shepherd-service): Adapt to be used as a home 
>> service.
>> * doc/guix.texi: Ditto.
>
> Nice!
>
> Note: You can just say “New file” for a new file; however please 
> specify
> the name of the node added to the manual, for clarity.

So it looks like this?
--8<---------------cut here---------------start------------->8---
* gnu/home/services/syncthing.scm: New file.
* doc/guix.texi: Document home-syncthing-service-type and
home-syncthing-configuration.
--8<---------------cut here---------------end--------------->8---

>> +(define syncthing-home-shepherd-service
>> +  (lambda (configuration)
>> +    (map (lambda (srv) (shepherd-service (inherit srv) 
>> (requirement '())))
>> +         ((@@ (gnu services syncthing) 
>> syncthing-shepherd-service) configuration))))
>
> You could do that without resorting to @@, by using ‘find’ on 
> the
> extensions of ‘syncthing-service-type’.

Not sure I get you. I use @@ because `syncthing-shepherd-service` 
is not exported and I want to leave that as is.

>> diff --git a/gnu/services/syncthing.scm 
>> b/gnu/services/syncthing.scm
>> index 7c3d5b027d..960f0a1db8 100644
>> --- a/gnu/services/syncthing.scm
>> +++ b/gnu/services/syncthing.scm
>> @@ -43,8 +43,7 @@ (define-record-type* 
>> <syncthing-configuration>
>>               (default '()))
>>    (logflags  syncthing-configuration-logflags  ;number
>>               (default 0))
>> -  (user      syncthing-configuration-user      ;string
>> -             (default #f))
>> +  (user      syncthing-configuration-user)     ;string
>
> This means that users of ‘syncthing-service-type’ will now have 
> to
> provide a value for ‘user’, which wasn’t the case until now.  Is 
> this
> change necessary?
>

The existing code fails on this line, when the user is not 
specified:
--8<---------------cut here---------------start------------->8---
(provision (list (string->symbol (string-append "syncthing-" 
user))))
--8<---------------cut here---------------end--------------->8---

string-append doesn't accept nil args

>
> The rest looks reasonable to me.  My main concern is whether it 
> would
> make sense to automate system->home service translation.  I’ll 
> expand on
> that separately.

Does guix really need a system syncthing service? It runs under 
`user`, looks for configuration in `/home/user` and therefore 
looks out of place in the system services list.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#62401] [PATCH] home: Add home-syncthing-service-type.
  2023-03-28 19:29   ` Sergey Trofimov
@ 2023-03-29 16:35     ` Bruno Victal
  0 siblings, 0 replies; 5+ messages in thread
From: Bruno Victal @ 2023-03-29 16:35 UTC (permalink / raw)
  To: Sergey Trofimov; +Cc: paren, 62401, Ludovic Courtès, andrew

Hi Sergey,

On 2023-03-28 20:29, Sergey Trofimov wrote:
> 
> Does guix really need a system syncthing service? It runs under `user`, looks for configuration in `/home/user` and therefore looks out of place in the system services list.
> 

A system service doesn't necessarily mean root or "non-interactive/system user" only.
It's a service that can be configured by the system admin and it can be made to run under any user.

Someone could very well want to configure some kinds of services within config.scm rather than having
to manage both a system and user config.

My 2¢.


Cheers,
Bruno




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#62401] [PATCH] home: Add home-syncthing-service-type.
       [not found]   ` <07fc2e40-7e23-a7cb-469d-95aae6614ff5@makinata.eu>
@ 2023-08-07  9:50     ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2023-08-07  9:50 UTC (permalink / raw)
  To: Bruno Victal, Sergey Trofimov; +Cc: guix-devel, paren, 62401, andrew

Hi Bruno, Sergey, and all,

<https://issues.guix.gnu.org/65119> is an attempt to provide a
consistent and simple way to “port” System services to Home, including
Syncthing, as discussed in this thread.

Let me know what you think!

Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-07  9:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23  8:10 [bug#62401] [PATCH] home: Add home-syncthing-service-type Sergey Trofimov
2023-03-28 15:58 ` Ludovic Courtès
2023-03-28 19:29   ` Sergey Trofimov
2023-03-29 16:35     ` Bruno Victal
     [not found] ` <87edp8g88j.fsf@gnu.org>
     [not found]   ` <07fc2e40-7e23-a7cb-469d-95aae6614ff5@makinata.eu>
2023-08-07  9:50     ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).