From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id mJcWGUQ91GNQ2AAAbAwnHQ (envelope-from ) for ; Fri, 27 Jan 2023 22:08:20 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2GvkGEQ91GO2TAEAauVa8A (envelope-from ) for ; Fri, 27 Jan 2023 22:08:20 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E570338730 for ; Fri, 27 Jan 2023 22:08:19 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLVx6-0001uZ-Kp; Fri, 27 Jan 2023 16:08:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLVx4-0001u2-T1 for guix-patches@gnu.org; Fri, 27 Jan 2023 16:08:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLVx4-0003n0-Js for guix-patches@gnu.org; Fri, 27 Jan 2023 16:08:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pLVx4-0007Lz-Ci for guix-patches@gnu.org; Fri, 27 Jan 2023 16:08:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60735] [PATCH v3 2/3] system: Deprecate hosts-file. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 27 Jan 2023 21:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60735 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60735@debbugs.gnu.org Cc: Bruno Victal Received: via spool by 60735-submit@debbugs.gnu.org id=B60735.167485365228227 (code B ref 60735); Fri, 27 Jan 2023 21:08:02 +0000 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 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1674853700; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=YysHKvl7yHTLrB0G6jYfYM3Xev6VGdVOWDZSR+kJmlM=; b=qR8qeWCUfwh+3vwrajo8qYQL6GP3oNNDm4co1FL5CvDhkrAIEMlJdPvjV+cv2D+NJ+ymnl jKf5loIVErbT6ZjkY94LI41p0seIdl/AHEjgLlXFpyKflDabmijZHuvEa6FX+l91SY14bP qvzciC7RgkaUEs38hG11rShiRod/UUKCbK+OMy974MGJt9daUIIMZTIiebGE6EvRSD1+8O e3RSG3HlPUVjIVi72kaXG3ipdOiNPtWsMymv1s+F2vOExPc39/exiCYwia29YjjgC39q5C 7NNMuZOmfqfram1GS3WOW8vDGpeG+jysFWtN0+uU/e7uLOvKIs/ckgZwnkyZ4A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1674853700; a=rsa-sha256; cv=none; b=rL4uzbghHDscq4Fh+Z8olzv6JPw2nVTBbB/4YlZO59Gppb0DYef9xfTQPB1TW/5jTxN4bD zD3WrGrAfKU7tBJc2udBc1DqdZLNz/wLyIp/EX1rmVa6uw9LxIGAuKHyCuVsKuWFzfv1O1 gAExT02Fs2pUaB6xs7YHL/WNWuLhIVWgvuPKQyIq0v+4XUm7UMYTUKc4A8798L1xKLW+UZ f0BZ66JGLnUyaLN7osZ7Gdi7e8KP0uolPjONSPKffdDc06yp7GxvRB2b2ycM/APpikJlwi qeiTOK6s+G43TzdegS6ZZfwx3uvfHH+KYkoH0Pntyg7m0zWQrN7B9LdJrG0RTQ== X-Spam-Score: -0.57 X-Migadu-Spam-Score: -0.57 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: E570338730 X-Migadu-Scanner: scn1.migadu.com X-TUID: 2LYnQgld9fNm * 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