From patchwork Wed Feb 8 23:57:39 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: 46761 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 A1B821643C; Wed, 8 Feb 2023 23:58:28 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham 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 30AF7163D7 for ; Wed, 8 Feb 2023 23:58:27 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPuKC-0005Nt-Ee; Wed, 08 Feb 2023 18:58:04 -0500 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 1pPuKB-0005Nb-34 for guix-patches@gnu.org; Wed, 08 Feb 2023 18:58:03 -0500 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 1pPuKA-0004r7-Dg for guix-patches@gnu.org; Wed, 08 Feb 2023 18:58:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pPuK9-0000C0-PP for guix-patches@gnu.org; Wed, 08 Feb 2023 18:58:01 -0500 Subject: bug#60735: [PATCH 0/2] Implement etc-hosts-service-type Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-To: guix-patches@gnu.org Resent-Date: Wed, 08 Feb 2023 23:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 60735 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Bruno Victal Cc: 60735-done@debbugs.gnu.org Mail-Followup-To: 60735@debbugs.gnu.org, ludo@gnu.org, mirai@makinata.eu Received: via spool by 60735-done@debbugs.gnu.org id=D60735.1675900675723 (code D ref 60735); Wed, 08 Feb 2023 23:58:01 +0000 Received: (at 60735-done) by debbugs.gnu.org; 8 Feb 2023 23:57:55 +0000 Received: from localhost ([127.0.0.1]:56898 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pPuK2-0000BP-BC for submit@debbugs.gnu.org; Wed, 08 Feb 2023 18:57:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pPuJx-0000B8-8k for 60735-done@debbugs.gnu.org; Wed, 08 Feb 2023 18:57:53 -0500 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 1pPuJr-0004le-D3; Wed, 08 Feb 2023 18:57:43 -0500 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=6uO+dyD0+WSQ518m2v5NVQRvfTvr97tI6CPWFY/2BhE=; b=X1QSvUNgG/RvGT0qVasb 45MDqjQCF87jm5kQCUObmmtvWlTcVvmcZpm7QeX4crtO38Fnf/C1fyce6RCTyE4wWcwNpv/QbtA6O bBUofQ/nVfNxjj/RztmHGL4VgSOCcNI4Jcucjps7vx2TSwOtdml4WCQl5WjkX16BeFVDrclLfzj4m bI53iQxsArXpDZ1hXU15ZU4o021NpWhGpQIuY+zu8TRcFIxbgVfAqss5qMt1v9yA7p0HU7DVSYbHP 7ZZJLTt3fE2+SOjtwMb6Oc0uDxZjo6mmUA46zKFrKbdq04ky2W3tYHccy98RGSmmj1pbXZaMlN5oK Mn6sC7M2ijmAMQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPuJq-0008P2-Td; Wed, 08 Feb 2023 18:57:43 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= References: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> <55ce2a77151a50d5e6e179ce53b437a3d0dc6d2b.1674853530.git.mirai@makinata.eu> Date: Thu, 09 Feb 2023 00:57:39 +0100 In-Reply-To: <55ce2a77151a50d5e6e179ce53b437a3d0dc6d2b.1674853530.git.mirai@makinata.eu> (Bruno Victal's message of "Fri, 27 Jan 2023 21:06:13 +0000") Message-ID: <87zg9nvhfw.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 Hi Bruno, I’ve finally applied this v3 with the changes below: • spelling “host name” as two words and tweaking docstrings of public procedures; • keeping ‘local-host-aliases’ unchanged (returning a string) as this is public and documented, and adding ‘local-host-entries’ to return a list of records; • referencing to ‘%operating-system-hosts-file’ (with leading percent sign) internally to avoid deprecation warnings. Thank you! Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index 5edc0d20cc..2b21e12b88 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40246,10 +40246,7 @@ from being an alias of @code{localhost}. (operation-system-default-essential-services this-operating-system) (hosts-service-type config => (list (host "127.0.0.1" "localhost") - (host "::1" "localhost"))))) - - ;; @dots{} -) + (host "::1" "localhost")))))) @end lisp @end quotation diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 53eda9ea1e..e9fdafd5d0 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -700,16 +700,16 @@ (define* (rngd-service #:key ;;; (define (valid-name? name) - "Return true if @var{name} is likely to be a valid hostname." + "Return true if @var{name} is likely to be a valid host name." (false-if-exception (not (string-any char-set:whitespace name)))) (define-compile-time-procedure (assert-valid-name (name valid-name?)) - "Ensure @var{name} is likely to be a valid hostname." + "Ensure @var{name} is likely to be a valid host name." ;; TODO: RFC compliant implementation. (unless (valid-name? name) (raise (make-compound-condition - (formatted-message (G_ "hostname '~a' contains invalid characters") + (formatted-message (G_ "host name '~a' contains invalid characters") name) (condition (&error-location (location @@ -728,7 +728,12 @@ (define-record-type* %host (sanitize (cut map assert-valid-name <>)))) (define* (host address canonical-name #:optional (aliases '())) - "Public constructor for records." + "Return a new record for the host at @var{address} with the given +@var{canonical-name} and possibly @var{aliases}. + +@var{address} must be a string denoting a valid IPv4 or IPv6 address, and +@var{canonical-name} and the strings listed in @var{aliases} must be valid +host names." (%host (address address) (canonical-name canonical-name) diff --git a/gnu/system.scm b/gnu/system.scm index e8904cfab7..df60fda53b 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -170,7 +170,8 @@ (define-module (gnu system) read-boot-parameters-file boot-parameters->menu-entry - local-host-aliases + local-host-aliases ;deprecated + local-host-entries %root-account %setuid-programs %sudoers-specification @@ -749,7 +750,7 @@ (define known-fs (swaps (swap-services os)) (procs (service user-processes-service-type)) (host-name (operating-system-host-name os)) - (hosts-file (operating-system-hosts-file os)) + (hosts-file (%operating-system-hosts-file os)) (entries (operating-system-directory-base-entries os))) (cons* (service system-service-type entries) (service linux-builder-service-type @@ -776,7 +777,7 @@ (define known-fs (simple-service 'deprecated-hosts-file etc-service-type (list `("hosts" ,hosts-file))) (service hosts-service-type - (local-host-aliases host-name))) + (local-host-entries host-name))) (service fstab-service-type (filter file-system-needed-for-boot? (operating-system-file-systems os))) @@ -798,7 +799,7 @@ (define known-fs (define (hurd-default-essential-services os) (let ((host-name (operating-system-host-name os)) - (hosts-file (operating-system-hosts-file os)) + (hosts-file (%operating-system-hosts-file os)) (entries (operating-system-directory-base-entries os))) (list (service system-service-type entries) %boot-service @@ -824,7 +825,7 @@ (define (hurd-default-essential-services os) (simple-service 'deprecated-hosts-file etc-service-type (list `("hosts" ,hosts-file))) (service hosts-service-type - (local-host-aliases host-name))) + (local-host-entries host-name))) (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type (operating-system-packages os))))) @@ -943,8 +944,14 @@ (define %default-issue " This is the GNU system. Welcome.\n") -(define (local-host-aliases host-name) +(define-deprecated (local-host-aliases host-name) + local-host-entries "Return aliases for HOST-NAME, to be used in /etc/hosts." + (string-append "127.0.0.1 localhost " host-name "\n" + "::1 localhost " host-name "\n")) + +(define (local-host-entries host-name) + "Return records for @var{host-name}." (map (lambda (address) (host address "localhost" (list host-name))) '("127.0.0.1" "::1")))