From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id YIzwJ20TI2T5mQAASxT56A (envelope-from ) for ; Tue, 28 Mar 2023 18:18:53 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id ABn3Jm0TI2Qz4wAAG6o9tA (envelope-from ) for ; Tue, 28 Mar 2023 18:18:53 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2503323767 for ; Tue, 28 Mar 2023 18:18:53 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phC1m-0001YO-AG; Tue, 28 Mar 2023 12:18:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phC1i-0001WJ-Oe for guix-devel@gnu.org; Tue, 28 Mar 2023 12:18:26 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phC1f-00089Y-P9; Tue, 28 Mar 2023 12:18:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=CjzggzOy8FsRmwtlGczw4QJU8xOcXnQPsd0boz97y0M=; b=pjs+1HO7OlwY8pgJ4Jh6 wxTg0+hg2ASsJsTtgypR0isaPjfDvR0WytT0uoB87WdrgboRmQ/K9Xesdni9AT8pGBxFLPotpKZ46 C6I93gHycJCsWijSxI8/K83AhuyKnwfRA0tyPTEfUGkYreIHdk6EvcBbfLMXlTIBj7fvYC9TN+552 Fh6f2z6usNLad8aE9bmJWjqD6yR2UT8RnR4P5kayl0hoY0w8MqalgNBfWd4yhDA9+0IMRRpIpx8hs 4k8Sl2N53xoALXkkLwcrgF9il0naZ75rqBjWAwrOYOefeYCrP3uRA9emm9ohHmJQ+jYtHngTrPIjw rUANP2/qOSTjkQ==; Received: from [193.50.110.81] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phC1f-0008Ow-1d; Tue, 28 Mar 2023 12:18:23 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Sergey Trofimov Cc: 62401@debbugs.gnu.org, paren@disroot.org, andrew@trop.in, guix-devel@gnu.org Subject: Automatically mapping services from System to Home References: <20230323081026.13850-1-sarg@sarg.org.ru> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Octidi 8 Germinal an 231 de la =?utf-8?Q?R=C3=A9volu?= =?utf-8?Q?tion=2C?= jour de la Jonquille X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Tue, 28 Mar 2023 18:18:20 +0200 In-Reply-To: <20230323081026.13850-1-sarg@sarg.org.ru> (Sergey Trofimov's message of "Thu, 23 Mar 2023 09:10:26 +0100") Message-ID: <87edp8g88j.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1680020333; a=rsa-sha256; cv=none; b=BJAaPV9hhjyvzqzKEnH/vkrL6PVqXPZ1rPSlGCssc1OkeoNFtPhplQMUXMCvw1uWMNA54a iV65s3egvA5g151fIKSwEgqCx+mPJpp4OlsN+sGXzkbmGfKQtWpkCut8GT1f2y3cgqm/Dq vYUueMvUP4iaZnB9FZgIaGv9TTIZ8ZEaFaa1PztrF+lHahfCRq1DNXUO+DFStWmtkYl3Hz 8WbaLe1uxXMO0X8UbZdxJM2jhc79G0eQVxn7edfr+BInsLvQJF6wSmvrCHDek+ylIeOCDO 8fl7DfJMLPgvqhPPyOqZ+xFUDWgkLko//u2xOfJjQAg3ZyP7Qi3Ohvannp1C8w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=pjs+1HO7; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1680020333; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=8KhmQYRRPUAUfkM6DRXPsA/Z6Dg5PWL+ma4vmKfCAms=; b=BTmh7iE8MOtAOp6Mcj17z5JRM8tM6HLh1lTmJYWcvRO8ESB1MYNlHj9QGedgAyT1gBRFjw Ptf/tktQfMk8xIFWujmoxMpnX7eZ0SUNCGE0EaOIvWBO/JoS2Y/qh2lTRHSIP/NP28aXiI ne3B1N3DJJzutaCLMPQ9EGtT0yF9mk3yrEiluVpKTtMMXXLQIHCg4fKFVNrLle5YajlzzK UtDp100rzZJw916iHAVwH0YUMCerEh3Jw69GY2FZDCLDxMvHiow8k3Oee13p1jp91PJxp2 KqCU7YLx90/eteVYDOmcrGBviPrg86JCM8VPmUbgRtXMy1smeLSBDc+2JyybDg== Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=pjs+1HO7; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -1.23 X-Spam-Score: -1.23 X-Migadu-Queue-Id: 2503323767 X-TUID: HkkJrg/4uipW --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=E2=80=99d d= efine mappings, like: (define-service-type-mapping shepherd-root-service-type =3D> 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=E2=80=99s as little duplication as possible between Home and System. OTOH, it doesn=E2=80=99t take care of things like #:user in =E2=80=98make-forkexec-constructor=E2=80=99 calls and the like. Thoughts? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/gnu/home/services.scm b/gnu/home/services.scm index b7ea6f08dd..b32e7395b1 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2021 Andrew Tropin ;;; Copyright =C2=A9 2021 Xinglu Chen +;;; Copyright =C2=A9 2022 Ludovic Court=C3=A8s ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,8 +32,10 @@ (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 (ice-9 match) + #:use-module (ice-9 vlist) =20 #:export (home-service-type home-profile-service-type @@ -46,6 +49,9 @@ (define-module (gnu home services) fold-home-service-types home-provenance =20 + define-service-type-mapping + system-service-type->home-service-type + %initialize-gettext) =20 #:re-export (service @@ -396,6 +402,77 @@ (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."))) =20 + +;;; +;;; Service type graph rewriting. +;;; + +(define (service-type-mapping proc) + (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) + (location (service-type-location type)) + (extensions (filter-map rewrite (service-type-extensions type)))))) + + replace) + +;; (define (service-type-extensions-rewriting replacements) +;; (define replace +;; (let ((replacements (alist->vhash replacements hashq))) +;; (lambda (type) +;; (match (vhash-assq type replacements) +;; (#f type) +;; ((_ . replacement) replacement))))) + +;; (service-type-mapping replace)) + +(define system-service-type->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 %system/home-service-type-mapping + (make-hash-table)) + +(define-syntax define-service-type-mapping + (syntax-rules (=3D>) + ((_ system-type =3D> home-type) + (hashq-set! %system/home-service-type-mapping + system-type home-type)))) + +(define-syntax define-service-type-mappings + (syntax-rules (=3D>) + ((_ (system-type =3D> home-type) ...) + (begin + (define-service-type-mapping system-type =3D> home-type) + ...)))) + +(define-service-type-mappings + (system-service-type =3D> home-service-type) + (activation-service-type =3D> home-activation-service-type)) + +;; (define system->home-service-type +;; (service-type-extensions-rewriting +;; `((,system-service-type . ,home-service-type) +;; (,activation-service-type . ,home-activation-service-type) +;; (,shepherd-root-service-type . ,home-shepherd-service-type)))) + ;;; ;;; On-change. diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm index 7a9cc064bb..21b73d8cdf 100644 --- a/gnu/home/services/shepherd.scm +++ b/gnu/home/services/shepherd.scm @@ -131,4 +131,5 @@ (define-public home-shepherd-service-type (default-value (home-shepherd-configuration)) (description "Configure and install userland Shepherd."))) =20 - +(define-service-type-mapping + shepherd-root-service-type =3D> home-shepherd-service-type) diff --git a/gnu/services/syncthing.scm b/gnu/services/syncthing.scm index 7c3d5b027d..130a87705e 100644 --- a/gnu/services/syncthing.scm +++ b/gnu/services/syncthing.scm @@ -57,7 +57,7 @@ (define syncthing-shepherd-service (shepherd-service (provision (list (string->symbol (string-append "syncthing-" user))= )) (documentation "Run syncthing.") - (requirement '(loopback)) + ;; (requirement '(loopback)) (start #~(make-forkexec-constructor (append (list (string-append #$syncthing "/bin/syncthing") "-no-browser" --=-=-=--