all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bruno Victal <mirai@makinata.eu>
To: "Ludovic Courtès" <ludo@gnu.org>, "Sergey Trofimov" <sarg@sarg.org.ru>
Cc: 62401@debbugs.gnu.org, paren@disroot.org, andrew@trop.in,
	guix-devel@gnu.org
Subject: Re: Automatically mapping services from System to Home
Date: Wed, 29 Mar 2023 16:21:02 +0100	[thread overview]
Message-ID: <07fc2e40-7e23-a7cb-469d-95aae6614ff5@makinata.eu> (raw)
In-Reply-To: <87edp8g88j.fsf@gnu.org>

Hi Ludo’,

On 2023-03-28 17:18, Ludovic Courtès wrote:
> One idea I toyed with is automatic translation of service types from
> System to Home.  The service itself would look like this:
> 
> --8<---------------cut here---------------start------------->8---
> (define-module (gnu home services syncthing)
>   #:use-module (gnu home services)
>   #:use-module (gnu services syncthing)
>   #:export (home-syncthing-service-type)
>   #:re-export (syncthing-configuration
>                syncthing-configuration?))
> 
> (define home-syncthing-service-type
>   (system-service-type->home-service-type syncthing-service-type))
> --8<---------------cut here---------------end--------------->8---
> 
> The code to do that is attached below.  The key here is that we’d define
> mappings, like:
> 
>   (define-service-type-mapping
>     shepherd-root-service-type => home-shepherd-service-type)
> 
> The rest of the service type graph would be automatically constructed
> from this.
> 
> I feel like it would be worth pursuing this path so that there’s as
> little duplication as possible between Home and System.
> 
> OTOH, it doesn’t take care of things like #:user in
> ‘make-forkexec-constructor’ calls and the like.
> 

I've been thinking that shepherd services should, in general, come with a
preamble in their configuration record-types. (perhaps à la SRFI-136 parent-style records?)

Below is a non-exhaustive list of “things” that should almost always be configurable,
unless it's reasonable to omit it:

--8<---------------cut here---------------start------------->8---
;; These fields were listed based on “experience” in reworking,
;; repurposing and adding new (system) services within Guix.


(define-configuration example-configuration
  ;; Allow the package to be overridden.
  (package
    file-like
    "Lorem ipsum …")

  ;; Note that they're not strings. This allows for tailoring
  ;; the user-account used by the service (e.g. adding extra groups
  ;; for the daemon to have access to other directories, etc.
  (user
    user-account
    "Lorem ipsum …")

  ;; ^^^^^ Ditto.
  (group
   user-group
   "Lorem ipsum …")

  (shepherd-requirement   ; or shepherd-requirements, the former already has some presence in Guix
                          ; but could be phased-out in favor of the plural form
    list-of-symbols
    "Lorem ipsum …")

  ;; Uncommonly seen among services
  ;; but mpd-service-type is an example where this is important.
  (environment-variables
    list-of-env-vars
    "Lorem ipsum …")

--8<---------------cut here---------------end--------------->8---


Tossing another idea in the air, with <https://issues.guix.gnu.org/62298>
define-configuration could perhaps be enriched with additional parameters to 
hint that certain fields should be treated differently depending
on “context”? Naturally the service code will have to be adjusted
to use these hints, but overall it should result in a much cleaner
way to guide serializations and service-extension pruning.


It could be something of the sort:

--8<---------------cut here---------------start------------->8---
(define-configuration example-configuration
  …

  (user
    user-account
    "Lorem ipsum …"
   (attributes 'system-service)
  …)

;; or
(define-configuration example-configuration
  …

  (user
    user-account
    "Lorem ipsum …"
    system-only
  …)


;; or
(define-configuration example-configuration
  …

  (user
    user-account
    "Lorem ipsum …"
    (system #t)
    (home #f)
  …)
--8<---------------cut here---------------end--------------->8---


Cheers,
Bruno


  parent reply	other threads:[~2023-03-29 15:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2023-03-28 16:18 ` Automatically mapping services from System to Home Ludovic Courtès
2023-03-28 19:59   ` Attila Lendvai
2023-03-29 15:21   ` Bruno Victal [this message]
2023-08-07  9:50     ` [bug#62401] [PATCH] home: Add home-syncthing-service-type Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07fc2e40-7e23-a7cb-469d-95aae6614ff5@makinata.eu \
    --to=mirai@makinata.eu \
    --cc=62401@debbugs.gnu.org \
    --cc=andrew@trop.in \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    --cc=paren@disroot.org \
    --cc=sarg@sarg.org.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.