me
/
guix
Archived
1
0
Fork 0

system: Deprecate hosts-file.

* 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.
(local-host-aliases): Mark as deprecated.
(local-host-entries): New procedure.
(operating-system-default-essential-services,
hurd-default-essential-services): Use hosts-service-type.  Use
'%operating-system-hosts-file' and 'local-host-entries'.
(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.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
master
Bruno Victal 2023-01-27 21:06:12 +00:00 committed by Ludovic Courtès
parent 22dd558c70
commit 802ea1f3a4
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
3 changed files with 94 additions and 51 deletions

View File

@ -16481,13 +16481,6 @@ supported hardware.
@item @code{host-name} @item @code{host-name}
The 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{'()}) @item @code{mapped-devices} (default: @code{'()})
A list of mapped devices. @xref{Mapped Devices}. A list of mapped devices. @xref{Mapped Devices}.
@ -21012,22 +21005,33 @@ 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 on-line service---e.g., @code{www.facebook.com}---to the local
host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. 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 This variable is typically used as a @code{hosts-service-type}
@code{operating-system} declaration (@pxref{operating-system Reference, service extension (@pxref{Service Reference, @code{hosts-service-type}}):
@file{/etc/hosts}}):
@lisp @lisp
(use-modules (gnu) (guix)) (use-modules (gnu) (gnu services) (guix) (srfi srfi-1) (ice-9 match))
(use-service-modules networking)
(operating-system (operating-system
(host-name "mymachine") ;; @dots{}
;; ...
(hosts-file (service
;; Create a /etc/hosts file with aliases for "localhost" (simple-service 'block-facebook-hosts hosts-service-type
;; and "mymachine", as well as for Facebook servers. (let ((host-pairs
(plain-file "hosts" (filter-map
(string-append (local-host-aliases host-name) (lambda (x)
%facebook-host-aliases)))) (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 @end lisp
This mechanism can prevent programs running locally, such as Web This mechanism can prevent programs running locally, such as Web
@ -34555,7 +34559,7 @@ and to make maintenance and recovery tasks easy. It consists of multiple
services which are described later in this section. In addition to the Ganeti services which are described later in this section. In addition to the Ganeti
service, you will need the OpenSSH service (@pxref{Networking Services, service, you will need the OpenSSH service (@pxref{Networking Services,
@code{openssh-service-type}}), and update the @file{/etc/hosts} file @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). and address (or use a DNS server).
All nodes participating in a Ganeti cluster should have the same Ganeti and All nodes participating in a Ganeti cluster should have the same Ganeti and
@ -34569,14 +34573,6 @@ cluster node that supports multiple storage backends, and installs the
(operating-system (operating-system
;; @dots{} ;; @dots{}
(host-name "node1") (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 ;; 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. ;; in order to use the "plain", "drbd" and "rbd" storage backends.
@ -34604,6 +34600,14 @@ cluster node that supports multiple storage backends, and installs the
(openssh-configuration (openssh-configuration
(permit-root-login 'prohibit-password))) (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 (service ganeti-service-type
(ganeti-configuration (ganeti-configuration
;; This list specifies allowed file system paths ;; This list specifies allowed file system paths

View File

@ -14,6 +14,7 @@
;;; Copyright © 2020, 2022 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2020, 2022 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -97,7 +98,7 @@
operating-system-user-services operating-system-user-services
operating-system-packages operating-system-packages
operating-system-host-name operating-system-host-name
operating-system-hosts-file operating-system-hosts-file ;deprecated
operating-system-hurd operating-system-hurd
operating-system-kernel operating-system-kernel
operating-system-kernel-file operating-system-kernel-file
@ -169,7 +170,8 @@
read-boot-parameters-file read-boot-parameters-file
boot-parameters->menu-entry boot-parameters->menu-entry
local-host-aliases local-host-aliases ;deprecated
local-host-entries
%root-account %root-account
%setuid-programs %setuid-programs
%sudoers-specification %sudoers-specification
@ -208,6 +210,15 @@ VERSION is the target version of the boot-parameters record."
#$system "/boot"))) #$system "/boot")))
;; System-wide configuration. ;; 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. ;; TODO: Add per-field docstrings/stexi.
(define-record-type* <operating-system> operating-system (define-record-type* <operating-system> operating-system
make-operating-system make-operating-system
@ -239,8 +250,9 @@ VERSION is the target version of the boot-parameters record."
(default %base-firmware)) (default %base-firmware))
(host-name operating-system-host-name) ; string (host-name operating-system-host-name) ; string
(hosts-file operating-system-hosts-file ; file-like | #f (hosts-file %operating-system-hosts-file ; deprecated
(default #f)) (default #f)
(sanitize warn-hosts-file-field-deprecation))
(mapped-devices operating-system-mapped-devices ; list of <mapped-device> (mapped-devices operating-system-mapped-devices ; list of <mapped-device>
(default '())) (default '()))
@ -296,6 +308,10 @@ VERSION is the target version of the boot-parameters record."
source-properties->location)) source-properties->location))
(innate))) (innate)))
(define-deprecated (operating-system-hosts-file os)
hosts-service-type
(%operating-system-hosts-file os))
(define* (operating-system-kernel-arguments (define* (operating-system-kernel-arguments
os root-device #:key (version %boot-parameters-version)) os root-device #:key (version %boot-parameters-version))
"Return all the kernel arguments, including the ones not specified directly "Return all the kernel arguments, including the ones not specified directly
@ -733,7 +749,8 @@ bookkeeping."
(non-boot-fs (non-boot-file-system-service os)) (non-boot-fs (non-boot-file-system-service os))
(swaps (swap-services os)) (swaps (swap-services os))
(procs (service user-processes-service-type)) (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))) (entries (operating-system-directory-base-entries os)))
(cons* (service system-service-type entries) (cons* (service system-service-type entries)
(service linux-builder-service-type (service linux-builder-service-type
@ -755,12 +772,19 @@ bookkeeping."
(operating-system-groups os)) (operating-system-groups os))
(operating-system-skeletons os)) (operating-system-skeletons os))
(operating-system-etc-service 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-entries host-name)))
(service fstab-service-type (service fstab-service-type
(filter file-system-needed-for-boot? (filter file-system-needed-for-boot?
(operating-system-file-systems os))) (operating-system-file-systems os)))
(session-environment-service (session-environment-service
(operating-system-environment-variables os)) (operating-system-environment-variables os))
host-name procs root-fs (host-name-service host-name)
procs root-fs
(service setuid-program-service-type (service setuid-program-service-type
(operating-system-setuid-programs os)) (operating-system-setuid-programs os))
(service profile-service-type (service profile-service-type
@ -774,7 +798,9 @@ bookkeeping."
(operating-system-firmware os))))))) (operating-system-firmware os)))))))
(define (hurd-default-essential-services 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) (list (service system-service-type entries)
%boot-service %boot-service
%hurd-startup-service %hurd-startup-service
@ -794,6 +820,12 @@ bookkeeping."
(operating-system-file-systems os))) (operating-system-file-systems os)))
(pam-root-service (operating-system-pam-services os)) (pam-root-service (operating-system-pam-services os))
(operating-system-etc-service 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-entries host-name)))
(service setuid-program-service-type (service setuid-program-service-type
(operating-system-setuid-programs os)) (operating-system-setuid-programs os))
(service profile-service-type (operating-system-packages os))))) (service profile-service-type (operating-system-packages os)))))
@ -912,14 +944,17 @@ of PROVENANCE-SERVICE-TYPE to its services."
" "
This is the GNU system. Welcome.\n") 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." "Return aliases for HOST-NAME, to be used in /etc/hosts."
(string-append "127.0.0.1 localhost " host-name "\n" (string-append "127.0.0.1 localhost " host-name "\n"
"::1 localhost " host-name "\n")) "::1 localhost " host-name "\n"))
(define (default-/etc/hosts host-name) (define (local-host-entries host-name)
"Return the default /etc/hosts file." "Return <host> records for @var{host-name}."
(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) (define (validated-sudoers-file file)
"Return a copy of FILE, a sudoers file, after checking that it is "Return a copy of FILE, a sudoers file, after checking that it is
@ -1068,8 +1103,6 @@ fi\n")))
,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '()) ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '())
("profile" ,#~#$profile) ("profile" ,#~#$profile)
("bashrc" ,#~#$bashrc) ("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 ;; Write the operating-system-host-name to /etc/hostname to prevent
;; NetworkManager from changing the system's hostname when connecting ;; NetworkManager from changing the system's hostname when connecting
;; to certain networks. Some discussion at ;; to certain networks. Some discussion at

View File

@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020, 2021 Marius Bakke <marius@gnu.org> ;;; Copyright © 2020, 2021 Marius Bakke <marius@gnu.org>
;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -22,6 +23,7 @@
#:use-module (gnu tests) #:use-module (gnu tests)
#:use-module (gnu system vm) #:use-module (gnu system vm)
#:use-module (gnu services) #:use-module (gnu services)
#:use-module (gnu services base)
#:use-module (gnu services ganeti) #:use-module (gnu services ganeti)
#:use-module (gnu services networking) #:use-module (gnu services networking)
#:use-module (gnu services ssh) #:use-module (gnu services ssh)
@ -46,18 +48,15 @@
%base-file-systems)) %base-file-systems))
(firmware '()) (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) (packages (append (list ganeti-instance-debootstrap ganeti-instance-guix)
%base-packages)) %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 (services
(append (list (service static-networking-service-type (append (list (service static-networking-service-type
(list %qemu-static-networking)) (list %qemu-static-networking))
@ -65,6 +64,13 @@
(openssh-configuration (openssh-configuration
(permit-root-login 'prohibit-password))) (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 (service ganeti-service-type
(ganeti-configuration (ganeti-configuration
(file-storage-paths '("/srv/ganeti/file-storage")) (file-storage-paths '("/srv/ganeti/file-storage"))