From: Gary Johnson <lambdatronic@disroot.org>
To: Remco van 't Veer <remco@remworks.net>
Cc: Sergiu Ivanov <sivanov@colimite.fr>, help-guix@gnu.org
Subject: Re: Examples of local-host-entries or hosts-service-type?
Date: Tue, 21 Feb 2023 10:33:25 -0500 [thread overview]
Message-ID: <874jrfrpa1.fsf@disroot.org> (raw)
In-Reply-To: <87r0uw4e78.fsf@remworks.net>
2023/02/10 23:40, Sergiu Ivanov:
> I am reconfiguring my system right now, and guix system reconfigure
> /etc/config.scm tells me this:
>
> /etc/config.scm:126:27: warning: 'local-host-aliases' is deprecated, use 'local-host-entries' instead
> /etc/config.scm:126:27: warning: 'local-host-aliases' is deprecated, use 'local-host-entries' instead
> /etc/config.scm:124:14: warning: the 'hosts-file' field is deprecated, please use 'hosts-service-type' instead
>
> For the record, here are the lines guix system reconfigure is
> complaining about:
>
> (hosts-file (plain-file "hosts"
> (string-append
> (local-host-aliases host-name)
> "some.ip.address.1 machine1\n"
> "some.other.ip.address machine2\n")))
>
> I spent quite some time trying to find some examples of using
> local-host-entries or hosts-service-type, but I don't seem to find any
> mention of these. Quite on the contrary, the Guix manual actually seems
> to advice declarations similar to those which I have in my
> /etc/config.scm.
>
> Could someone point me to an example of how I should update
> my configuration?
Hi Sergiu et al,
I just went through this exercise myself, and I decided to keep my
extra /etc/hosts entries in a separate text file using the original
hosts format. This makes them much easier for me to read and edit. To
provide them to the `hosts-service-type` service, I went ahead and wrote
a little importer function in Scheme that I thought some other folks
might benefit from. Here it is along with how to use it in your
`operating-system` declaration:
```scheme
(use-modules
((gnu services base) #:select (hosts-service-type host))
((gnu services desktop) #:select (%desktop-services))
((gnu services) #:select (simple-service))
((gnu system) #:select (operating-system))
((ice-9 ports) #:select (call-with-input-file))
((ice-9 textual-ports) #:select (get-string-all)))
(define (load-hosts-entries)
(call-with-input-file "etcfiles/extra-hosts"
(lambda (p)
(let* ((text (get-string-all p))
(lines (string-split text #\newline))
(lines* (filter (lambda (l) (not (or (string-null? l) (string-prefix? "#" l)))) lines)))
(map (lambda (l)
(let* ((tokens (string-split l #\space))
(tokens* (filter (lambda (t) (not (string-null? t))) tokens))
(ip (car tokens*))
(alias (cadr tokens*)))
(host ip alias)))
lines*)))))
(operating-system
...
(services (cons* (simple-service 'add-extra-hosts hosts-service-type (load-hosts-entries))
...
%desktop-services)))
```
To make this work, I have my additional hosts entries in a file called
"etcfiles/extra-hosts" relative to the location of my `system.scm` file
(which contains the `operating-system` declaration above).
That file looks like so:
```
# Section Comment 1
10.1.30.1 name1 # Maybe a comment for myself
10.1.30.2 name2
10.1.30.3 name3
10.1.30.4 name4 # Another comment
# Section Comment 2
10.6.1.1 name5
10.6.1.2 name6 # And yet another comment
10.6.1.3 name7
10.6.1.4 name8
```
This is, of course, the regular /etc/hosts format. I just leave out the
127.0.0.1 and ::1 entries for localhost since Guix adds those
automatically.
Also, please note that the Guix info pages are incorrect for
`hosts-service-type` and `host`. The docs say they are exported by `(gnu
services)`, but they are actually located in `(gnu services base)`. It
would be great if one of the manual maintainers could fix this mistake
as it was one of the trickiest things I had to figure out to make this
code work.
Thanks and happy hacking!
Gary
--
GPG Key ID: C4FBEDBD
Use `gpg --search-keys tracker@disroot.org' to find me
Protect yourself from surveillance: https://emailselfdefense.fsf.org
=======================================================================
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
Why is HTML email a security nightmare? See https://useplaintext.email/
Please avoid sending me MS-Office attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
next prev parent reply other threads:[~2023-02-21 15:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 22:40 Examples of local-host-entries or hosts-service-type? Sergiu Ivanov
2023-02-10 23:37 ` Bruno Victal
2023-02-11 11:46 ` Remco van 't Veer
2023-02-13 10:49 ` Sergiu Ivanov
2023-02-14 9:34 ` Remco van 't Veer
2023-02-21 15:33 ` Gary Johnson [this message]
2023-02-26 18:33 ` Sergiu Ivanov
2023-02-21 16:45 ` Bruno Victal
2023-02-26 18:05 ` Sergiu Ivanov
2023-02-27 6:23 ` Remco van 't Veer
2023-03-02 2:41 ` Bruno Victal
2023-03-02 8:47 ` Remco van 't Veer
2023-03-03 14:00 ` Bruno Victal
2023-03-03 16:16 ` Remco van 't Veer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874jrfrpa1.fsf@disroot.org \
--to=lambdatronic@disroot.org \
--cc=help-guix@gnu.org \
--cc=remco@remworks.net \
--cc=sivanov@colimite.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.