From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WIp+HPG9WGFiNgAAgWs5BA (envelope-from ) for ; Sat, 02 Oct 2021 22:15:45 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WKw9GPG9WGE8LAAAB5/wlQ (envelope-from ) for ; Sat, 02 Oct 2021 20:15:45 +0000 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 051F335487 for ; Sat, 2 Oct 2021 22:15:45 +0200 (CEST) Received: from localhost ([::1]:49802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWlQ8-0002NR-5V for larch@yhetil.org; Sat, 02 Oct 2021 16:15:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWlPS-0001ot-6x for guix-patches@gnu.org; Sat, 02 Oct 2021 16:15:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWlPR-0002Vx-V5 for guix-patches@gnu.org; Sat, 02 Oct 2021 16:15:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mWlPR-0001YX-Qd for guix-patches@gnu.org; Sat, 02 Oct 2021 16:15:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50967] [PATCH] home: services: configuration: Move and refactor content. References: <20211002134352.5735-1-go.wigust@gmail.com> In-Reply-To: <20211002134352.5735-1-go.wigust@gmail.com> Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 02 Oct 2021 20:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50967 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 50967@debbugs.gnu.org Cc: Oleg Pykhalov Received: via spool by 50967-submit@debbugs.gnu.org id=B50967.16332056555895 (code B ref 50967); Sat, 02 Oct 2021 20:15:01 +0000 Received: (at 50967) by debbugs.gnu.org; 2 Oct 2021 20:14:15 +0000 Received: from localhost ([127.0.0.1]:60672 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWlOc-0001Ww-Qq for submit@debbugs.gnu.org; Sat, 02 Oct 2021 16:14:14 -0400 Received: from mail-lf1-f51.google.com ([209.85.167.51]:44896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWlOb-0001Wi-1K for 50967@debbugs.gnu.org; Sat, 02 Oct 2021 16:14:10 -0400 Received: by mail-lf1-f51.google.com with SMTP id y26so53405524lfa.11 for <50967@debbugs.gnu.org>; Sat, 02 Oct 2021 13:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VP0Mij6685Imz9vTeFC6Sa0qxEXhtBSgyCxe+qT1OpM=; b=cSB//IPzXng933VERlWut83kiTtL8Wj9LoWMQctk3zdVZE5Fm6eE+btEDBurpUJw4u 1T9MkIWtDakjKtQfYXJDy3yoolVabnVEbzEXCymH6jB1yDpki75UTbi4/XYMZtxCWve+ xXC1216ROM2wpt6GQTNKwBAWEcKJd9vJQEjFYeQ1BdfQa0afIZS8MUCse8riRaCxT/xE l/Pa4hdx88F7rFP8si9sXq+KMZfxwVqQARwMoZ97jlyRtWgjmYUUwT3lvIBFQUquILlN hl6sGmI4L8IKUNdAo9ypxG4k6m+BphwA+yOM1dnFV0ZosFnMFxRiWx1cGESBPHqeIo0i fCbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VP0Mij6685Imz9vTeFC6Sa0qxEXhtBSgyCxe+qT1OpM=; b=cPDd5NYAzGe6RkZnjK6Ol8Ml/6IpXge03j7aYQg19S4wmZr57Am8lUbcHnqPC+1g+E uLkedf7e80BsTb3t7YjdWCF/hgVI6r9ac+Roi/EYcpF0Jj/MT1fdfDNBDSFJ6CCzV7qK e+GlUQUJ+dlnxeocLGbCkSrmG4i7cMWzbN9b/E5L21WCDAftPiVpeN2EmFtf6kOJYBIB c7unCim3RpaT9HI/yZ7jsHqW0PwwP6gQtvvL8YrrxJB1EWpLYPaVdURPdXYrdquOO++X lA6B78ErtBOzRbrSTSxN+gyOPHijBJPJJCHFhteh6yPaeieTbjtm2GDi0nXrs2cZV+1O BWWQ== X-Gm-Message-State: AOAM531/XfGMX1rJpnogtEmyyO7KsxuGEMfq8q2QUpV09va/zLn34Shk /UptPFa+cAHjbxC2IX+E5ZdmBNOYgIY= X-Google-Smtp-Source: ABdhPJzWvRFMRIWidt1alWSTgAwOaf/Z1HlLxMaItuezvOUxEbb0V6i0FkjWbtxIELYE3/1IAGtHPw== X-Received: by 2002:a19:c395:: with SMTP id t143mr648973lff.89.1633205642510; Sat, 02 Oct 2021 13:14:02 -0700 (PDT) Received: from localhost.localdomain ([88.201.161.72]) by smtp.gmail.com with ESMTPSA id 23sm1039194ljq.83.2021.10.02.13.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Oct 2021 13:14:02 -0700 (PDT) From: Oleg Pykhalov Date: Sat, 2 Oct 2021 23:13:46 +0300 Message-Id: <20211002201346.10568-1-go.wigust@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633205745; 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: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=VP0Mij6685Imz9vTeFC6Sa0qxEXhtBSgyCxe+qT1OpM=; b=ZSQzQlqrLrqv4zODr5fNgin8/ho93lohnDJ4W6kPFTBALOy0MbD9ec0xrbtc0HSaGRJdUs RX+zSRGzLUVoEcsjz3348DNt+MyJupf6qwdvvYxi72xB8SGRGfAABzq0dWrgCqNxRiEizh z8DyqCEgptol5VcghsrdvVRZN8qdHyZrkK2U08WDy4X3mxtuhsliOmpb0yICibbTtb5i8+ qghUkanqXGxdDFOnekM/UqhBCrCzhsMPpSuvihSAeTcnYVrnGJP/1n4fmwPx2rMCu5iyH8 7uadZqT782PYVFD2TA8yqnvXZfk5/w2FtQTIPy8u/lrMYki+qwCNtw3esUv6mw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633205745; a=rsa-sha256; cv=none; b=S0aPtVZzKDsWhTTuysXFNlXJsgm2lgNswVSzpqgNbhPKjWLWZ3cNE9pXuRwcwPEeuOK0wv GWGVXrrEAtkyXtWfiMCQrwpWZwgzNHoBNIwriqQsX0LWMjTSqb4bUFeFC73RT0+2psBKZv ZiKERO9jFNvTnMBZqPZ1wrpcx4XEtV7l4WTW8iLiasKryVF62UlzIZGUYWIXh3BUDc6dbv Px89sM6VRocF30Q0GqLVHWh+1LAqxZtVNJ6PXA4JjVMzOqj6AQ6Z2MAznakOohyQHUo34Y xql40LVUb0655/2tKjTOHdHXGFurQSWNGLeVOYcOCTOpm1t5Y66G3tdupbH4gw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="cSB//IPz"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.31 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="cSB//IPz"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 051F335487 X-Spam-Score: -1.31 X-Migadu-Scanner: scn0.migadu.com X-TUID: CDPILCtbUmtE * gnu/home/services/configuration.scm: Move content ... * gnu/services/configuration.scm: here. * gnu/home/services/shells.scm: Delete (gnu home services configuration). * gnu/home/services/xdg.scm: Same. * gnu/local.mk: Same. --- gnu/home/services/configuration.scm | 115 ---------------------------- gnu/home/services/shells.scm | 1 - gnu/home/services/xdg.scm | 1 - gnu/local.mk | 1 - gnu/services/configuration.scm | 95 ++++++++++++++++++++++- 5 files changed, 93 insertions(+), 120 deletions(-) delete mode 100644 gnu/home/services/configuration.scm diff --git a/gnu/home/services/configuration.scm b/gnu/home/services/configuration.scm deleted file mode 100644 index 39db7a5693..0000000000 --- a/gnu/home/services/configuration.scm +++ /dev/null @@ -1,115 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2021 Andrew Tropin -;;; Copyright © 2021 Xinglu Chen -;;; -;;; 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 . - -(define-module (gnu home services configuration) - #:use-module (gnu services configuration) - #:use-module (guix gexp) - #:use-module (srfi srfi-1) - #:use-module (ice-9 curried-definitions) - #:use-module (ice-9 match) - #:use-module (guix i18n) - #:use-module (guix diagnostics) - - #:export (filter-configuration-fields - - interpose - list-of - - list-of-strings? - alist? - string-or-gexp? - serialize-string-or-gexp - text-config? - serialize-text-config - generic-serialize-alist-entry - generic-serialize-alist)) - -(define* (filter-configuration-fields configuration-fields fields - #:optional negate?) - "Retrieve the fields listed in FIELDS from CONFIGURATION-FIELDS. -If NEGATE? is @code{#t}, retrieve all fields except FIELDS." - (filter (lambda (field) - (let ((member? (member (configuration-field-name field) fields))) - (if (not negate?) member? (not member?)))) - configuration-fields)) - - -(define* (interpose ls #:optional (delimiter "\n") (grammar 'infix)) - "Same as @code{string-join}, but without join and string, returns an -DELIMITER interposed LS. Support 'infix and 'suffix GRAMMAR values." - (when (not (member grammar '(infix suffix))) - (raise - (formatted-message - (G_ "The GRAMMAR value must be 'infix or 'suffix, but ~a provided.") - grammar))) - (fold-right (lambda (e acc) - (cons (if (file-like? e) - #~(begin - (use-modules (ice-9 rdelim)) - (with-fluids ((%default-port-encoding "UTF-8")) - (with-input-from-file #$e read-string))) - e) - (if (and (null? acc) (eq? grammar 'infix)) - acc - (cons delimiter acc)))) - '() ls)) - -(define (list-of pred?) - "Return a procedure that takes a list and check if all the elements of -the list result in @code{#t} when applying PRED? on them." - (lambda (x) - (if (list? x) - (every pred? x) - #f))) - - -(define list-of-strings? - (list-of string?)) - -(define alist? list?) - -(define (file-or-string-or-gexp? fsg) - (or (string? fsg) (gexp? fsg) (file-like? fsg))) -(define (serialize-file-or-string-or-gexp field-name val) "") - -(define (text-config? config) - (and (list? config) (every file-or-string-or-gexp? config))) -(define (serialize-text-config field-name val) - #~(string-append #$@(interpose val "\n" 'suffix))) - -(define ((generic-serialize-alist-entry serialize-field) entry) - "Apply the SERIALIZE-FIELD procedure on the field and value of ENTRY." - (match entry - ((field . val) (serialize-field field val)))) - -(define (generic-serialize-alist combine serialize-field fields) - "Generate a configuration from an association list FIELDS. - -SERIALIZE-FIELD is a procedure that takes two arguments, it will be -applied on the fields and values of FIELDS using the -@code{generic-serialize-alist-entry} procedure. - -COMBINE is a procedure that takes one or more arguments and combines -all the alist entries into one value, @code{string-append} or -@code{append} are usually good candidates for this. - -See the @code{serialize-alist} procedure in `@code{(gnu home-services -version-control}' for an example usage.)}" - (apply combine - (map (generic-serialize-alist-entry serialize-field) fields))) diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index 2308371dd0..4e5825962c 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -19,7 +19,6 @@ (define-module (gnu home services shells) #:use-module (gnu services configuration) - #:use-module (gnu home services configuration) #:use-module (gnu home services utils) #:use-module (gnu home-services) #:use-module (gnu packages shells) diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm index 4aed9a5803..c285d126dd 100644 --- a/gnu/home/services/xdg.scm +++ b/gnu/home/services/xdg.scm @@ -19,7 +19,6 @@ (define-module (gnu home services xdg) #:use-module (gnu services configuration) - #:use-module (gnu home services configuration) #:use-module (gnu home-services) #:use-module (gnu packages freedesktop) #:use-module (gnu home services utils) diff --git a/gnu/local.mk b/gnu/local.mk index 5e8b769ce9..9c3bf44a2b 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -77,7 +77,6 @@ GNU_SYSTEM_MODULES = \ %D%/home-services.scm \ %D%/home/services/symlink-manager.scm \ %D%/home/services/fontutils.scm \ - %D%/home/services/configuration.scm \ %D%/home/services/shells.scm \ %D%/home/services/shepherd.scm \ %D%/home/services/mcron.scm \ diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index df3d3b6f9b..1829dbd2bf 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2017, 2018 Clément Lassieur ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2021 Andrew Tropin ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,10 +26,12 @@ #:use-module (guix records) #:use-module (guix gexp) #:use-module ((guix utils) #:select (source-properties->location)) - #:use-module ((guix diagnostics) #:select (location-file)) + #:use-module ((guix diagnostics) #:select (formatted-message location-file)) #:use-module ((guix modules) #:select (file-name->module-name)) + #:use-module (guix i18n) #:autoload (texinfo) (texi-fragment->stexi) #:autoload (texinfo serialize) (stexi->texi) + #:use-module (ice-9 curried-definitions) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-34) @@ -56,7 +59,21 @@ generate-documentation configuration->documentation empty-serializer - serialize-package)) + serialize-package + + filter-configuration-fields + + interpose + list-of + + list-of-strings? + alist? + string-or-gexp? + serialize-string-or-gexp + text-config? + serialize-text-config + generic-serialize-alist-entry + generic-serialize-alist)) ;;; Commentary: ;;; @@ -323,3 +340,77 @@ Texinfo documentation of its fields." '-fields)))) (display (generate-documentation `((,configuration-symbol ,fields-getter)) configuration-symbol)))) + +(define* (filter-configuration-fields configuration-fields fields + #:optional negate?) + "Retrieve the fields listed in FIELDS from CONFIGURATION-FIELDS. +If NEGATE? is @code{#t}, retrieve all fields except FIELDS." + (filter (lambda (field) + (let ((member? (member (configuration-field-name field) fields))) + (if (not negate?) member? (not member?)))) + configuration-fields)) + + +(define* (interpose ls #:optional (delimiter "\n") (grammar 'infix)) + "Same as @code{string-join}, but without join and string, returns an +DELIMITER interposed LS. Support 'infix and 'suffix GRAMMAR values." + (when (not (member grammar '(infix suffix))) + (raise + (formatted-message + (G_ "The GRAMMAR value must be 'infix or 'suffix, but ~a provided.") + grammar))) + (fold-right (lambda (e acc) + (cons (if (file-like? e) + #~(begin + (use-modules (ice-9 rdelim)) + (with-fluids ((%default-port-encoding "UTF-8")) + (with-input-from-file #$e read-string))) + e) + (if (and (null? acc) (eq? grammar 'infix)) + acc + (cons delimiter acc)))) + '() ls)) + +(define (list-of pred?) + "Return a procedure that takes a list and check if all the elements of +the list result in @code{#t} when applying PRED? on them." + (lambda (x) + (if (list? x) + (every pred? x) + #f))) + + +(define list-of-strings? + (list-of string?)) + +(define alist? list?) + +(define (file-like-or-string-or-gexp? fsg) + (or (string? fsg) (gexp? fsg) (file-like? fsg))) +(define serialize-file-like-or-string-or-gexp empty-serializer) + +(define (text-config? config) + (list-of file-like-or-string-or-gexp?)) +(define (serialize-text-config field-name val) + #~(string-append #$@(interpose val "\n" 'suffix))) + +(define ((generic-serialize-alist-entry serialize-field) entry) + "Apply the SERIALIZE-FIELD procedure on the field and value of ENTRY." + (match entry + ((field . val) (serialize-field field val)))) + +(define (generic-serialize-alist combine serialize-field fields) + "Generate a configuration from an association list FIELDS. + +SERIALIZE-FIELD is a procedure that takes two arguments, it will be +applied on the fields and values of FIELDS using the +@code{generic-serialize-alist-entry} procedure. + +COMBINE is a procedure that takes one or more arguments and combines +all the alist entries into one value, @code{string-append} or +@code{append} are usually good candidates for this. + +See the @code{serialize-alist} procedure in `@code{(gnu home-services +version-control}' for an example usage.)}" + (apply combine + (map (generic-serialize-alist-entry serialize-field) fields))) -- 2.33.0