all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 65119@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#65119] [PATCH 5/8] home: services: Support mapping of System services to Home services.
Date: Sun,  6 Aug 2023 23:07:32 +0200	[thread overview]
Message-ID: <2e33f4ce62f4238a147e1bac16302751efe69c26.1691355218.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1691355218.git.ludo@gnu.org>

* gnu/home/services.scm (service-type-mapping)
(system->home-service-type): New procedures.
(define-service-type-mapping, define-service-type-mappings): New macros.
(%system/home-service-type-mapping): New variable.
<top level>: Use 'define-service-type-mappings'.
* gnu/home/services/shepherd.scm <top level>: Likewise.
---
 gnu/home/services.scm          | 69 +++++++++++++++++++++++++++++++++-
 gnu/home/services/shepherd.scm |  4 +-
 2 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 042eba4780..8d53f2f4d3 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -33,6 +33,7 @@ (define-module (gnu home services)
   #:use-module (guix diagnostics)
   #:use-module (guix i18n)
   #:use-module (guix modules)
+  #:use-module (guix memoization)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (ice-9 match)
@@ -63,11 +64,16 @@ (define-module (gnu home services)
             lookup-home-service-types
             home-provenance
 
+            define-service-type-mapping
+            system->home-service-type
+
             %initialize-gettext)
 
   #:re-export (service
                service-type
-               service-extension))
+               service-extension
+               for-home
+               for-home?))
 
 ;;; Comment:
 ;;;
@@ -513,6 +519,67 @@ (define home-activation-service-type
 reconfiguration or generation switching.  This service can be extended
 with one gexp, but many times, and all gexps must be idempotent.")))
 
+\f
+;;;
+;;; Service type graph rewriting.
+;;;
+
+(define (service-type-mapping proc)
+  "Return a procedure that applies PROC to map a service type graph to another
+one."
+  (define (rewrite extension)
+    (match (proc (service-extension-target extension))
+      (#f #f)
+      (target
+       (service-extension target
+                          (service-extension-compute extension)))))
+
+  (define replace
+    (mlambdaq (type)
+      (service-type
+       (inherit type)
+       (name (symbol-append 'home- (service-type-name type)))
+       (location (service-type-location type))
+       (extensions (filter-map rewrite (service-type-extensions type))))))
+
+  replace)
+
+(define %system/home-service-type-mapping
+  ;; Mapping of System to Home services.
+  (make-hash-table))
+
+(define system->home-service-type
+  ;; Map the given System service type to the corresponding Home service type.
+  (let ()
+    (define (replace type)
+      (define replacement
+        (hashq-ref %system/home-service-type-mapping type
+                   *unspecified*))
+
+      (if (eq? replacement *unspecified*)
+          type
+          replacement))
+
+    (service-type-mapping replace)))
+
+(define-syntax define-service-type-mapping
+  (syntax-rules (=>)
+    ((_ system-type => home-type)
+     (hashq-set! %system/home-service-type-mapping
+                 system-type home-type))))
+
+(define-syntax define-service-type-mappings
+  (syntax-rules (=>)
+    ((_ (system-type => home-type) ...)
+     (begin
+       (define-service-type-mapping system-type => home-type)
+       ...))))
+
+(define-service-type-mappings
+  (system-service-type => home-service-type)
+  (activation-service-type => home-activation-service-type)
+  (profile-service-type => home-profile-service-type))
+
 \f
 ;;;
 ;;; On-change.
diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index 5585ef61b2..bd068c37fc 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -141,7 +141,7 @@ (define (ensure-shepherd-gexp config)
 (define (shepherd-xdg-configuration-files config)
   `(("shepherd/init.scm" ,(home-shepherd-configuration-file config))))
 
-(define-public home-shepherd-service-type
+(define home-shepherd-service-type
   (service-type (name 'home-shepherd)
                 (extensions
                  (list (service-extension
@@ -168,4 +168,6 @@ (define-public home-shepherd-service-type
                 (default-value (home-shepherd-configuration))
                 (description "Configure and install userland Shepherd.")))
 
+(define-service-type-mapping
+  shepherd-root-service-type => home-shepherd-service-type)
 
-- 
2.41.0





  parent reply	other threads:[~2023-08-06 21:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-06 21:04 [bug#65119] [PATCH 0/8] Sharing service code between Home and System Ludovic Courtès
2023-08-06 21:07 ` [bug#65119] [PATCH 1/8] services: dicod: Remove Shepherd < 0.9.0 compatibility layer Ludovic Courtès
2023-08-06 21:07 ` [bug#65119] [PATCH 2/8] services: dicod: Pre-build the GCIDE index Ludovic Courtès
2023-08-06 21:07 ` [bug#65119] [PATCH 3/8] services: syncthing: Use 'match-record' Ludovic Courtès
2023-08-06 21:07 ` [bug#65119] [PATCH 4/8] services: Define 'for-home' Ludovic Courtès
2023-08-06 21:07 ` Ludovic Courtès [this message]
2023-08-06 21:07 ` [bug#65119] [PATCH 6/8] home: services: mcron: Define as a mapping of the system service Ludovic Courtès
2023-08-21 15:50   ` Andrew Tropin
2023-08-06 21:07 ` [bug#65119] [PATCH 7/8] home: services: Add dicod Ludovic Courtès
2023-08-06 21:07 ` [bug#65119] [PATCH 8/8] home: services: Add Syncthing Ludovic Courtès
2023-08-13  5:28 ` [bug#65119] [PATCH 0/8] Sharing service code between Home and System 宋文武 via Guix-patches via
2023-08-20 21:23   ` bug#65119: " Ludovic Courtès
2023-08-21 13:43   ` [bug#65119] " Andrew Tropin
2023-08-22 16:25     ` Ludovic Courtès
2023-08-25  6:28       ` Andrew Tropin
2023-09-08 12:42         ` Andrew Tropin
2023-09-08 22:18         ` Ludovic Courtès
2023-09-09 10:42           ` Andrew Tropin
2023-09-13 18:06             ` Ludovic Courtès
2023-09-17  5:28               ` Andrew Tropin
2023-09-17 10:27                 ` Ludovic Courtès
2023-09-13 19:55             ` Ludovic Courtès
2023-09-17  7:01               ` Andrew Tropin
2023-10-13 16:05                 ` Ludovic Courtès
2023-10-14  6:03                   ` Andrew Tropin

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=2e33f4ce62f4238a147e1bac16302751efe69c26.1691355218.git.ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=65119@debbugs.gnu.org \
    /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.