diff mbox series

bug#60735: [PATCH 0/2] Implement etc-hosts-service-type

Message ID 87zg9nvhfw.fsf_-_@gnu.org
State New
Headers show
Series bug#60735: [PATCH 0/2] Implement etc-hosts-service-type | expand

Commit Message

Ludovic Courtès Feb. 8, 2023, 11:57 p.m. UTC
Hi Bruno,

I’ve finally applied this v3 with the changes below:

  • spelling “host name” as two words and tweaking docstrings of public
    procedures;

  • keeping ‘local-host-aliases’ unchanged (returning a string) as this
    is public and documented, and adding ‘local-host-entries’ to return
    a list of <host> records;

  • referencing to ‘%operating-system-hosts-file’ (with leading percent
    sign) internally to avoid deprecation warnings.

Thank you!

Ludo’.
diff mbox series

Patch

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> %host
                   (sanitize (cut map assert-valid-name <>))))
 
 (define* (host address canonical-name #:optional (aliases '()))
-  "Public constructor for <host> 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 <host> records for @var{host-name}."
   (map (lambda (address)
          (host address "localhost" (list host-name)))
        '("127.0.0.1" "::1")))