services: Add block-facebook-hosts-service-type.
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. Signed-off-by: Ludovic Courtès <ludo@gnu.org>master
parent
802ea1f3a4
commit
b0e18601db
|
@ -20998,42 +20998,14 @@ Logging level.
|
||||||
@end table
|
@end table
|
||||||
@end deftp
|
@end deftp
|
||||||
|
|
||||||
@defvar %facebook-host-aliases
|
@defvar block-facebook-hosts-service-type
|
||||||
This variable contains a string for use in @file{/etc/hosts}
|
This service type adds a list of known Facebook hosts to the
|
||||||
(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
|
@file{/etc/hosts} file.
|
||||||
line contains a entry that maps a known server name of the Facebook
|
(@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
|
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 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
|
This mechanism can prevent programs running locally, such as Web
|
||||||
browsers, from accessing Facebook.
|
browsers, from accessing Facebook.
|
||||||
@end defvar
|
@end defvar
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
|
;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
|
||||||
;;; Copyright © 2022, 2023 Andrew Tropin <andrew@trop.in>
|
;;; Copyright © 2022, 2023 Andrew Tropin <andrew@trop.in>
|
||||||
;;; Copyright © 2023 Declan Tsien <declantsien@riseup.net>
|
;;; Copyright © 2023 Declan Tsien <declantsien@riseup.net>
|
||||||
|
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -80,7 +81,9 @@
|
||||||
#:use-module (json)
|
#:use-module (json)
|
||||||
#:re-export (static-networking-service
|
#:re-export (static-networking-service
|
||||||
static-networking-service-type)
|
static-networking-service-type)
|
||||||
#:export (%facebook-host-aliases
|
#:export (%facebook-host-aliases ;deprecated
|
||||||
|
block-facebook-hosts-service-type
|
||||||
|
|
||||||
dhcp-client-service-type
|
dhcp-client-service-type
|
||||||
dhcp-client-configuration
|
dhcp-client-configuration
|
||||||
dhcp-client-configuration?
|
dhcp-client-configuration?
|
||||||
|
@ -235,39 +238,36 @@
|
||||||
;;;
|
;;;
|
||||||
;;; Code:
|
;;; 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
|
;; This is the list of known Facebook hosts to be added to /etc/hosts if you
|
||||||
;; are to block it.
|
;; are to block it.
|
||||||
"\
|
(let ((domains '("facebook.com" "www.facebook.com"
|
||||||
# Block Facebook IPv4.
|
"login.facebook.com" "www.login.facebook.com"
|
||||||
127.0.0.1 www.facebook.com
|
"fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com"
|
||||||
127.0.0.1 facebook.com
|
"static.ak.fbcdn.net" "static.ak.connect.facebook.com"
|
||||||
127.0.0.1 login.facebook.com
|
"connect.facebook.net" "www.connect.facebook.net"
|
||||||
127.0.0.1 www.login.facebook.com
|
"apps.facebook.com")))
|
||||||
127.0.0.1 fbcdn.net
|
(append-map (lambda (name)
|
||||||
127.0.0.1 www.fbcdn.net
|
(map (lambda (addr)
|
||||||
127.0.0.1 fbcdn.com
|
(host addr name))
|
||||||
127.0.0.1 www.fbcdn.com
|
(list "127.0.0.1" "::1"))) domains)))
|
||||||
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.
|
(define-deprecated %facebook-host-aliases
|
||||||
fe80::1%lo0 facebook.com
|
block-facebook-hosts-service-type
|
||||||
fe80::1%lo0 login.facebook.com
|
(string-join
|
||||||
fe80::1%lo0 www.login.facebook.com
|
(map (lambda (x)
|
||||||
fe80::1%lo0 fbcdn.net
|
(string-append (host-address x) "\t"
|
||||||
fe80::1%lo0 www.fbcdn.net
|
(host-canonical-name x) "\n"))
|
||||||
fe80::1%lo0 fbcdn.com
|
facebook-host-aliases)))
|
||||||
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")
|
|
||||||
|
|
||||||
|
(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>
|
(define-record-type* <dhcp-client-configuration>
|
||||||
dhcp-client-configuration make-dhcp-client-configuration
|
dhcp-client-configuration make-dhcp-client-configuration
|
||||||
|
|
Reference in New Issue