From patchwork Tue Mar 28 16:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 48778 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8B5401710F; Tue, 28 Mar 2023 17:19:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAD_ENC_HEADER,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 553E516F60 for ; Tue, 28 Mar 2023 17:19:16 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phC2K-0002CA-LQ; Tue, 28 Mar 2023 12:19:04 -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 1phC2J-0002Bh-4q for guix-patches@gnu.org; Tue, 28 Mar 2023 12:19:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phC2I-0008IV-TG for guix-patches@gnu.org; Tue, 28 Mar 2023 12:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1phC2I-0005jJ-DI for guix-patches@gnu.org; Tue, 28 Mar 2023 12:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62401] Automatically mapping services from System to Home Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 28 Mar 2023 16:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62401 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Sergey Trofimov Cc: guix-devel@gnu.org, paren@disroot.org, 62401@debbugs.gnu.org, andrew@trop.in Received: via spool by 62401-submit@debbugs.gnu.org id=B62401.168002031421991 (code B ref 62401); Tue, 28 Mar 2023 16:19:02 +0000 Received: (at 62401) by debbugs.gnu.org; 28 Mar 2023 16:18:34 +0000 Received: from localhost ([127.0.0.1]:50568 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phC1p-0005ic-Cb for submit@debbugs.gnu.org; Tue, 28 Mar 2023 12:18:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33150) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phC1n-0005iQ-RB for 62401@debbugs.gnu.org; Tue, 28 Mar 2023 12:18:32 -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: Ludovic =?utf-8?q?Court=C3=A8s?= 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=A9volution, ?= 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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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. Thoughts? Ludo’. 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 © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Ludovic Courtès ;;; ;;; 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) #:export (home-service-type home-profile-service-type @@ -46,6 +49,9 @@ (define-module (gnu home services) fold-home-service-types home-provenance + define-service-type-mapping + system-service-type->home-service-type + %initialize-gettext) #: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."))) + +;;; +;;; 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 (=>) + ((_ 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)) + +;; (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."))) - +(define-service-type-mapping + shepherd-root-service-type => 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"