From unknown Mon Jun 16 23:46:29 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#60735 <60735@debbugs.gnu.org> To: bug#60735 <60735@debbugs.gnu.org> Subject: Status: [PATCH 0/2] Implement etc-hosts-service-type Reply-To: bug#60735 <60735@debbugs.gnu.org> Date: Tue, 17 Jun 2025 06:46:29 +0000 retitle 60735 [PATCH 0/2] Implement etc-hosts-service-type reassign 60735 guix-patches submitter 60735 Bruno Victal severity 60735 normal tag 60735 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 11 12:26:47 2023 Received: (at submit) by debbugs.gnu.org; 11 Jan 2023 17:26:48 +0000 Received: from localhost ([127.0.0.1]:43712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFesB-0003Zj-Mb for submit@debbugs.gnu.org; Wed, 11 Jan 2023 12:26:47 -0500 Received: from lists.gnu.org ([209.51.188.17]:42046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFes9-0003Zb-M8 for submit@debbugs.gnu.org; Wed, 11 Jan 2023 12:26:46 -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 1pFes4-0004wb-CD for guix-patches@gnu.org; Wed, 11 Jan 2023 12:26:40 -0500 Received: from smtpmciv8.myservices.hosting ([185.26.106.203]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pFes2-00010f-FE for guix-patches@gnu.org; Wed, 11 Jan 2023 12:26:40 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpmciv8.myservices.hosting (Postfix) with ESMTP id A926320E2F; Wed, 11 Jan 2023 18:26:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 627E080096; Wed, 11 Jan 2023 18:26:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id zDOu8bxpYRXW; Wed, 11 Jan 2023 18:26:33 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id D14A480093; Wed, 11 Jan 2023 18:26:32 +0100 (CET) From: Bruno Victal To: guix-patches@gnu.org Subject: [PATCH 0/2] Implement etc-hosts-service-type Date: Wed, 11 Jan 2023 17:26:23 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Debbugs-CC: ludo@gnu.org tags: patch Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.26.106.203; envelope-from=mirai@makinata.eu; helo=smtpmciv8.myservices.hosting X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Bruno Victal , maxim.cournoyer@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This patch-set introduces etc-hosts-service-type which allows for /etc/hosts to be extended with service-extensions. As an example of such a service, %facebook-host-aliases was used as a base for the new block-facebook-hosts-service-type. Indirectly solves #59700. Bruno Victal (2): services: Add etc-hosts-service-type. services: Add block-facebook-hosts-service-type. doc/guix.texi | 42 ++++++++++++------------- gnu/services.scm | 18 +++++++++++ gnu/services/networking.scm | 61 ++++++++++++++++++------------------- gnu/system.scm | 55 ++++++++++++++++++++++++--------- 4 files changed, 107 insertions(+), 69 deletions(-) base-commit: c42ae60a84f0e7c30126f726a0057781b81f5074 -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 11 12:28:41 2023 Received: (at 60735) by debbugs.gnu.org; 11 Jan 2023 17:28:41 +0000 Received: from localhost ([127.0.0.1]:43729 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFeu0-0003dh-Ax for submit@debbugs.gnu.org; Wed, 11 Jan 2023 12:28:41 -0500 Received: from smtpm3.myservices.hosting ([185.26.105.234]:58528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFetx-0003dY-VI for 60735@debbugs.gnu.org; Wed, 11 Jan 2023 12:28:39 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm3.myservices.hosting (Postfix) with ESMTP id 478A121102 for <60735@debbugs.gnu.org>; Wed, 11 Jan 2023 18:28:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 06B4780096; Wed, 11 Jan 2023 18:28:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qtDgHqOWWAs3; Wed, 11 Jan 2023 18:28:36 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 33E4E80093; Wed, 11 Jan 2023 18:28:36 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH 1/2] services: Add etc-hosts-service-type. Date: Wed, 11 Jan 2023 17:28:13 +0000 Message-Id: <0248101fa24f80f52a0412930598a7bbc9f71194.1673457786.git.mirai@makinata.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/services.scm (etc-hosts-service-type): New variable. * gnu/system.scm (operating-system-hosts-file): Deprecate procedure. (warn-hosts-file-field-deprecation): New procedure, helper for deprecated variable). (operating-system)[hosts-file]: Use helper to warn deprecated field. (operating-system-default-essential-services) (hurd-default-essential-services): Use etc-hosts-service-type. (local-host-aliases): Return a list of strings representing hosts file entries. (default-/etc/hosts): Remove procedure. (operating-system-etc-service): Remove hosts file. * doc/guix.texi: Document it. --- doc/guix.texi | 13 ++++++++++++ gnu/services.scm | 18 ++++++++++++++++ gnu/system.scm | 55 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 39c6468651..a55634ba8c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -111,6 +111,7 @@ Copyright @copyright{} 2022 John Kehayias@* Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@* Copyright @copyright{} 2023 Giacomo Leidi@* +Copyright @copyright{} 2023 Bruno Victal@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -40121,6 +40122,18 @@ Service Reference pointing to the given file. @end defvr +@defvar etc-hosts-service-type +Type of the service that populates the entries for (@file{/etc/hosts}). +This service can be extended by passing it lists of strings such as: + +@c TRANSLATORS: The domain names below SHOULD NOT be translated. +@c They're domains reserved for use in documentation. (RFC6761 Section 6.5) +@lisp +(list "127.0.0.1 example.com example.net" + "::1 example.com example.net" +@end lisp +@end defvar + @defvr {Scheme Variable} setuid-program-service-type Type for the ``setuid-program service''. This service collects lists of executable file names, passed as gexps, and adds them to the set of diff --git a/gnu/services.scm b/gnu/services.scm index 2abef557d4..2d8e2c8ad2 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -6,6 +6,7 @@ ;;; Copyright © 2021 raid5atemyhomework ;;; Copyright © 2020 Christine Lemmer-Webber ;;; Copyright © 2020, 2021 Brice Waegeneire +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -109,6 +110,7 @@ (define-module (gnu services) extra-special-file etc-service-type etc-directory + etc-hosts-service-type setuid-program-service-type profile-service-type firmware-service-type @@ -809,6 +811,22 @@ (define (etc-service files) FILES must be a list of name/file-like object pairs." (service etc-service-type files)) +(define etc-hosts-service-type + ;; Extend etc-service-type with a entry for @file{/etc/hosts}. + (service-type + (name 'etc-hosts) + (extensions + (list + (service-extension etc-service-type + (lambda (lst) + `(("hosts" + ,(plain-file "hosts" + (string-join lst "\n" + 'suffix)))))))) + (compose concatenate) + (extend append) + (description "Populate the @file{/etc/hosts} file."))) + (define (setuid-program->activation-gexp programs) "Return an activation gexp for setuid-program from PROGRAMS." (let ((programs (map (lambda (program) diff --git a/gnu/system.scm b/gnu/system.scm index d67f9a615b..a1514b5109 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -14,6 +14,7 @@ ;;; Copyright © 2020, 2022 Efraim Flashner ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2021 raid5atemyhomework +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,6 +32,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu system) + #:use-module (guix discovery) #:use-module (guix inferior) #:use-module (guix store) #:use-module (guix memoization) @@ -97,7 +99,7 @@ (define-module (gnu system) operating-system-user-services operating-system-packages operating-system-host-name - operating-system-hosts-file + operating-system-hosts-file ;deprecated operating-system-hurd operating-system-kernel operating-system-kernel-file @@ -208,6 +210,15 @@ (define* (bootable-kernel-arguments system root-device version) #$system "/boot"))) ;; System-wide configuration. + +(define-with-syntax-properties (warn-hosts-file-field-deprecation + (value properties)) + (when value + (warning (source-properties->location properties) + (G_ "the 'hosts-file' field is deprecated, please use \ +'etc-hosts-service-type' instead~%"))) + value) + ;; TODO: Add per-field docstrings/stexi. (define-record-type* operating-system make-operating-system @@ -239,8 +250,9 @@ (define-record-type* operating-system (default %base-firmware)) (host-name operating-system-host-name) ; string - (hosts-file operating-system-hosts-file ; file-like | #f - (default #f)) + (hosts-file %operating-system-hosts-file ; deprecated + (default #f) + (sanitize warn-hosts-file-field-deprecation)) (mapped-devices operating-system-mapped-devices ; list of (default '())) @@ -296,6 +308,10 @@ (define-record-type* operating-system source-properties->location)) (innate))) +(define-deprecated (operating-system-hosts-file os) + etc-hosts-service-type + (%operating-system-hosts-file os)) + (define* (operating-system-kernel-arguments os root-device #:key (version %boot-parameters-version)) "Return all the kernel arguments, including the ones not specified directly @@ -733,7 +749,8 @@ (define (operating-system-default-essential-services os) (non-boot-fs (non-boot-file-system-service os)) (swaps (swap-services os)) (procs (service user-processes-service-type)) - (host-name (host-name-service (operating-system-host-name os))) + (host-name (operating-system-host-name 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 @@ -755,12 +772,19 @@ (define (operating-system-default-essential-services os) (operating-system-groups os)) (operating-system-skeletons os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service etc-hosts-service-type + (local-host-aliases host-name))) (service fstab-service-type (filter file-system-needed-for-boot? (operating-system-file-systems os))) (session-environment-service (operating-system-environment-variables os)) - host-name procs root-fs + (host-name-service host-name) + procs root-fs (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type @@ -774,7 +798,9 @@ (define (operating-system-default-essential-services os) (operating-system-firmware os))))))) (define (hurd-default-essential-services os) - (let ((entries (operating-system-directory-base-entries os))) + (let ((host-name (operating-system-host-name os)) + (hosts-file (operating-system-hosts-file os)) + (entries (operating-system-directory-base-entries os))) (list (service system-service-type entries) %boot-service %hurd-startup-service @@ -794,6 +820,12 @@ (define (hurd-default-essential-services os) (operating-system-file-systems os))) (pam-root-service (operating-system-pam-services os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service etc-hosts-service-type + (local-host-aliases host-name))) (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type (operating-system-packages os))))) @@ -914,12 +946,9 @@ (define %default-issue (define (local-host-aliases host-name) "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 (default-/etc/hosts host-name) - "Return the default /etc/hosts file." - (plain-file "hosts" (local-host-aliases host-name))) + (list + (string-join `("127.0.0.1" "localhost" ,host-name) "\t") + (string-join `("::1" "localhost" ,host-name) "\t"))) (define (validated-sudoers-file file) "Return a copy of FILE, a sudoers file, after checking that it is @@ -1068,8 +1097,6 @@ (define* (operating-system-etc-service os) ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '()) ("profile" ,#~#$profile) ("bashrc" ,#~#$bashrc) - ("hosts" ,#~#$(or (operating-system-hosts-file os) - (default-/etc/hosts (operating-system-host-name os)))) ;; Write the operating-system-host-name to /etc/hostname to prevent ;; NetworkManager from changing the system's hostname when connecting ;; to certain networks. Some discussion at -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 11 12:28:50 2023 Received: (at 60735) by debbugs.gnu.org; 11 Jan 2023 17:28:50 +0000 Received: from localhost ([127.0.0.1]:43732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFeuA-0003e6-5X for submit@debbugs.gnu.org; Wed, 11 Jan 2023 12:28:50 -0500 Received: from smtpm3.myservices.hosting ([185.26.105.234]:58560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pFeu7-0003dx-Vl for 60735@debbugs.gnu.org; Wed, 11 Jan 2023 12:28:48 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm3.myservices.hosting (Postfix) with ESMTP id 88AB721102 for <60735@debbugs.gnu.org>; Wed, 11 Jan 2023 18:28:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 4731C80096; Wed, 11 Jan 2023 18:28:47 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ePxDfwfySSWo; Wed, 11 Jan 2023 18:28:45 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id ECE9280093; Wed, 11 Jan 2023 18:28:44 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH 2/2] services: Add block-facebook-hosts-service-type. Date: Wed, 11 Jan 2023 17:28:14 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Deprecates %facebook-host-aliases in favour of using etc-hosts-service-type service extensions. * gnu/services/networking.scm (block-facebook-hosts-service-type): New variable. (%facebook-host-aliases): Deprecate variable. * doc/guix.texi: Document it. --- doc/guix.texi | 29 ++++-------------- gnu/services/networking.scm | 61 ++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 55 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index a55634ba8c..703e0e6769 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20952,34 +20952,17 @@ Networking Services @end table @end deftp -@defvr {Scheme Variable} %facebook-host-aliases -This variable contains a string for use in @file{/etc/hosts} -(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each -line contains a entry that maps a known server name of the Facebook +@defvar block-facebook-hosts-service-type +This service type adds a list of known Facebook hosts to the +@file{/etc/hosts} file. +(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}) +Each line contains a entry that maps a known server name of the Facebook on-line service---e.g., @code{www.facebook.com}---to the local host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. -This variable is typically used in the @code{hosts-file} field of an -@code{operating-system} declaration (@pxref{operating-system Reference, -@file{/etc/hosts}}): - -@lisp -(use-modules (gnu) (guix)) - -(operating-system - (host-name "mymachine") - ;; ... - (hosts-file - ;; Create a /etc/hosts file with aliases for "localhost" - ;; and "mymachine", as well as for Facebook servers. - (plain-file "hosts" - (string-append (local-host-aliases host-name) - %facebook-host-aliases)))) -@end lisp - This mechanism can prevent programs running locally, such as Web browsers, from accessing Facebook. -@end defvr +@end defvar The @code{(gnu services avahi)} provides the following definition. diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 702404bc6c..9e5caed3c5 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -19,6 +19,7 @@ ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2022 Andrew Tropin +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -79,7 +80,9 @@ (define-module (gnu services networking) #:use-module (json) #:re-export (static-networking-service static-networking-service-type) - #:export (%facebook-host-aliases + #:export (%facebook-host-aliases ;deprecated + block-facebook-hosts-service-type + dhcp-client-service-type dhcp-client-configuration dhcp-client-configuration? @@ -234,39 +237,33 @@ (define-module (gnu services networking) ;;; ;;; Code: -(define %facebook-host-aliases +(define facebook-host-aliases ;; This is the list of known Facebook hosts to be added to /etc/hosts if you ;; are to block it. - "\ -# Block Facebook IPv4. -127.0.0.1 www.facebook.com -127.0.0.1 facebook.com -127.0.0.1 login.facebook.com -127.0.0.1 www.login.facebook.com -127.0.0.1 fbcdn.net -127.0.0.1 www.fbcdn.net -127.0.0.1 fbcdn.com -127.0.0.1 www.fbcdn.com -127.0.0.1 static.ak.fbcdn.net -127.0.0.1 static.ak.connect.facebook.com -127.0.0.1 connect.facebook.net -127.0.0.1 www.connect.facebook.net -127.0.0.1 apps.facebook.com - -# Block Facebook IPv6. -fe80::1%lo0 facebook.com -fe80::1%lo0 login.facebook.com -fe80::1%lo0 www.login.facebook.com -fe80::1%lo0 fbcdn.net -fe80::1%lo0 www.fbcdn.net -fe80::1%lo0 fbcdn.com -fe80::1%lo0 www.fbcdn.com -fe80::1%lo0 static.ak.fbcdn.net -fe80::1%lo0 static.ak.connect.facebook.com -fe80::1%lo0 connect.facebook.net -fe80::1%lo0 www.connect.facebook.net -fe80::1%lo0 apps.facebook.com\n") - + (let ((domains '("facebook.com" "www.facebook.com" + "login.facebook.com" "www.login.facebook.com" + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com" + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" + "connect.facebook.net" "www.connect.facebook.net" + "apps.facebook.com"))) + (fold (lambda (x tail) + (cons* (string-join `("127.0.0.1" ,x) "\t") + (string-join `("::1" ,x) "\t") + tail)) + '() domains))) + +(define-deprecated %facebook-host-aliases + block-facebook-hosts-service-type + (string-join facebook-host-aliases "\n" 'suffix)) + +(define block-facebook-hosts-service-type + (service-type + (name 'block-facebook-hosts) + (extensions + (list (service-extension etc-hosts-service-type + (const facebook-host-aliases)))) + (default-value #f) + (description "Add a list of known Facebook hosts to @file{/etc/hosts}"))) (define-record-type* dhcp-client-configuration make-dhcp-client-configuration -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 14 12:30:22 2023 Received: (at 60735) by debbugs.gnu.org; 14 Jan 2023 17:30:22 +0000 Received: from localhost ([127.0.0.1]:55484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGkMI-0003yp-9o for submit@debbugs.gnu.org; Sat, 14 Jan 2023 12:30:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGkMG-0003yc-2T for 60735@debbugs.gnu.org; Sat, 14 Jan 2023 12:30:21 -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 1pGkM9-0001jX-8t; Sat, 14 Jan 2023 12:30:14 -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=Q72rthPK3vDCTcfYK/mYrZO+rvR2+Ug27G19U6+PA7Q=; b=p9iEciv6KWMyRDtkqcmh QBzUlN8bbRE0fNuEEpEnWrsCt5Q2UmylxTNxBIb9gztM+zcBNCJF5oc+VSqR3GtvxJFyd8MUpydzy TBq9VC6sU/OnC7PUDnI/HM6qrcXQzfMxAdmxNlueG3f57SHbeqOySIrkMVr/LRNWcM9Ej9F7Bef5z ElwQHV8PfiOeh/dLFeHEIO+ltn0EHl9r8Tls6imC0GYbGilTSHyWRoIbPsoQTGCR8RHeYl5WgE7Zg tyyPOiyDtoVxokDCZLlPy/Gmt+hsH/hHO0evCvMGohqhmTEwL/VNiKYmfljEhnsYncnHnFZEnweod nScx+0r1CB/kdg==; 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 1pGkM7-0003gP-9T; Sat, 14 Jan 2023 12:30:12 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: bug#60735: [PATCH 0/2] Implement etc-hosts-service-type References: <0248101fa24f80f52a0412930598a7bbc9f71194.1673457786.git.mirai@makinata.eu> Date: Sat, 14 Jan 2023 18:30:08 +0100 In-Reply-To: <0248101fa24f80f52a0412930598a7bbc9f71194.1673457786.git.mirai@makinata.eu> (Bruno Victal's message of "Wed, 11 Jan 2023 17:28:13 +0000") Message-ID: <87v8l981nj.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello Bruno, Bruno Victal skribis: > * gnu/services.scm (etc-hosts-service-type): New variable. > * gnu/system.scm (operating-system-hosts-file): Deprecate procedure. > (warn-hosts-file-field-deprecation): New procedure, helper for > deprecated variable). > (operating-system)[hosts-file]: Use helper to warn deprecated field. > (operating-system-default-essential-services) > (hurd-default-essential-services): Use etc-hosts-service-type. > (local-host-aliases): Return a list of strings representing hosts file en= tries. > (default-/etc/hosts): Remove procedure. > (operating-system-etc-service): Remove hosts file. > * doc/guix.texi: Document it. Neat! Some comments: > +@defvar etc-hosts-service-type > +Type of the service that populates the entries for (@file{/etc/hosts}). > +This service can be extended by passing it lists of strings such as: > + > +@c TRANSLATORS: The domain names below SHOULD NOT be translated. > +@c They're domains reserved for use in documentation. (RFC6761 Section 6= .5) > +@lisp > +(list "127.0.0.1 example.com example.net" > + "::1 example.com example.net" > +@end lisp > +@end defvar [...] > +(define etc-hosts-service-type > + ;; Extend etc-service-type with a entry for @file{/etc/hosts}. > + (service-type > + (name 'etc-hosts) > + (extensions > + (list > + (service-extension etc-service-type > + (lambda (lst) > + `(("hosts" > + ,(plain-file "hosts" > + (string-join lst "\n" > + 'suffix)))))))) > + (compose concatenate) > + (extend append) > + (description "Populate the @file{/etc/hosts} file."))) Two suggestions: 1. Calling it =E2=80=98hosts-service-type=E2=80=99. 2. Instead of plain strings, take records along the lines of: (define-record-type* host make-host host? (address host-address) ;string (canonical-name host-canonical-name) ;string (aliases host-aliases (default '()))) ;list of strings WDYT? If =E2=80=9Chost=E2=80=9D is too likely to clash, we can call it or something, but I think it should be fine. > +(define-with-syntax-properties (warn-hosts-file-field-deprecation > + (value properties)) > + (when value > + (warning (source-properties->location properties) > + (G_ "the 'hosts-file' field is deprecated, please use \ > +'etc-hosts-service-type' instead~%"))) > + value) Could you move deprecation to a separate patch? Apart from that it LGTM, thank you! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 18 11:55:25 2023 Received: (at 60735) by debbugs.gnu.org; 18 Jan 2023 16:55:25 +0000 Received: from localhost ([127.0.0.1]:41643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBie-0004hH-LU for submit@debbugs.gnu.org; Wed, 18 Jan 2023 11:55:25 -0500 Received: from smtpm2.myservices.hosting ([185.26.105.233]:45910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBic-0004h9-Kz for 60735@debbugs.gnu.org; Wed, 18 Jan 2023 11:55:23 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm2.myservices.hosting (Postfix) with ESMTP id E2F3620CF2; Wed, 18 Jan 2023 17:55:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 8215580098; Wed, 18 Jan 2023 17:55:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id FRxeiXFIR4aA; Wed, 18 Jan 2023 17:55:20 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id B1A2880099; Wed, 18 Jan 2023 17:55:19 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v2 1/3] services: Add etc-hosts-service-type. Date: Wed, 18 Jan 2023 16:54:11 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: ludo@gnu.org, Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/services.scm (etc-hosts-service-type): New variable. * doc/guix.texi: Document it. --- doc/guix.texi | 46 +++++++++++++++++++++++++++++++++++ gnu/services.scm | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 9b478733eb..5fb3df441c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -112,6 +112,7 @@ Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@* Copyright @copyright{} 2023 Giacomo Leidi@* Copyright @copyright{} 2022 Antero Mejr@* +Copyright @copyright{} 2023 Bruno Victal@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -40191,6 +40192,51 @@ Service Reference pointing to the given file. @end defvr +@defvar hosts-service-type +Type of the service that populates the entries for (@file{/etc/hosts}). +This service type can be extended by passing it a list of +@code{host-entry} records. + +@c TRANSLATORS: The domain names below SHOULD NOT be translated. +@c They're domains reserved for use in documentation. (RFC6761 Section 6.5) +@c The addresses used are explained in RFC3849 and RFC5737. +@lisp +(simple-service 'add-extra-hosts + hosts-service-type + (list (host-entry + (address "192.0.2.1") + (canonical-name "example.com") + (aliases '("example.net" "example.org"))) + (host-entry + (address "2001:DB8::1") + (canonical-name "example.com") + (aliases '("example.net" "example.org"))))) +@end lisp + +@deftp {Data Type} host-entry +Available @code{host-entry} fields are: + +@table @asis +@item @code{address} (type: string) +IP address. + +@item @code{canonical-name} (type: string) +Hostname. + +@item @code{aliases} (default: @code{'()}) (type: list-of-string) +Additional aliases that map to the same @code{canonical-name}. + +@end table +@end deftp + +For convenience, the procedure @code{host} can be for creating +@code{host-entry} records. + +@defun host address canonical-name [aliases] +Procedure for creating @code{host-entry} records. +@end defun +@end defvar + @defvr {Scheme Variable} setuid-program-service-type Type for the ``setuid-program service''. This service collects lists of executable file names, passed as gexps, and adds them to the set of diff --git a/gnu/services.scm b/gnu/services.scm index 2abef557d4..12ecfa4492 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -6,6 +6,7 @@ ;;; Copyright © 2021 raid5atemyhomework ;;; Copyright © 2020 Christine Lemmer-Webber ;;; Copyright © 2020, 2021 Brice Waegeneire +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,6 +52,7 @@ (define-module (gnu services) #:use-module (srfi srfi-35) #:use-module (ice-9 vlist) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:autoload (ice-9 pretty-print) (pretty-print) #:export (service-extension service-extension? @@ -109,6 +111,15 @@ (define-module (gnu services) extra-special-file etc-service-type etc-directory + + host + host-entry + host-entry? + host-entry-address + host-entry-canonical-name + host-entry-aliases + hosts-service-type + setuid-program-service-type profile-service-type firmware-service-type @@ -809,6 +820,58 @@ (define (etc-service files) FILES must be a list of name/file-like object pairs." (service etc-service-type files)) +(define (valid-name? name) + "Return true if @var{name} is likely to be a valid hostname." + (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." + ;; TODO: RFC compliant implementation. + (unless (valid-name? name) + (raise + (make-compound-condition + (formatted-message (G_ "hostname '~a' contains invalid characters.") + name) + (condition (&error-location + (location + (source-properties->location procedure-call-location))))))) + name) + +(define-record-type* host-entry + make-host-entry host-entry? + (address host-entry-address) + (canonical-name host-entry-canonical-name + (sanitize assert-valid-name)) + (aliases host-entry-aliases + (default '()) + (sanitize (cut map assert-valid-name <>)))) + +(define* (host address canonical-name #:optional (aliases '())) + "More compact way of creating records" + (make-host-entry address canonical-name aliases)) + +(define hosts-service-type + ;; Extend etc-service-type with a entry for @file{/etc/hosts}. + (let* ((serialize-host-entry-record + (lambda (record) + (match-record record (address canonical-name aliases) + (format #f "~a~/~a~{~^~/~a~}~%" address canonical-name aliases)))) + (host-etc-service + (lambda (lst) + `(("hosts" ,(plain-file "hosts" + (format #f "~{~a~}" + (map serialize-host-entry-record + lst)))))))) + (service-type + (name 'etc-hosts) + (extensions + (list + (service-extension etc-service-type + host-etc-service))) + (compose concatenate) + (extend append) + (description "Populate the @file{/etc/hosts} file.")))) + (define (setuid-program->activation-gexp programs) "Return an activation gexp for setuid-program from PROGRAMS." (let ((programs (map (lambda (program) -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 18 11:57:19 2023 Received: (at 60735) by debbugs.gnu.org; 18 Jan 2023 16:57:19 +0000 Received: from localhost ([127.0.0.1]:41649 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkU-0004kM-Cy for submit@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:19 -0500 Received: from smtpm1.myservices.hosting ([185.26.105.232]:39790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkS-0004kC-BS for 60735@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:17 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm1.myservices.hosting (Postfix) with ESMTP id 6C68E203C8; Wed, 18 Jan 2023 17:57:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 0A4B78009C; Wed, 18 Jan 2023 17:57:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xBMCTwhgCmhc; Wed, 18 Jan 2023 17:57:11 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 2E66A80098; Wed, 18 Jan 2023 17:57:11 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v2 2/3] system: Deprecate hosts-file. Date: Wed, 18 Jan 2023 16:54:13 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: ludo@gnu.org, Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/system.scm (operating-system-hosts-file): Deprecate procedure. (warn-hosts-file-field-deprecation): New procedure, helper for deprecated variable). (operating-system)[hosts-file]: Use helper to warn deprecated field. (operating-system-default-essential-services) (hurd-default-essential-services): Use hosts-service-type. (local-host-aliases): Return a list of host-entry records. (default-/etc/hosts): Remove procedure. (operating-system-etc-service): Remove hosts file. * doc/guix.texi (operating-system Reference) (Networking Services) (Virtualization Services): Rewrite documentation entries to use hosts-service-type. * gnu/tests/ganeti.scm: Use hosts-service-type extension. --- WIP, the ganeti tests fail because host-name is added as an alias of localhost. Ideally hosts-service-type should be moved to %base-services but we lose access to os host-name if we do so. doc/guix.texi | 60 +++++++++++++++++++++++--------------------- gnu/system.scm | 59 ++++++++++++++++++++++++++++++++----------- gnu/tests/ganeti.scm | 18 ++++++------- 3 files changed, 85 insertions(+), 52 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5fb3df441c..eb4c1a2dbb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -16479,13 +16479,6 @@ operating-system Reference @item @code{host-name} The host name. -@item @code{hosts-file} -@cindex hosts file -A file-like object (@pxref{G-Expressions, file-like objects}) for use as -@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library -Reference Manual}). The default is a file with entries for -@code{localhost} and @var{host-name}. - @item @code{mapped-devices} (default: @code{'()}) A list of mapped devices. @xref{Mapped Devices}. @@ -21010,22 +21003,33 @@ Networking Services on-line service---e.g., @code{www.facebook.com}---to the local host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. -This variable is typically used in the @code{hosts-file} field of an -@code{operating-system} declaration (@pxref{operating-system Reference, -@file{/etc/hosts}}): +This variable is typically used as a @code{hosts-service-type} +service extension (@pxref{Service Reference, @code{hosts-service-type}}): @lisp -(use-modules (gnu) (guix)) +(use-modules (gnu) (gnu services) (guix) (srfi srfi-1) (ice-9 match)) +(use-service-modules networking) (operating-system - (host-name "mymachine") - ;; ... - (hosts-file - ;; Create a /etc/hosts file with aliases for "localhost" - ;; and "mymachine", as well as for Facebook servers. - (plain-file "hosts" - (string-append (local-host-aliases host-name) - %facebook-host-aliases)))) + ;; @dots{} + + (service + (simple-service 'block-facebook-hosts hosts-service-type + (let ((host-pairs + (filter-map + (lambda (x) + (and (not (or (string-null? x) + (string-prefix? "#" x))) + (remove string-null? + (string-split + x + char-set:whitespace)))) + (string-split %facebook-host-aliases #\newline)))) + (map (match-lambda + ((addr name) + (host addr name))) + host-pairs))) + ;; @dots{} @end lisp This mechanism can prevent programs running locally, such as Web @@ -34310,7 +34314,7 @@ Virtualization Services services which are described later in this section. In addition to the Ganeti service, you will need the OpenSSH service (@pxref{Networking Services, @code{openssh-service-type}}), and update the @file{/etc/hosts} file -(@pxref{operating-system Reference, @code{hosts-file}}) with the cluster name +(@pxref{Service Reference, @code{hosts-service-type}}) with the cluster name and address (or use a DNS server). All nodes participating in a Ganeti cluster should have the same Ganeti and @@ -34324,14 +34328,6 @@ Virtualization Services (operating-system ;; @dots{} (host-name "node1") - (hosts-file (plain-file "hosts" (format #f " -127.0.0.1 localhost -::1 localhost - -192.168.1.200 ganeti.example.com -192.168.1.201 node1.example.com node1 -192.168.1.202 node2.example.com node2 -"))) ;; Install QEMU so we can use KVM-based instances, and LVM, DRBD and Ceph ;; in order to use the "plain", "drbd" and "rbd" storage backends. @@ -34359,6 +34355,14 @@ Virtualization Services (openssh-configuration (permit-root-login 'prohibit-password))) + (simple-service 'ganeti-hosts-entries hosts-service-type + (list + (host "192.168.1.200" "ganeti.example.com") + (host "192.168.1.201" "node1.example.com" + '("node1")) + (host "192.168.1.202" "node2.example.com" + '("node2")))) + (service ganeti-service-type (ganeti-configuration ;; This list specifies allowed file system paths diff --git a/gnu/system.scm b/gnu/system.scm index d67f9a615b..d80f2a3a23 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -14,6 +14,7 @@ ;;; Copyright © 2020, 2022 Efraim Flashner ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2021 raid5atemyhomework +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,6 +32,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu system) + #:use-module (guix discovery) #:use-module (guix inferior) #:use-module (guix store) #:use-module (guix memoization) @@ -97,7 +99,7 @@ (define-module (gnu system) operating-system-user-services operating-system-packages operating-system-host-name - operating-system-hosts-file + operating-system-hosts-file ;deprecated operating-system-hurd operating-system-kernel operating-system-kernel-file @@ -208,6 +210,15 @@ (define* (bootable-kernel-arguments system root-device version) #$system "/boot"))) ;; System-wide configuration. + +(define-with-syntax-properties (warn-hosts-file-field-deprecation + (value properties)) + (when value + (warning (source-properties->location properties) + (G_ "the 'hosts-file' field is deprecated, please use \ +'hosts-service-type' instead~%"))) + value) + ;; TODO: Add per-field docstrings/stexi. (define-record-type* operating-system make-operating-system @@ -239,8 +250,9 @@ (define-record-type* operating-system (default %base-firmware)) (host-name operating-system-host-name) ; string - (hosts-file operating-system-hosts-file ; file-like | #f - (default #f)) + (hosts-file %operating-system-hosts-file ; deprecated + (default #f) + (sanitize warn-hosts-file-field-deprecation)) (mapped-devices operating-system-mapped-devices ; list of (default '())) @@ -296,6 +308,10 @@ (define-record-type* operating-system source-properties->location)) (innate))) +(define-deprecated (operating-system-hosts-file os) + hosts-service-type + (%operating-system-hosts-file os)) + (define* (operating-system-kernel-arguments os root-device #:key (version %boot-parameters-version)) "Return all the kernel arguments, including the ones not specified directly @@ -733,7 +749,8 @@ (define (operating-system-default-essential-services os) (non-boot-fs (non-boot-file-system-service os)) (swaps (swap-services os)) (procs (service user-processes-service-type)) - (host-name (host-name-service (operating-system-host-name os))) + (host-name (operating-system-host-name 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 @@ -755,12 +772,19 @@ (define (operating-system-default-essential-services os) (operating-system-groups os)) (operating-system-skeletons os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service hosts-service-type + (local-host-aliases host-name))) (service fstab-service-type (filter file-system-needed-for-boot? (operating-system-file-systems os))) (session-environment-service (operating-system-environment-variables os)) - host-name procs root-fs + (host-name-service host-name) + procs root-fs (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type @@ -774,7 +798,9 @@ (define (operating-system-default-essential-services os) (operating-system-firmware os))))))) (define (hurd-default-essential-services os) - (let ((entries (operating-system-directory-base-entries os))) + (let ((host-name (operating-system-host-name os)) + (hosts-file (operating-system-hosts-file os)) + (entries (operating-system-directory-base-entries os))) (list (service system-service-type entries) %boot-service %hurd-startup-service @@ -794,6 +820,12 @@ (define (hurd-default-essential-services os) (operating-system-file-systems os))) (pam-root-service (operating-system-pam-services os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service hosts-service-type + (local-host-aliases host-name))) (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type (operating-system-packages os))))) @@ -914,12 +946,13 @@ (define %default-issue (define (local-host-aliases host-name) "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 (default-/etc/hosts host-name) - "Return the default /etc/hosts file." - (plain-file "hosts" (local-host-aliases host-name))) + (map (lambda (address) + (host-entry + (address address) + (canonical-name "localhost") + (aliases (list host-name)))) + '("127.0.0.1" + "::1"))) (define (validated-sudoers-file file) "Return a copy of FILE, a sudoers file, after checking that it is @@ -1068,8 +1101,6 @@ (define* (operating-system-etc-service os) ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '()) ("profile" ,#~#$profile) ("bashrc" ,#~#$bashrc) - ("hosts" ,#~#$(or (operating-system-hosts-file os) - (default-/etc/hosts (operating-system-host-name os)))) ;; Write the operating-system-host-name to /etc/hostname to prevent ;; NetworkManager from changing the system's hostname when connecting ;; to certain networks. Some discussion at diff --git a/gnu/tests/ganeti.scm b/gnu/tests/ganeti.scm index f647e9554c..10ec2980ee 100644 --- a/gnu/tests/ganeti.scm +++ b/gnu/tests/ganeti.scm @@ -46,16 +46,6 @@ (define %ganeti-os %base-file-systems)) (firmware '()) - ;; The hosts file must contain a nonlocal IP for host-name. - ;; In addition, the cluster name must resolve to an IP address that - ;; is not currently provisioned. - (hosts-file (plain-file "hosts" (format #f " -127.0.0.1 localhost -::1 localhost -10.0.2.15 gnt1.example.com gnt1 -192.168.254.254 ganeti.example.com -"))) - (packages (append (list ganeti-instance-debootstrap ganeti-instance-guix) %base-packages)) (services @@ -65,6 +55,14 @@ (define %ganeti-os (openssh-configuration (permit-root-login 'prohibit-password))) + ;; The hosts file must contain a nonlocal IP for host-name. + ;; In addition, the cluster name must resolve to an IP address that + ;; is not currently provisioned. + (simple-service 'ganeti-host-entries hosts-service-type + (list + (host "10.0.2.15" "gnt1.example.com" '("gnt1")) + (host "192.168.254.254" "ganeti.example.com"))) + (service ganeti-service-type (ganeti-configuration (file-storage-paths '("/srv/ganeti/file-storage")) -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 18 11:57:23 2023 Received: (at 60735) by debbugs.gnu.org; 18 Jan 2023 16:57:23 +0000 Received: from localhost ([127.0.0.1]:41652 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkY-0004kc-G3 for submit@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:23 -0500 Received: from smtpm2.myservices.hosting ([185.26.105.233]:46266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkU-0004kL-Ij for 60735@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:19 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm2.myservices.hosting (Postfix) with ESMTP id E4CBC20CF2; Wed, 18 Jan 2023 17:57:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 96C908009A; Wed, 18 Jan 2023 17:57:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9Znsq_JJLYRI; Wed, 18 Jan 2023 17:57:14 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id BCF2480099; Wed, 18 Jan 2023 17:57:13 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v2 3/3] services: Add block-facebook-hosts-service-type. Date: Wed, 18 Jan 2023 16:54:14 +0000 Message-Id: <511996014cccd059f1d2ea701e5fe134ad2c4735.1674060851.git.mirai@makinata.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: ludo@gnu.org, Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Deprecates %facebook-host-aliases in favour of using hosts-service-type service extensions. * gnu/services/networking.scm (block-facebook-hosts-service-type): New variable. (%facebook-host-aliases): Deprecate variable. * doc/guix.texi: Document it. --- doc/guix.texi | 40 ++++------------------- gnu/services/networking.scm | 65 +++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 66 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index eb4c1a2dbb..da93cc613f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20996,45 +20996,17 @@ Networking Services @end table @end deftp -@defvr {Scheme Variable} %facebook-host-aliases -This variable contains a string for use in @file{/etc/hosts} -(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each -line contains a entry that maps a known server name of the Facebook +@defvar block-facebook-hosts-service-type +This service type adds a list of known Facebook hosts to the +@file{/etc/hosts} file. +(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}) +Each line contains a entry that maps a known server name of the Facebook on-line service---e.g., @code{www.facebook.com}---to the local host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. -This variable is typically used as a @code{hosts-service-type} -service extension (@pxref{Service Reference, @code{hosts-service-type}}): - -@lisp -(use-modules (gnu) (gnu services) (guix) (srfi srfi-1) (ice-9 match)) -(use-service-modules networking) - -(operating-system - ;; @dots{} - - (service - (simple-service 'block-facebook-hosts hosts-service-type - (let ((host-pairs - (filter-map - (lambda (x) - (and (not (or (string-null? x) - (string-prefix? "#" x))) - (remove string-null? - (string-split - x - char-set:whitespace)))) - (string-split %facebook-host-aliases #\newline)))) - (map (match-lambda - ((addr name) - (host addr name))) - host-pairs))) - ;; @dots{} -@end lisp - This mechanism can prevent programs running locally, such as Web browsers, from accessing Facebook. -@end defvr +@end defvar The @code{(gnu services avahi)} provides the following definition. diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 89ce16f6af..3e41e42da1 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2022, 2023 Andrew Tropin ;;; Copyright © 2023 Declan Tsien +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -80,7 +81,9 @@ (define-module (gnu services networking) #:use-module (json) #:re-export (static-networking-service static-networking-service-type) - #:export (%facebook-host-aliases + #:export (%facebook-host-aliases ;deprecated + block-facebook-hosts-service-type + dhcp-client-service-type dhcp-client-configuration dhcp-client-configuration? @@ -235,39 +238,37 @@ (define-module (gnu services networking) ;;; ;;; Code: -(define %facebook-host-aliases +(define facebook-host-aliases ;; This is the list of known Facebook hosts to be added to /etc/hosts if you ;; are to block it. - "\ -# Block Facebook IPv4. -127.0.0.1 www.facebook.com -127.0.0.1 facebook.com -127.0.0.1 login.facebook.com -127.0.0.1 www.login.facebook.com -127.0.0.1 fbcdn.net -127.0.0.1 www.fbcdn.net -127.0.0.1 fbcdn.com -127.0.0.1 www.fbcdn.com -127.0.0.1 static.ak.fbcdn.net -127.0.0.1 static.ak.connect.facebook.com -127.0.0.1 connect.facebook.net -127.0.0.1 www.connect.facebook.net -127.0.0.1 apps.facebook.com - -# Block Facebook IPv6. -fe80::1%lo0 facebook.com -fe80::1%lo0 login.facebook.com -fe80::1%lo0 www.login.facebook.com -fe80::1%lo0 fbcdn.net -fe80::1%lo0 www.fbcdn.net -fe80::1%lo0 fbcdn.com -fe80::1%lo0 www.fbcdn.com -fe80::1%lo0 static.ak.fbcdn.net -fe80::1%lo0 static.ak.connect.facebook.com -fe80::1%lo0 connect.facebook.net -fe80::1%lo0 www.connect.facebook.net -fe80::1%lo0 apps.facebook.com\n") - + (let ((domains '("facebook.com" "www.facebook.com" + "login.facebook.com" "www.login.facebook.com" + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com" + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" + "connect.facebook.net" "www.connect.facebook.net" + "apps.facebook.com"))) + (append-map (lambda (name) + (map (lambda (addr) + (host addr name)) + (list "127.0.0.1" "::1"))) domains))) + +(define-deprecated %facebook-host-aliases + block-facebook-hosts-service-type + (let (( (@ (gnu services) ))) + (string-join + (map (match-lambda + (($ address canonical-name) + (string-append address "\t" canonical-name "\n"))) + facebook-host-aliases)))) + +(define block-facebook-hosts-service-type + (service-type + (name 'block-facebook-hosts) + (extensions + (list (service-extension hosts-service-type + (const facebook-host-aliases)))) + (default-value #f) + (description "Add a list of known Facebook hosts to @file{/etc/hosts}"))) (define-record-type* dhcp-client-configuration make-dhcp-client-configuration -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 23 17:30:41 2023 Received: (at 60735) by debbugs.gnu.org; 23 Jan 2023 22:30:41 +0000 Received: from localhost ([127.0.0.1]:55515 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Kr-0003Sc-5f for submit@debbugs.gnu.org; Mon, 23 Jan 2023 17:30:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Kq-0003SO-8R for 60735@debbugs.gnu.org; Mon, 23 Jan 2023 17:30:40 -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 1pK5Ki-0003TW-TE; Mon, 23 Jan 2023 17:30:34 -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=0XEaWQTMSWITa5EUYaooTB/FkLksslNSyGq15V0ChPE=; b=jUYYNNyl+HVipIWahPAK rf9RGqBKMH4MPe9tK8+fXmcd4XJH1EbdUE3Ey1Y6WURVCsgEF9c1fvc6Fv3j2ZDE4NhaasXrhcI8p FbDjEPrbEAy4EYP/gYmuf0+PCpGgEgNXzrg4emgJAQHPfOuUlNF6NNKq+AzhJ/EdlhesLlVz5Sb/e /t/PVZaXbjEB8vV0deAvU/DP/nmBx+ZxAFE8PIHvAGlshBJMrjjk/sCyc9BvBKQ/RtJ6SbhFpkJKM TYg8gIQ49cHZJmAJlUdj3Nmxciy3mNg7B00UeQqUVTBHH6YnMbBJdRGTGyOfGVYH8l+dEi5thLsz1 bdQynzbilbn3kA==; 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 1pK5Ki-0006fW-FS; Mon, 23 Jan 2023 17:30:32 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: [PATCH v2 1/3] services: Add etc-hosts-service-type. References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 4 =?utf-8?Q?Pluvi=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Perce-neige 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: Mon, 23 Jan 2023 23:30:30 +0100 In-Reply-To: (Bruno Victal's message of "Wed, 18 Jan 2023 16:54:11 +0000") Message-ID: <87sfg0yjcp.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi! Bruno Victal skribis: > * gnu/services.scm (etc-hosts-service-type): New variable. > * doc/guix.texi: Document it. LGTM! Bonus points if you can list all the new/modified variables and procedures in the commit log. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 23 17:38:00 2023 Received: (at 60735) by debbugs.gnu.org; 23 Jan 2023 22:38:00 +0000 Received: from localhost ([127.0.0.1]:55521 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Rw-0003ec-3f for submit@debbugs.gnu.org; Mon, 23 Jan 2023 17:38:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60410) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Ru-0003eP-1Y for 60735@debbugs.gnu.org; Mon, 23 Jan 2023 17:37:59 -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 1pK5Ro-0004Yk-5w; Mon, 23 Jan 2023 17:37:52 -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=kxc3kkceNhaAcZZYfYaWe59+StHGIzUcFddVxED7HyQ=; b=f1YdCr5XOzaw+ovb7Xgq 2Dj7eciujVglRc6qIh5bwbgFmJtOG/1fIhFh0ftMKMwY73x/kgw5DRIafV039YIxRzLTVg6pEydfi czPV5bW1UUMS6OyzZchb1C9oLYnKLxQLFgGzGazpmpJXPdy2Ur49xGecelcv53AuoRYNsFDfTqQEY nJxRXmWRN3OUGsP1/Wehs9B8YXyassCXyOnzxbrrliUxDc25zUgCTuEqJ94+YDRbx5I206IT3iL1d QJCGZsOf0ncZj8AAtufuSi0RJZF6WxP6aGnCih3UHYCAEn/vi/5mtLVcj8lUX2aOsJXRPOSvm+fl5 bL24p15EpyIeGA==; 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 1pK5Rn-0000q2-Lv; Mon, 23 Jan 2023 17:37:51 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: [PATCH v2 2/3] system: Deprecate hosts-file. References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 4 =?utf-8?Q?Pluvi=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Perce-neige 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: Mon, 23 Jan 2023 23:37:49 +0100 In-Reply-To: (Bruno Victal's message of "Wed, 18 Jan 2023 16:54:13 +0000") Message-ID: <87o7qoyj0i.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Bruno Victal skribis: > * gnu/system.scm (operating-system-hosts-file): Deprecate procedure. > (warn-hosts-file-field-deprecation): New procedure, helper for > deprecated variable). > (operating-system)[hosts-file]: Use helper to warn deprecated field. > (operating-system-default-essential-services) > (hurd-default-essential-services): Use hosts-service-type. > (local-host-aliases): Return a list of host-entry records. > (default-/etc/hosts): Remove procedure. > (operating-system-etc-service): Remove hosts file. > * doc/guix.texi (operating-system Reference) > (Networking Services) (Virtualization Services): Rewrite documentation > entries to use hosts-service-type. > * gnu/tests/ganeti.scm: Use hosts-service-type extension. > --- > > WIP, the ganeti tests fail because host-name is added as an alias of loca= lhost. Before these patches, =E2=80=98host-name=E2=80=99 was already an alias of = =E2=80=98localhost=E2=80=99. Is there something else interfering? > + (simple-service 'block-facebook-hosts hosts-service-type > + (let ((host-pairs > + (filter-map > + (lambda (x) > + (and (not (or (string-null? x) > + (string-prefix? "#" x))) > + (remove string-null? > + (string-split > + x > + char-set:whitespace)))) > + (string-split %facebook-host-aliases #\new= line)))) > + (map (match-lambda > + ((addr name) > + (host addr name))) > + host-pairs))) It doesn=E2=80=99t matter because it=E2=80=99s removed in the commit that f= ollows I think using =E2=80=98string-tokenize=E2=80=99 instead of =E2=80=98string-sp= lit=E2=80=99 may bring simplifications. > +++ b/gnu/system.scm > @@ -14,6 +14,7 @@ > ;;; Copyright =C2=A9 2020, 2022 Efraim Flashner > ;;; Copyright =C2=A9 2021 Maxime Devos > ;;; Copyright =C2=A9 2021 raid5atemyhomework > +;;; Copyright =C2=A9 2023 Bruno Victal > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -31,6 +32,7 @@ > ;;; along with GNU Guix. If not, see . >=20=20 > (define-module (gnu system) > + #:use-module (guix discovery) Do we really need this module? Otherwise LGTM. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 23 17:41:02 2023 Received: (at 60735) by debbugs.gnu.org; 23 Jan 2023 22:41:02 +0000 Received: from localhost ([127.0.0.1]:55531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Us-0003ky-6K for submit@debbugs.gnu.org; Mon, 23 Jan 2023 17:41:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5Up-0003kJ-Pz for 60735@debbugs.gnu.org; Mon, 23 Jan 2023 17:41:00 -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 1pK5Uk-0005Al-0I; Mon, 23 Jan 2023 17:40:54 -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=AQ4GllMoBdlAOUU+QyvhjapO6v+7YZomT0z3bvq3Dz4=; b=YzptctAnE4PikzKDtnc+ 8y4cmDSMRiKrR0VBzXY9X/MBWPT1iHLqoCxVuDIh0ItGPRrX1pMudGJBiR20egZRGOLfz3ns4H47Q y+vf37hnA9bL0l6DlU2a7tJcJmWkELw/Rm7s0dAR6u+Uds6VLj7srWcvtGBU5XCnXzoMYQQHsnNzX XSfWGwZ3w1Fk61SGokbBCXr9f6xv0ECjXYlmplbQLYT+dIBLp/rk1TSj3vSbFTksNi32GbkeVVG/0 3OeQZMVDfokypOvnN4fq0oaiADuMAtd3dtZb0RBLahab82j3XHOfjPERouJECzSI0tHL4DZ6fCKZZ L6vxAIEJtpULFg==; 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 1pK5Uj-0001CQ-BE; Mon, 23 Jan 2023 17:40:53 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: [PATCH v2 3/3] services: Add block-facebook-hosts-service-type. References: <511996014cccd059f1d2ea701e5fe134ad2c4735.1674060851.git.mirai@makinata.eu> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 4 =?utf-8?Q?Pluvi=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Perce-neige 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: Mon, 23 Jan 2023 23:40:52 +0100 In-Reply-To: <511996014cccd059f1d2ea701e5fe134ad2c4735.1674060851.git.mirai@makinata.eu> (Bruno Victal's message of "Wed, 18 Jan 2023 16:54:14 +0000") Message-ID: <87k01cyivf.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Bruno Victal skribis: > Deprecates %facebook-host-aliases in favour of using > hosts-service-type service extensions. > > * gnu/services/networking.scm > (block-facebook-hosts-service-type): New variable. > (%facebook-host-aliases): Deprecate variable. > * doc/guix.texi: Document it. [...] > -fe80::1%lo0 www.connect.facebook.net > -fe80::1%lo0 apps.facebook.com\n") > - > + (let ((domains '("facebook.com" "www.facebook.com" > + "login.facebook.com" "www.login.facebook.com" > + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.co= m" > + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" > + "connect.facebook.net" "www.connect.facebook.net" > + "apps.facebook.com"))) > + (append-map (lambda (name) > + (map (lambda (addr) > + (host addr name)) > + (list "127.0.0.1" "::1"))) domains))) The IPv6 address is different, but now I=E2=80=99m not sure whether fe80::1= %lo0 made sense? > +(define-deprecated %facebook-host-aliases > + block-facebook-hosts-service-type > + (let (( (@ (gnu services) ))) > + (string-join > + (map (match-lambda > + (($ address canonical-name) Avoid matching on records, just use the accessors. Otherwise LGTM, thanks! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 23 17:47:45 2023 Received: (at 60735) by debbugs.gnu.org; 23 Jan 2023 22:47:45 +0000 Received: from localhost ([127.0.0.1]:55546 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5bN-0003wr-BD for submit@debbugs.gnu.org; Mon, 23 Jan 2023 17:47:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK5bL-0003we-Sy for 60735@debbugs.gnu.org; Mon, 23 Jan 2023 17:47:44 -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 1pK5bG-00068G-Ak; Mon, 23 Jan 2023 17:47:38 -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=15bhVAWGHgyE//AxHSXPaDKBZ33F88SQTPJ80d4Pr5U=; b=cJ3wSNuWtJ1dsEVTvS1q nz8YvlJ9Jv8EeiRNApaXS1dUq2PSPqRAA6W1z+7BKeOTRp+LIyRl5kjx7657OKQJtkHXdEn43o7EA BklLKdbXJxZC+20Cr2UDe9fUj+WJV/39P1iPEuhqbG5VXIkU829ezfc6DO3TU7KDtn5lDo4AB8vp2 aQsCv5Tp4mtSwxIRKityp3obc2S7OFC0ZgSH/J0IYrUpfMwKC2Y4vcLT++S0wPf14CYhGF8BT6ZCs hxOkeKAJ7iqvxvtUlPCQPXBve0tV9NRL++P3Me2chwDSL1JGSQml1sE1o1YWjTm3mSisHcuteqOf6 mW6SxyvDFuuCJA==; 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 1pK5bF-0001oT-Gw; Mon, 23 Jan 2023 17:47:37 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: [PATCH v2 1/3] services: Add etc-hosts-service-type. References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 4 =?utf-8?Q?Pluvi=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Perce-neige 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: Mon, 23 Jan 2023 23:47:35 +0100 In-Reply-To: (Bruno Victal's message of "Wed, 18 Jan 2023 16:54:11 +0000") Message-ID: <87edrkyik8.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Bruno Victal skribis: > * gnu/services.scm (etc-hosts-service-type): New variable. > * doc/guix.texi: Document it. Other things that crossed my mind; sorry for not noticing earlier! > +++ b/gnu/services.scm Should this be in (gnu services base) instead? > + (make-compound-condition > + (formatted-message (G_ "hostname '~a' contains invalid characters.= ") No period please. > +(define-record-type* host-entry > + make-host-entry host-entry? > + (address host-entry-address) > + (canonical-name host-entry-canonical-name > + (sanitize assert-valid-name)) > + (aliases host-entry-aliases > + (default '()) > + (sanitize (cut map assert-valid-name <>)))) > + > +(define* (host address canonical-name #:optional (aliases '())) > + "More compact way of creating records" > + (make-host-entry address canonical-name aliases)) I just realized that =E2=80=98make-host-entry=E2=80=99 won=E2=80=99t run an= y sanitizer, oops! So you have to use =E2=80=98host-entry=E2=80=99: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (define-record-type* host-entry make-host-entry host-entry? (address host-entry-address) (canonical-name host-entry-canonical-name (sanitize assert-valid-name)) (aliases host-entry-aliases (default '()) (sanitize (cut map assert-valid-name <>)))) scheme@(guile-user)> ,optimize (make-host-entry 1 2 3) $12 =3D (make-struct/simple #{% rtd}# 1 2 3) scheme@(guile-user)> ,optimize (host-entry (address 1) (canonical-name 2)) $13 =3D (let ((canonical-name (assert-valid-name 2))) (if (eq? #{% abi-cookie}# 796283273607885551) (if #f #f) (throw 'record-abi-mismatch-error 'abi-check "~a: record ABI mismatch; recompilation needed" (list #{% rtd}#) '())) (let ((aliases ((cut map assert-valid-name <>) '()))) (make-struct/simple #{% rtd}# 1 canonical-name aliases))) --8<---------------cut here---------------end--------------->8--- Also, there=E2=80=99s a naming confusion between =E2=80=98host=E2=80=99 and= =E2=80=98host-entry=E2=80=99; you should choose one or the other IMO. Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 23 18:19:24 2023 Received: (at 60735) by debbugs.gnu.org; 23 Jan 2023 23:19:24 +0000 Received: from localhost ([127.0.0.1]:55573 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK660-0004kl-8y for submit@debbugs.gnu.org; Mon, 23 Jan 2023 18:19:24 -0500 Received: from smtpmciv1.myservices.hosting ([185.26.107.237]:42788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pK65y-0004kc-My for 60735@debbugs.gnu.org; Mon, 23 Jan 2023 18:19:23 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpmciv1.myservices.hosting (Postfix) with ESMTP id B641A20A68; Tue, 24 Jan 2023 00:19:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 4B7FB80096; Tue, 24 Jan 2023 00:19:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JCXMgzwFNquu; Tue, 24 Jan 2023 00:19:11 +0100 (CET) Received: from [192.168.1.239] (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 7F31780093; Tue, 24 Jan 2023 00:19:11 +0100 (CET) Message-ID: Date: Mon, 23 Jan 2023 23:19:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v2 2/3] system: Deprecate hosts-file. Content-Language: en-US To: =?UTF-8?Q?Ludovic_Court=c3=a8s?= References: <87o7qoyj0i.fsf@gnu.org> From: Bruno Victal In-Reply-To: <87o7qoyj0i.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) On 2023-01-23 22:37, Ludovic Courtès wrote: > Bruno Victal skribis: > >> --- >> >> WIP, the ganeti tests fail because host-name is added as an alias of localhost. > > Before these patches, ‘host-name’ was already an alias of ‘localhost’. > Is there something else interfering? In some cases, it's not desired for host-name to be an alias of localhost. The ganeti tests did this by passing a hosts-file file-like object where host-name wasn't an alias of localhost. I've brainstormed a bit on this and here's what I thought: Approach 1 (DOESN'T WORK): * hosts-service-type in essential-services (gnu/systems.scm), default value: 127.0.0.1 localhost ::1 localhost * simple-service extension on base-services (gnu/services/base.scm): \\FLOPS since both /etc/hosts and /etc/hostname are provisioned with activation-service-type. This means we can't write /etc/hosts AFTER /etc/hostname or host-name-service-type is ready. Approach 2: * NO /etc/hosts in essential-services (is this possible?) * is an absent /etc/hosts (or absent %base-services) a valid OS? * Value set in %base-services, hosts-service-type as a ONE-SHOT shepherd service. * Can be changed with modify-services. * It's a one-shot shepherd service since we're depending on /etc/hostname which is activation-service-type. (we're depending on either etc-service-type or host-name-service-type) Approach 3: * Do not set our hostname as an alias of localhost by default. * Manpage doesn't seem to make this mandatory, in fact, our hostname can point to any IP. (it says 'often', not 'mandatory') * We only set localhost name. * Is this mandatory? If not, there might be cases where this entry is undesired. > >> + (simple-service 'block-facebook-hosts hosts-service-type >> + (let ((host-pairs >> + (filter-map >> + (lambda (x) >> + (and (not (or (string-null? x) >> + (string-prefix? "#" x))) >> + (remove string-null? >> + (string-split >> + x >> + char-set:whitespace)))) >> + (string-split %facebook-host-aliases #\newline)))) >> + (map (match-lambda >> + ((addr name) >> + (host addr name))) >> + host-pairs))) > > It doesn’t matter because it’s removed in the commit that follows I > think using ‘string-tokenize’ instead of ‘string-split’ may bring > simplifications. It was added because otherwise the "split" commits would seem to be missing some context. I can leave it as is, delete it here or try your suggestion. >> +++ b/gnu/system.scm >> @@ -14,6 +14,7 @@ >> ;;; Copyright © 2020, 2022 Efraim Flashner >> ;;; Copyright © 2021 Maxime Devos >> ;;; Copyright © 2021 raid5atemyhomework >> +;;; Copyright © 2023 Bruno Victal >> ;;; >> ;;; This file is part of GNU Guix. >> ;;; >> @@ -31,6 +32,7 @@ >> ;;; along with GNU Guix. If not, see . >> >> (define-module (gnu system) >> + #:use-module (guix discovery) > > Do we really need this module? IIRC this was for the deprecated procedures to work. Can they work without this module? Cheers, Bruno From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 24 03:53:47 2023 Received: (at 60735) by debbugs.gnu.org; 24 Jan 2023 08:53:47 +0000 Received: from localhost ([127.0.0.1]:55826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKF3r-0003T0-6m for submit@debbugs.gnu.org; Tue, 24 Jan 2023 03:53:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55622) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKF3q-0003Sn-74 for 60735@debbugs.gnu.org; Tue, 24 Jan 2023 03:53:46 -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 1pKF3k-0002t8-8T; Tue, 24 Jan 2023 03:53:40 -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=bggO+lvyzUKNRvlfBQsMTzh6PYkqCIM7wOt+q9hgUEo=; b=ljkhUP72VSl4KmMUF8Y5 9yD9+hR/Xt3U9lKCnkdCH09gx8AyC/ZjLq2WIhlZ8jqfBW7rfs+X6+Mx3lktZ0Kf+qQhSzHKacp3U lKKDcCn+Bs8nQ03zMzHtTa6EoO1iGAOpxlxBPH39npkqCQSlL3QxwJBkZNBmpHX9bY56acwuIAOsW Kid99Lo3FA2VnALgyCho5SF7cclsrhqavPv7sQBsl4JAkDqy2aPbcJWLWaqpjCtfL22nObJqOeVc/ ztUm++nAanPh01dPySKmTghpNAjbp0TMMEOGSfMf2tCQKU+RAbmPltWY7Obb8rEUbnRObRpOAMCfN Pppx2UZjaZHzgQ==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKF3j-0000ms-H9; Tue, 24 Jan 2023 03:53:39 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: [PATCH v2 2/3] system: Deprecate hosts-file. References: <87o7qoyj0i.fsf@gnu.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quintidi 5 =?utf-8?Q?Pluvi=C3=B4se?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Taureau 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, 24 Jan 2023 09:53:37 +0100 In-Reply-To: (Bruno Victal's message of "Mon, 23 Jan 2023 23:19:00 +0000") Message-ID: <87tu0gwbxq.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Bruno! Bruno Victal skribis: > On 2023-01-23 22:37, Ludovic Court=C3=A8s wrote: >> Bruno Victal skribis: >>=20 >>> --- >>> >>> WIP, the ganeti tests fail because host-name is added as an alias of lo= calhost. >>=20 >> Before these patches, =E2=80=98host-name=E2=80=99 was already an alias o= f =E2=80=98localhost=E2=80=99. >> Is there something else interfering? > > In some cases, it's not desired for host-name to be an alias of localhost. > The ganeti tests did this by passing a hosts-file file-like object where > host-name wasn't an alias of localhost. Oh, I see. > I've brainstormed a bit on this and here's what I thought: > > Approach 1 (DOESN'T WORK): > * hosts-service-type in essential-services (gnu/systems.scm), default val= ue: > 127.0.0.1 localhost > ::1 localhost > * simple-service extension on base-services (gnu/services/base.scm): > \\FLOPS since both /etc/hosts and /etc/hostname are provisioned with act= ivation-service-type. > This means we can't write /etc/hosts AFTER /etc/hostname or host-name-se= rvice-type is ready. > > Approach 2: > * NO /etc/hosts in essential-services (is this possible?) > * is an absent /etc/hosts (or absent %base-services) a valid OS? > * Value set in %base-services, hosts-service-type as a ONE-SHOT shepherd = service. > * Can be changed with modify-services. > * It's a one-shot shepherd service since we're depending on /etc/hostnam= e which is activation-service-type. (we're depending on either etc-service-= type or host-name-service-type) > > Approach 3: > * Do not set our hostname as an alias of localhost by default. > * Manpage doesn't seem to make this mandatory, in fact, our hostname can= point to any IP. (it says 'often', not 'mandatory') > * We only set localhost name. > * Is this mandatory? If not, there might be cases where this entry is u= ndesired. Wait, why don=E2=80=99t we keep =E2=80=98hosts-service-type=E2=80=99 in =E2= =80=98essential-services=E2=80=99, with the localhost/host-name alias, and have =E2=80=98%ganeti-os=E2=80=99 i= n (gnu tests ganeti) modify its essential services to get what it wants? As in: (operating-system ;; =E2=80=A6 (essential-services (modify-services (operation-system-default-essential-services this-op= erating-system) (hosts-service-type config =3D> =E2=80=A6)))) Granted, that=E2=80=99s a bit verbose :-), but it should do the job just li= ke setting =E2=80=98hosts-file=E2=80=99 currently in =E2=80=98master=E2=80=99,= no? >> It doesn=E2=80=99t matter because it=E2=80=99s removed in the commit tha= t follows I >> think using =E2=80=98string-tokenize=E2=80=99 instead of =E2=80=98string= -split=E2=80=99 may bring >> simplifications. > > It was added because otherwise the "split" commits would seem to be missi= ng some context. > I can leave it as is, delete it here or try your suggestion. Yeah leave it as is. >>> + #:use-module (guix discovery) >>=20 >> Do we really need this module? > > IIRC this was for the deprecated procedures to work. Can they work withou= t this module? Yes, =E2=80=98define-deprecated=E2=80=99 is defined in (guix deprecation). Thanks! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 25 15:29:37 2023 Received: (at 60735) by debbugs.gnu.org; 25 Jan 2023 20:29:37 +0000 Received: from localhost ([127.0.0.1]:60054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKmOn-0004s9-3W for submit@debbugs.gnu.org; Wed, 25 Jan 2023 15:29:37 -0500 Received: from smtpm2.myservices.hosting ([185.26.105.233]:50404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKmOk-0004s0-Qk for 60735@debbugs.gnu.org; Wed, 25 Jan 2023 15:29:36 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm2.myservices.hosting (Postfix) with ESMTP id 9ACC620E6D; Wed, 25 Jan 2023 21:29:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 461518009C; Wed, 25 Jan 2023 21:29:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XzwS0emrbUju; Wed, 25 Jan 2023 21:29:32 +0100 (CET) Received: from [192.168.1.239] (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id E31AE8009B; Wed, 25 Jan 2023 21:29:31 +0100 (CET) Message-ID: Date: Wed, 25 Jan 2023 20:29:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v2 1/3] services: Add etc-hosts-service-type. Content-Language: en-US To: =?UTF-8?Q?Ludovic_Court=c3=a8s?= References: <87edrkyik8.fsf@gnu.org> From: Bruno Victal In-Reply-To: <87edrkyik8.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) On 2023-01-23 22:47, Ludovic Courtès wrote:> Also, there’s a naming confusion between ‘host’ and ‘host-entry’; you > should choose one or the other IMO. 'host' is a convenience procedure for creating host-entries while 'host-entry' is the record type, I don't see how these could be merged together. The host procedure could be changed to 'simple-host' to become less confusing. (It's a bit longer to type but I think it's acceptable) Thoughts? Cheers, Bruno From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 25 15:34:14 2023 Received: (at 60735) by debbugs.gnu.org; 25 Jan 2023 20:34:14 +0000 Received: from localhost ([127.0.0.1]:60060 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKmTF-00050F-PG for submit@debbugs.gnu.org; Wed, 25 Jan 2023 15:34:14 -0500 Received: from smtpmciv7.myservices.hosting ([185.26.106.202]:52152) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKmTC-000506-Ho for 60735@debbugs.gnu.org; Wed, 25 Jan 2023 15:34:12 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpmciv7.myservices.hosting (Postfix) with ESMTP id 808C320883; Wed, 25 Jan 2023 21:34:09 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 2BCB780097; Wed, 25 Jan 2023 21:34:09 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id MxZQIZxRt48K; Wed, 25 Jan 2023 21:34:08 +0100 (CET) Received: from [192.168.1.239] (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 4887280096; Wed, 25 Jan 2023 21:34:08 +0100 (CET) Message-ID: Date: Wed, 25 Jan 2023 20:34:07 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v2 3/3] services: Add block-facebook-hosts-service-type. Content-Language: en-US To: =?UTF-8?Q?Ludovic_Court=c3=a8s?= References: <511996014cccd059f1d2ea701e5fe134ad2c4735.1674060851.git.mirai@makinata.eu> <87k01cyivf.fsf@gnu.org> From: Bruno Victal In-Reply-To: <87k01cyivf.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 60735 Cc: 60735@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) On 2023-01-23 22:40, Ludovic Courtès wrote: > Bruno Victal skribis: > >> Deprecates %facebook-host-aliases in favour of using >> hosts-service-type service extensions. >> >> * gnu/services/networking.scm >> (block-facebook-hosts-service-type): New variable. >> (%facebook-host-aliases): Deprecate variable. >> * doc/guix.texi: Document it. > > [...] > >> -fe80::1%lo0 www.connect.facebook.net >> -fe80::1%lo0 apps.facebook.com\n") >> - >> + (let ((domains '("facebook.com" "www.facebook.com" >> + "login.facebook.com" "www.login.facebook.com" >> + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com" >> + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" >> + "connect.facebook.net" "www.connect.facebook.net" >> + "apps.facebook.com"))) >> + (append-map (lambda (name) >> + (map (lambda (addr) >> + (host addr name)) >> + (list "127.0.0.1" "::1"))) domains))) > > The IPv6 address is different, but now I’m not sure whether fe80::1%lo0 > made sense? It's a valid address though it's not really equivalent to [::1]. From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 27 16:06:48 2023 Received: (at 60735) by debbugs.gnu.org; 27 Jan 2023 21:06:48 +0000 Received: from localhost ([127.0.0.1]:38724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVvr-0007Jr-Jm for submit@debbugs.gnu.org; Fri, 27 Jan 2023 16:06:48 -0500 Received: from smtpm5.myservices.hosting ([185.26.105.236]:56310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVvn-0007Jf-FG for 60735@debbugs.gnu.org; Fri, 27 Jan 2023 16:06:46 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm5.myservices.hosting (Postfix) with ESMTP id 0E4AC20CFC for <60735@debbugs.gnu.org>; Fri, 27 Jan 2023 22:06:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id B150880096; Fri, 27 Jan 2023 22:06:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Lin9rSRk4mdT; Fri, 27 Jan 2023 22:06:38 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 7D29E80093; Fri, 27 Jan 2023 22:06:38 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v3 1/3] services: Add hosts-service-type. Date: Fri, 27 Jan 2023 21:06:11 +0000 Message-Id: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/services/base.scm (host, %host, host-address, host-canonical-name, host-aliases) (hosts-service-type): New variable. (host?): New predicate. * doc/guix.texi: Document it. --- doc/guix.texi | 75 +++++++++++++++++++++++++++++++++++++++++++ gnu/services/base.scm | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 2b1ad77ba5..e38c2c4b9b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -112,6 +112,7 @@ Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@* Copyright @copyright{} 2023 Giacomo Leidi@* Copyright @copyright{} 2022 Antero Mejr@* +Copyright @copyright{} 2023 Bruno Victal@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -40193,6 +40194,80 @@ Service Reference pointing to the given file. @end defvar +@defvar hosts-service-type +Type of the service that populates the entries for (@file{/etc/hosts}). +This service type can be extended by passing it a list of +@code{host} records. + +@c TRANSLATORS: The domain names below SHOULD NOT be translated. +@c They're domains reserved for use in documentation. (RFC6761 Section 6.5) +@c The addresses used are explained in RFC3849 and RFC5737. +@lisp +(simple-service 'add-extra-hosts + hosts-service-type + (list (host "192.0.2.1" "example.com" + '("example.net" "example.org")) + (host "2001:db8::1" "example.com" + '("example.net" "example.org")))) +@end lisp + +@quotation Note +@cindex @file{/etc/host} default entries +By default @file{/etc/host} comes with the following entries: +@example +127.0.0.1 localhost @var{host-name} +::1 localhost @var{host-name} +@end example + +For most setups this is what you want though if you find yourself in +the situation where you want to change the default entries, you can +do so in @code{operating-system}.@pxref{operating-system Reference,@code{essential-services}} + +The following example shows how one would unset @var{host-name} +from being an alias of @code{localhost}. +@lisp +(operating-system + ;; @dots{} + + (essential-services + (modify-services + (operation-system-default-essential-services this-operating-system) + (hosts-service-type config => (list + (host "127.0.0.1" "localhost") + (host "::1" "localhost"))))) + + ;; @dots{} +) +@end lisp +@end quotation + +@deftp {Data Type} host +Available @code{host} fields are: + +@table @asis +@item @code{address} (type: string) +IP address. + +@item @code{canonical-name} (type: string) +Hostname. + +@item @code{aliases} (default: @code{'()}) (type: list-of-string) +Additional aliases that map to the same @code{canonical-name}. + +@end table +@end deftp + +@defun host address canonical-name [aliases] +Procedure for creating @code{host} records. +@end defun + +@quotation Note +The @code{host} data type constructor is @code{%host} though it is +tiresome to create multiple records with it so in practice the procedure +@code{host} (which wraps around @code{%host}) is used instead. +@end quotation +@end defvar + @defvar setuid-program-service-type Type for the ``setuid-program service''. This service collects lists of executable file names, passed as gexps, and adds them to the set of diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 9e799445d2..53eda9ea1e 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2022 Guillaume Le Vaillant ;;; Copyright © 2022 Justin Veilleux ;;; Copyright © 2022 ( +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -103,6 +104,14 @@ (define-module (gnu services base) console-font-service virtual-terminal-service-type + host + %host + host? + host-address + host-canonical-name + host-aliases + hosts-service-type + static-networking static-networking? static-networking-addresses @@ -685,6 +694,67 @@ (define* (rngd-service #:key (rngd-configuration (rng-tools rng-tools) (device device)))) + +;;; +;;; /etc/hosts +;;; + +(define (valid-name? name) + "Return true if @var{name} is likely to be a valid hostname." + (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." + ;; TODO: RFC compliant implementation. + (unless (valid-name? name) + (raise + (make-compound-condition + (formatted-message (G_ "hostname '~a' contains invalid characters") + name) + (condition (&error-location + (location + (source-properties->location procedure-call-location))))))) + name) + +(define-record-type* %host + ;; XXX: Using the record type constructor becomes tiresome when + ;; there's multiple records to make. + make-host host? + (address host-address) + (canonical-name host-canonical-name + (sanitize assert-valid-name)) + (aliases host-aliases + (default '()) + (sanitize (cut map assert-valid-name <>)))) + +(define* (host address canonical-name #:optional (aliases '())) + "Public constructor for records." + (%host + (address address) + (canonical-name canonical-name) + (aliases aliases))) + +(define hosts-service-type + ;; Extend etc-service-type with a entry for @file{/etc/hosts}. + (let* ((serialize-host-record + (lambda (record) + (match-record record (address canonical-name aliases) + (format #f "~a~/~a~{~^~/~a~}~%" address canonical-name aliases)))) + (host-etc-service + (lambda (lst) + `(("hosts" ,(plain-file "hosts" + (format #f "~{~a~}" + (map serialize-host-record + lst)))))))) + (service-type + (name 'etc-hosts) + (extensions + (list + (service-extension etc-service-type + host-etc-service))) + (compose concatenate) + (extend append) + (description "Populate the @file{/etc/hosts} file.")))) ;;; base-commit: 35e626f312aa5f8c9c4c3f06751db5e3394c66b6 -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 27 16:07:32 2023 Received: (at 60735) by debbugs.gnu.org; 27 Jan 2023 21:07:32 +0000 Received: from localhost ([127.0.0.1]:38728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVwZ-0007LB-8v for submit@debbugs.gnu.org; Fri, 27 Jan 2023 16:07:32 -0500 Received: from smtpmciv2.myservices.hosting ([185.26.107.238]:47450) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVwV-0007L1-7e for 60735@debbugs.gnu.org; Fri, 27 Jan 2023 16:07:29 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpmciv2.myservices.hosting (Postfix) with ESMTP id 84F5520D8D for <60735@debbugs.gnu.org>; Fri, 27 Jan 2023 22:07:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 323CC80098; Fri, 27 Jan 2023 22:07:26 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eNHvFgGnbsUm; Fri, 27 Jan 2023 22:07:25 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id BC71180097; Fri, 27 Jan 2023 22:07:24 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v3 2/3] system: Deprecate hosts-file. Date: Fri, 27 Jan 2023 21:06:12 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> References: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/system.scm (operating-system-hosts-file): Deprecate procedure. (warn-hosts-file-field-deprecation): New procedure, helper for deprecated variable. (operating-system)[hosts-file]: Use helper to warn deprecated field. (operating-system-default-essential-services) (hurd-default-essential-services): Use hosts-service-type. (local-host-aliases): Return a list of host records. (default-/etc/hosts): Remove procedure. (operating-system-etc-service): Remove hosts file. * doc/guix.texi (operating-system Reference) (Networking Services) (Virtualization Services): Rewrite documentation entries to use hosts-service-type. --- doc/guix.texi | 60 +++++++++++++++++++++++--------------------- gnu/system.scm | 54 ++++++++++++++++++++++++++++----------- gnu/tests/ganeti.scm | 26 +++++++++++-------- 3 files changed, 88 insertions(+), 52 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index e38c2c4b9b..84afadafdb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -16480,13 +16480,6 @@ operating-system Reference @item @code{host-name} The host name. -@item @code{hosts-file} -@cindex hosts file -A file-like object (@pxref{G-Expressions, file-like objects}) for use as -@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library -Reference Manual}). The default is a file with entries for -@code{localhost} and @var{host-name}. - @item @code{mapped-devices} (default: @code{'()}) A list of mapped devices. @xref{Mapped Devices}. @@ -21011,22 +21004,33 @@ Networking Services on-line service---e.g., @code{www.facebook.com}---to the local host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. -This variable is typically used in the @code{hosts-file} field of an -@code{operating-system} declaration (@pxref{operating-system Reference, -@file{/etc/hosts}}): +This variable is typically used as a @code{hosts-service-type} +service extension (@pxref{Service Reference, @code{hosts-service-type}}): @lisp -(use-modules (gnu) (guix)) +(use-modules (gnu) (gnu services) (guix) (srfi srfi-1) (ice-9 match)) +(use-service-modules networking) (operating-system - (host-name "mymachine") - ;; ... - (hosts-file - ;; Create a /etc/hosts file with aliases for "localhost" - ;; and "mymachine", as well as for Facebook servers. - (plain-file "hosts" - (string-append (local-host-aliases host-name) - %facebook-host-aliases)))) + ;; @dots{} + + (service + (simple-service 'block-facebook-hosts hosts-service-type + (let ((host-pairs + (filter-map + (lambda (x) + (and (not (or (string-null? x) + (string-prefix? "#" x))) + (remove string-null? + (string-split + x + char-set:whitespace)))) + (string-split %facebook-host-aliases #\newline)))) + (map (match-lambda + ((addr name) + (host addr name))) + host-pairs))) + ;; @dots{} @end lisp This mechanism can prevent programs running locally, such as Web @@ -34312,7 +34316,7 @@ Virtualization Services services which are described later in this section. In addition to the Ganeti service, you will need the OpenSSH service (@pxref{Networking Services, @code{openssh-service-type}}), and update the @file{/etc/hosts} file -(@pxref{operating-system Reference, @code{hosts-file}}) with the cluster name +(@pxref{Service Reference, @code{hosts-service-type}}) with the cluster name and address (or use a DNS server). All nodes participating in a Ganeti cluster should have the same Ganeti and @@ -34326,14 +34330,6 @@ Virtualization Services (operating-system ;; @dots{} (host-name "node1") - (hosts-file (plain-file "hosts" (format #f " -127.0.0.1 localhost -::1 localhost - -192.168.1.200 ganeti.example.com -192.168.1.201 node1.example.com node1 -192.168.1.202 node2.example.com node2 -"))) ;; Install QEMU so we can use KVM-based instances, and LVM, DRBD and Ceph ;; in order to use the "plain", "drbd" and "rbd" storage backends. @@ -34361,6 +34357,14 @@ Virtualization Services (openssh-configuration (permit-root-login 'prohibit-password))) + (simple-service 'ganeti-hosts-entries hosts-service-type + (list + (host "192.168.1.200" "ganeti.example.com") + (host "192.168.1.201" "node1.example.com" + '("node1")) + (host "192.168.1.202" "node2.example.com" + '("node2")))) + (service ganeti-service-type (ganeti-configuration ;; This list specifies allowed file system paths diff --git a/gnu/system.scm b/gnu/system.scm index d67f9a615b..e8904cfab7 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -14,6 +14,7 @@ ;;; Copyright © 2020, 2022 Efraim Flashner ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2021 raid5atemyhomework +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -97,7 +98,7 @@ (define-module (gnu system) operating-system-user-services operating-system-packages operating-system-host-name - operating-system-hosts-file + operating-system-hosts-file ;deprecated operating-system-hurd operating-system-kernel operating-system-kernel-file @@ -208,6 +209,15 @@ (define* (bootable-kernel-arguments system root-device version) #$system "/boot"))) ;; System-wide configuration. + +(define-with-syntax-properties (warn-hosts-file-field-deprecation + (value properties)) + (when value + (warning (source-properties->location properties) + (G_ "the 'hosts-file' field is deprecated, please use \ +'hosts-service-type' instead~%"))) + value) + ;; TODO: Add per-field docstrings/stexi. (define-record-type* operating-system make-operating-system @@ -239,8 +249,9 @@ (define-record-type* operating-system (default %base-firmware)) (host-name operating-system-host-name) ; string - (hosts-file operating-system-hosts-file ; file-like | #f - (default #f)) + (hosts-file %operating-system-hosts-file ; deprecated + (default #f) + (sanitize warn-hosts-file-field-deprecation)) (mapped-devices operating-system-mapped-devices ; list of (default '())) @@ -296,6 +307,10 @@ (define-record-type* operating-system source-properties->location)) (innate))) +(define-deprecated (operating-system-hosts-file os) + hosts-service-type + (%operating-system-hosts-file os)) + (define* (operating-system-kernel-arguments os root-device #:key (version %boot-parameters-version)) "Return all the kernel arguments, including the ones not specified directly @@ -733,7 +748,8 @@ (define (operating-system-default-essential-services os) (non-boot-fs (non-boot-file-system-service os)) (swaps (swap-services os)) (procs (service user-processes-service-type)) - (host-name (host-name-service (operating-system-host-name os))) + (host-name (operating-system-host-name 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 @@ -755,12 +771,19 @@ (define (operating-system-default-essential-services os) (operating-system-groups os)) (operating-system-skeletons os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service hosts-service-type + (local-host-aliases host-name))) (service fstab-service-type (filter file-system-needed-for-boot? (operating-system-file-systems os))) (session-environment-service (operating-system-environment-variables os)) - host-name procs root-fs + (host-name-service host-name) + procs root-fs (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type @@ -774,7 +797,9 @@ (define (operating-system-default-essential-services os) (operating-system-firmware os))))))) (define (hurd-default-essential-services os) - (let ((entries (operating-system-directory-base-entries os))) + (let ((host-name (operating-system-host-name os)) + (hosts-file (operating-system-hosts-file os)) + (entries (operating-system-directory-base-entries os))) (list (service system-service-type entries) %boot-service %hurd-startup-service @@ -794,6 +819,12 @@ (define (hurd-default-essential-services os) (operating-system-file-systems os))) (pam-root-service (operating-system-pam-services os)) (operating-system-etc-service os) + ;; XXX: hosts-file is deprecated + (if hosts-file + (simple-service 'deprecated-hosts-file etc-service-type + (list `("hosts" ,hosts-file))) + (service hosts-service-type + (local-host-aliases host-name))) (service setuid-program-service-type (operating-system-setuid-programs os)) (service profile-service-type (operating-system-packages os))))) @@ -914,12 +945,9 @@ (define %default-issue (define (local-host-aliases host-name) "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 (default-/etc/hosts host-name) - "Return the default /etc/hosts file." - (plain-file "hosts" (local-host-aliases host-name))) + (map (lambda (address) + (host address "localhost" (list host-name))) + '("127.0.0.1" "::1"))) (define (validated-sudoers-file file) "Return a copy of FILE, a sudoers file, after checking that it is @@ -1068,8 +1096,6 @@ (define* (operating-system-etc-service os) ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '()) ("profile" ,#~#$profile) ("bashrc" ,#~#$bashrc) - ("hosts" ,#~#$(or (operating-system-hosts-file os) - (default-/etc/hosts (operating-system-host-name os)))) ;; Write the operating-system-host-name to /etc/hostname to prevent ;; NetworkManager from changing the system's hostname when connecting ;; to certain networks. Some discussion at diff --git a/gnu/tests/ganeti.scm b/gnu/tests/ganeti.scm index f647e9554c..b5624b7598 100644 --- a/gnu/tests/ganeti.scm +++ b/gnu/tests/ganeti.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2020, 2021 Marius Bakke ;;; Copyright © 2020 Brice Waegeneire +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ (define-module (gnu tests ganeti) #:use-module (gnu tests) #:use-module (gnu system vm) #:use-module (gnu services) + #:use-module (gnu services base) #:use-module (gnu services ganeti) #:use-module (gnu services networking) #:use-module (gnu services ssh) @@ -46,18 +48,15 @@ (define %ganeti-os %base-file-systems)) (firmware '()) - ;; The hosts file must contain a nonlocal IP for host-name. - ;; In addition, the cluster name must resolve to an IP address that - ;; is not currently provisioned. - (hosts-file (plain-file "hosts" (format #f " -127.0.0.1 localhost -::1 localhost -10.0.2.15 gnt1.example.com gnt1 -192.168.254.254 ganeti.example.com -"))) - (packages (append (list ganeti-instance-debootstrap ganeti-instance-guix) %base-packages)) + + ;; The hosts file must contain a nonlocal IP for host-name. + (essential-services + (modify-services (operating-system-default-essential-services this-operating-system) + (hosts-service-type config => (list + (host "127.0.0.1" "localhost") + (host "::1" "localhost"))))) (services (append (list (service static-networking-service-type (list %qemu-static-networking)) @@ -65,6 +64,13 @@ (define %ganeti-os (openssh-configuration (permit-root-login 'prohibit-password))) + ;; In addition, the cluster name must resolve to an IP address that + ;; is not currently provisioned. + (simple-service 'ganeti-host-entries hosts-service-type + (list + (host "10.0.2.15" "gnt1.example.com" '("gnt1")) + (host "192.168.254.254" "ganeti.example.com"))) + (service ganeti-service-type (ganeti-configuration (file-storage-paths '("/srv/ganeti/file-storage")) -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 27 16:08:18 2023 Received: (at 60735) by debbugs.gnu.org; 27 Jan 2023 21:08:18 +0000 Received: from localhost ([127.0.0.1]:38732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVxK-0007Mc-7e for submit@debbugs.gnu.org; Fri, 27 Jan 2023 16:08:18 -0500 Received: from smtpmciv8.myservices.hosting ([185.26.106.203]:39470) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLVxH-0007MT-IX for 60735@debbugs.gnu.org; Fri, 27 Jan 2023 16:08:17 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpmciv8.myservices.hosting (Postfix) with ESMTP id CD3F620D92 for <60735@debbugs.gnu.org>; Fri, 27 Jan 2023 22:08:14 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 8932D80098; Fri, 27 Jan 2023 22:08:14 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-1.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id x7jJuLVD1rGG; Fri, 27 Jan 2023 22:08:14 +0100 (CET) Received: from guix-nuc.home.arpa (bl9-118-236.dsl.telepac.pt [85.242.118.236]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id CB00680097; Fri, 27 Jan 2023 22:08:13 +0100 (CET) From: Bruno Victal To: 60735@debbugs.gnu.org Subject: [PATCH v3 3/3] services: Add block-facebook-hosts-service-type. Date: Fri, 27 Jan 2023 21:06:13 +0000 Message-Id: <55ce2a77151a50d5e6e179ce53b437a3d0dc6d2b.1674853530.git.mirai@makinata.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> References: <23c3ca682838a1722e619148bac0aee88124d212.1674853530.git.mirai@makinata.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60735 Cc: Bruno Victal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Deprecates %facebook-host-aliases in favour of using hosts-service-type service extensions. * gnu/services/networking.scm (block-facebook-hosts-service-type): New variable. (%facebook-host-aliases): Deprecate variable. * doc/guix.texi: Document it. --- doc/guix.texi | 38 +++------------------- gnu/services/networking.scm | 64 ++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 65 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 84afadafdb..fb651f0315 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20997,42 +20997,14 @@ Networking Services @end table @end deftp -@defvar %facebook-host-aliases -This variable contains a string for use in @file{/etc/hosts} -(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each -line contains a entry that maps a known server name of the Facebook +@defvar block-facebook-hosts-service-type +This service type adds a list of known Facebook hosts to the +@file{/etc/hosts} file. +(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}) +Each line contains a entry that maps a known server name of the Facebook on-line service---e.g., @code{www.facebook.com}---to the local host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. -This variable is typically used as a @code{hosts-service-type} -service extension (@pxref{Service Reference, @code{hosts-service-type}}): - -@lisp -(use-modules (gnu) (gnu services) (guix) (srfi srfi-1) (ice-9 match)) -(use-service-modules networking) - -(operating-system - ;; @dots{} - - (service - (simple-service 'block-facebook-hosts hosts-service-type - (let ((host-pairs - (filter-map - (lambda (x) - (and (not (or (string-null? x) - (string-prefix? "#" x))) - (remove string-null? - (string-split - x - char-set:whitespace)))) - (string-split %facebook-host-aliases #\newline)))) - (map (match-lambda - ((addr name) - (host addr name))) - host-pairs))) - ;; @dots{} -@end lisp - This mechanism can prevent programs running locally, such as Web browsers, from accessing Facebook. @end defvar diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 89ce16f6af..dacf64c2d1 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2022, 2023 Andrew Tropin ;;; Copyright © 2023 Declan Tsien +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -80,7 +81,9 @@ (define-module (gnu services networking) #:use-module (json) #:re-export (static-networking-service static-networking-service-type) - #:export (%facebook-host-aliases + #:export (%facebook-host-aliases ;deprecated + block-facebook-hosts-service-type + dhcp-client-service-type dhcp-client-configuration dhcp-client-configuration? @@ -235,39 +238,36 @@ (define-module (gnu services networking) ;;; ;;; Code: -(define %facebook-host-aliases +(define facebook-host-aliases ;; This is the list of known Facebook hosts to be added to /etc/hosts if you ;; are to block it. - "\ -# Block Facebook IPv4. -127.0.0.1 www.facebook.com -127.0.0.1 facebook.com -127.0.0.1 login.facebook.com -127.0.0.1 www.login.facebook.com -127.0.0.1 fbcdn.net -127.0.0.1 www.fbcdn.net -127.0.0.1 fbcdn.com -127.0.0.1 www.fbcdn.com -127.0.0.1 static.ak.fbcdn.net -127.0.0.1 static.ak.connect.facebook.com -127.0.0.1 connect.facebook.net -127.0.0.1 www.connect.facebook.net -127.0.0.1 apps.facebook.com - -# Block Facebook IPv6. -fe80::1%lo0 facebook.com -fe80::1%lo0 login.facebook.com -fe80::1%lo0 www.login.facebook.com -fe80::1%lo0 fbcdn.net -fe80::1%lo0 www.fbcdn.net -fe80::1%lo0 fbcdn.com -fe80::1%lo0 www.fbcdn.com -fe80::1%lo0 static.ak.fbcdn.net -fe80::1%lo0 static.ak.connect.facebook.com -fe80::1%lo0 connect.facebook.net -fe80::1%lo0 www.connect.facebook.net -fe80::1%lo0 apps.facebook.com\n") - + (let ((domains '("facebook.com" "www.facebook.com" + "login.facebook.com" "www.login.facebook.com" + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com" + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" + "connect.facebook.net" "www.connect.facebook.net" + "apps.facebook.com"))) + (append-map (lambda (name) + (map (lambda (addr) + (host addr name)) + (list "127.0.0.1" "::1"))) domains))) + +(define-deprecated %facebook-host-aliases + block-facebook-hosts-service-type + (string-join + (map (lambda (x) + (string-append (host-address x) "\t" + (host-canonical-name x) "\n")) + facebook-host-aliases))) + +(define block-facebook-hosts-service-type + (service-type + (name 'block-facebook-hosts) + (extensions + (list (service-extension hosts-service-type + (const facebook-host-aliases)))) + (default-value #f) + (description "Add a list of known Facebook hosts to @file{/etc/hosts}"))) (define-record-type* dhcp-client-configuration make-dhcp-client-configuration -- 2.38.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 08 18:57:54 2023 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: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Bruno Victal Subject: Re: bug#60735: [PATCH 0/2] Implement etc-hosts-service-type 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 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60735-done Cc: 60735-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Bruno, I=E2=80=99ve finally applied this v3 with the changes below: =E2=80=A2 spelling =E2=80=9Chost name=E2=80=9D as two words and tweaking = docstrings of public procedures; =E2=80=A2 keeping =E2=80=98local-host-aliases=E2=80=99 unchanged (returni= ng a string) as this is public and documented, and adding =E2=80=98local-host-entries=E2=80= =99 to return a list of records; =E2=80=A2 referencing to =E2=80=98%operating-system-hosts-file=E2=80=99 (= with leading percent sign) internally to avoid deprecation warnings. Thank you! Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline 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"))) --=-=-=-- From unknown Mon Jun 16 23:46:29 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 09 Mar 2023 12:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator