From patchwork Wed Jan 18 16:54:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bruno Victal X-Patchwork-Id: 46271 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id AD1B727BBEB; Wed, 18 Jan 2023 16:58:27 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 64D8D27BBE9 for ; Wed, 18 Jan 2023 16:58:25 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIBlQ-0002Rp-T0; Wed, 18 Jan 2023 11:58:16 -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 1pIBlN-0002Qm-Ng for guix-patches@gnu.org; Wed, 18 Jan 2023 11:58:13 -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 1pIBlD-0003mG-0I for guix-patches@gnu.org; Wed, 18 Jan 2023 11:58:12 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pIBlC-0004lg-S5 for guix-patches@gnu.org; Wed, 18 Jan 2023 11:58:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60735] [PATCH v2 3/3] services: Add block-facebook-hosts-service-type. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 18 Jan 2023 16:58: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: ludo@gnu.org, Bruno Victal Received: via spool by 60735-submit@debbugs.gnu.org id=B60735.167406104318271 (code B ref 60735); Wed, 18 Jan 2023 16:58:02 +0000 Received: (at 60735) by debbugs.gnu.org; 18 Jan 2023 16:57:23 +0000 Received: from localhost ([127.0.0.1]:41652 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkY-0004kc-G3 for submit@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:23 -0500 Received: from smtpm2.myservices.hosting ([185.26.105.233]:46266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pIBkU-0004kL-Ij for 60735@debbugs.gnu.org; Wed, 18 Jan 2023 11:57:19 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.172]) by smtpm2.myservices.hosting (Postfix) with ESMTP id E4CBC20CF2; Wed, 18 Jan 2023 17:57:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 96C908009A; Wed, 18 Jan 2023 17:57:17 +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 9Znsq_JJLYRI; Wed, 18 Jan 2023 17:57:14 +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 BCF2480099; Wed, 18 Jan 2023 17:57:13 +0100 (CET) From: Bruno Victal Date: Wed, 18 Jan 2023 16:54:14 +0000 Message-Id: <511996014cccd059f1d2ea701e5fe134ad2c4735.1674060851.git.mirai@makinata.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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. --- doc/guix.texi | 40 ++++------------------- gnu/services/networking.scm | 65 +++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 66 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index eb4c1a2dbb..da93cc613f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20996,45 +20996,17 @@ Networking Services @end table @end deftp -@defvr {Scheme Variable} %facebook-host-aliases -This variable contains a string for use in @file{/etc/hosts} -(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each -line contains a entry that maps a known server name of the Facebook +@defvar block-facebook-hosts-service-type +This service type adds a list of known Facebook hosts to the +@file{/etc/hosts} file. +(@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 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 browsers, from accessing Facebook. -@end defvr +@end defvar The @code{(gnu services avahi)} provides the following definition. diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 89ce16f6af..3e41e42da1 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2022, 2023 Andrew Tropin ;;; Copyright © 2023 Declan Tsien +;;; Copyright © 2023 Bruno Victal ;;; ;;; This file is part of GNU Guix. ;;; @@ -80,7 +81,9 @@ (define-module (gnu services networking) #:use-module (json) #:re-export (static-networking-service static-networking-service-type) - #:export (%facebook-host-aliases + #:export (%facebook-host-aliases ;deprecated + block-facebook-hosts-service-type + dhcp-client-service-type dhcp-client-configuration dhcp-client-configuration? @@ -235,39 +238,37 @@ (define-module (gnu services networking) ;;; ;;; 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 ;; are to block it. - "\ -# Block Facebook IPv4. -127.0.0.1 www.facebook.com -127.0.0.1 facebook.com -127.0.0.1 login.facebook.com -127.0.0.1 www.login.facebook.com -127.0.0.1 fbcdn.net -127.0.0.1 www.fbcdn.net -127.0.0.1 fbcdn.com -127.0.0.1 www.fbcdn.com -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. -fe80::1%lo0 facebook.com -fe80::1%lo0 login.facebook.com -fe80::1%lo0 www.login.facebook.com -fe80::1%lo0 fbcdn.net -fe80::1%lo0 www.fbcdn.net -fe80::1%lo0 fbcdn.com -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") - + (let ((domains '("facebook.com" "www.facebook.com" + "login.facebook.com" "www.login.facebook.com" + "fbcdn.net" "www.fbcdn.net" "fbcdn.com" "www.fbcdn.com" + "static.ak.fbcdn.net" "static.ak.connect.facebook.com" + "connect.facebook.net" "www.connect.facebook.net" + "apps.facebook.com"))) + (append-map (lambda (name) + (map (lambda (addr) + (host addr name)) + (list "127.0.0.1" "::1"))) domains))) + +(define-deprecated %facebook-host-aliases + block-facebook-hosts-service-type + (let (( (@ (gnu services) ))) + (string-join + (map (match-lambda + (($ address canonical-name) + (string-append address "\t" canonical-name "\n"))) + facebook-host-aliases)))) + +(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 make-dhcp-client-configuration