From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8K9+J02Jl2L1ZwEAbAwnHQ (envelope-from ) for ; Wed, 01 Jun 2022 17:44:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id uE2CJ02Jl2KoFAAA9RJhRA (envelope-from ) for ; Wed, 01 Jun 2022 17:44:13 +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 573AD3C689 for ; Wed, 1 Jun 2022 17:44:13 +0200 (CEST) Received: from localhost ([::1]:57758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwQW4-0004Cw-Gg for larch@yhetil.org; Wed, 01 Jun 2022 11:44:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwQVu-0004Ca-SU for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwQVu-00088x-Jw for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nwQVu-0001WZ-Hs for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55752] [PATCH 3/5] home: services: Add 'lookup-home-service-types' procedure. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 01 Jun 2022 15:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55752 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55752@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 55752-submit@debbugs.gnu.org id=B55752.16540982025760 (code B ref 55752); Wed, 01 Jun 2022 15:44:02 +0000 Received: (at 55752) by debbugs.gnu.org; 1 Jun 2022 15:43:22 +0000 Received: from localhost ([127.0.0.1]:51642 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwQVF-0001Uj-Lx for submit@debbugs.gnu.org; Wed, 01 Jun 2022 11:43:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwQVD-0001U9-1v for 55752@debbugs.gnu.org; Wed, 01 Jun 2022 11:43:20 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37376) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwQV6-00083U-JB; Wed, 01 Jun 2022 11:43:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=X9tthBaSnp2/5Ds8iMjYN9aqAm7N11KC5LZ/OloCTVo=; b=XU+bYlAnTm/LTm+hTI4Z +yJ6eLw4q6SQVi7H2yYCunEEyD6zDqRHaMM/octcTE7WwCyqGxymLYe4HT8xNtyGyrNT6lHEnicct 650pzBkC5Dw1AwsDRYzc4y59rYVy6kk/WIuKG+1XQE5ORHca5yetRVOuMa+nHJqMfpk8Itkup4LRL uEngd2xSTHynbd1glBr5XI+t9A5M89Uu9e8NwkSpiSzJavUhmWvAN5gzkjAdYEE9oEGHNyTRODZi5 3d4iJHcIhkVVDybpvRW2dKKpipLy1daO1TDV/AB6Yaps0Sd9cCpCSkC2R08e2NBEZWJhEF6VX5S2L oB8IjcJfgAgsUQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:55618 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwQV6-0006Xy-6e; Wed, 01 Jun 2022 11:43:12 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 1 Jun 2022 17:43:00 +0200 Message-Id: <20220601154302.16222-3-ludo@gnu.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220601154302.16222-1-ludo@gnu.org> References: <20220601154302.16222-1-ludo@gnu.org> 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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654098253; 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=X9tthBaSnp2/5Ds8iMjYN9aqAm7N11KC5LZ/OloCTVo=; b=dv6yGp1JtzLpaa4DQl8+/7JYUxew1GsiylugNZNfHQ/Etj2sEFVizxxb5pQWWNAd16oOjJ NivBo4qX4+fjTZoh7BSsRE7XLxgWMFe4h0wNXwxyns37fVstWmth/DEojvOjhS1wL2qI85 +Frbfoytr6VENrH/AZOQ2/a8W27m840uVQd8NSNBhVCYazF42nvSLK7mmDodmomtcsuM4i 2EQg9o+7dNXNmJoJ60cuaZUBIbwikY5tH41/0R2beo1yt770jb9kanuUjlRCIkf/VBU3oJ gZoWMhgeQSuuo85twsRh8ugxXY2Gn+m+FooZ4s1ibUhPVDovxEbkIA9qbiKAKg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654098253; a=rsa-sha256; cv=none; b=oLsSU1fKYFN7D7F5bcquW6a9aDZYKynUt99kTCNXPN5dYxFR82U9frCAqsc/i562idRdF5 /VqhXxOa2J+V3AsgpCe0SjKCtKWr/Z7YtNK3h9pc10kBzOEB2LKYsJaX2bH8knbir3l6iE DTB1SsJOse2/BDYoTC3BOSDfGnv0IdUkTcLN5beHxb9m54pF+xAKOtBQqFMwo0MrvWN+aQ Fq9eAkz+nBmFoAyvnnpKLEeGJZvM3ahfxKnzegDM8VreY4CcduZa7ffHE4w9USj0CfbnGR qP19SBu/PqKSZCz+MDmP7l5jLpcW912Rdwrj7PNyQcILTcZWnSe/E2SqT1FZgg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=XU+bYlAn; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.93 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=XU+bYlAn; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 573AD3C689 X-Spam-Score: -2.93 X-Migadu-Scanner: scn1.migadu.com X-TUID: r7dpf2aWEWSh * gnu/home/services.scm (lookup-home-service-types): New procedure. * tests/home-services.scm: New file. * Makefile.am (SCM_TESTS): Add it. --- Makefile.am | 1 + gnu/home/services.scm | 12 +++++++++++ tests/home-services.scm | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/home-services.scm diff --git a/Makefile.am b/Makefile.am index f585d00b86..89bc03c9a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -497,6 +497,7 @@ SCM_TESTS = \ tests/gremlin.scm \ tests/hackage.scm \ tests/home-import.scm \ + tests/home-services.scm \ tests/http-client.scm \ tests/import-git.scm \ tests/import-github.scm \ diff --git a/gnu/home/services.scm b/gnu/home/services.scm index 8284a4f3fc..5ee3357792 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -33,6 +33,7 @@ (define-module (gnu home services) #:use-module (guix modules) #:use-module (srfi srfi-1) #:use-module (ice-9 match) + #:use-module (ice-9 vlist) #:export (home-service-type home-profile-service-type @@ -50,6 +51,7 @@ (define-module (gnu home services) xdg-data-files-directory fold-home-service-types + lookup-home-service-types home-provenance %initialize-gettext) @@ -605,3 +607,13 @@ (define (all-home-service-modules) (define* (fold-home-service-types proc seed) (fold-service-types proc seed (all-home-service-modules))) + +(define lookup-home-service-types + (let ((table + (delay (fold-home-service-types (lambda (type result) + (vhash-consq (service-type-name type) + type result)) + vlist-null)))) + (lambda (name) + "Return the list of services with the given NAME (a symbol)." + (vhash-foldq* cons '() name (force table))))) diff --git a/tests/home-services.scm b/tests/home-services.scm new file mode 100644 index 0000000000..e13733cabd --- /dev/null +++ b/tests/home-services.scm @@ -0,0 +1,46 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Ludovic Courtès +;;; +;;; 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 (test-home-services) + #:use-module (gnu services) + #:use-module (gnu home services) + #:use-module (guix diagnostics) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-64) + #:use-module (ice-9 match)) + +(test-begin "home-services") + +(test-assert "fold-home-service-types" + (match (fold-home-service-types cons '()) + (() #f) + (lst (and (every service-type? lst) + (every (lambda (type) + (let ((location (service-type-location type))) + (string-contains (location-file location) + "gnu/home"))) + lst))))) + +(test-eq "lookup-service-types" + home-files-service-type + (and (null? (lookup-home-service-types 'does-not-exist-at-all)) + (match (lookup-home-service-types 'home-files) + ((one) one) + (x x)))) + +(test-end) -- 2.36.1