From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 0vLTMpiKul9dCwAA0tVLHw (envelope-from ) for ; Sun, 22 Nov 2020 15:58:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id p3/5LZiKul/XDAAAbx9fmQ (envelope-from ) for ; Sun, 22 Nov 2020 15:58:16 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 754CD940367 for ; Sun, 22 Nov 2020 15:58:16 +0000 (UTC) Received: from localhost ([::1]:49074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgrkl-0001kh-8J for larch@yhetil.org; Sun, 22 Nov 2020 10:58:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgrkZ-0001k3-8U for guix-patches@gnu.org; Sun, 22 Nov 2020 10:58:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kgrkZ-0002HI-1R for guix-patches@gnu.org; Sun, 22 Nov 2020 10:58:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kgrkZ-00064G-1C for guix-patches@gnu.org; Sun, 22 Nov 2020 10:58:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44801] [PATCH 2/2] publish: Add avahi support. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 22 Nov 2020 15:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44801 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44801@debbugs.gnu.org Cc: Mathieu Othacehe X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.160606064623254 (code B ref -1); Sun, 22 Nov 2020 15:58:02 +0000 Received: (at submit) by debbugs.gnu.org; 22 Nov 2020 15:57:26 +0000 Received: from localhost ([127.0.0.1]:48116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kgrjy-00062y-8F for submit@debbugs.gnu.org; Sun, 22 Nov 2020 10:57:26 -0500 Received: from lists.gnu.org ([209.51.188.17]:48484) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kgrjv-00062d-49 for submit@debbugs.gnu.org; Sun, 22 Nov 2020 10:57:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgrju-0001hF-Rc for guix-patches@gnu.org; Sun, 22 Nov 2020 10:57:22 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46126) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgrju-000241-Kt for guix-patches@gnu.org; Sun, 22 Nov 2020 10:57:22 -0500 Received: from [2a01:e0a:19b:d9a0:f0c7:1dab:64ad:1a4a] (port=49596 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kgrjr-0006Iv-AG; Sun, 22 Nov 2020 10:57:19 -0500 From: Mathieu Othacehe Date: Sun, 22 Nov 2020 16:56:59 +0100 Message-Id: <20201122155659.67235-3-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201122155659.67235-1-othacehe@gnu.org> References: <20201122155659.67235-1-othacehe@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.49 X-TUID: PIk9lMMP+ypu * guix/scripts/publish.scm (%options): Add "--enable-avahi" option. (show-help): Document it. (service-name): New procedure, (service-type): new variable. (run-publish-server): Add "avahi?" and "port" parameters. Use them to publish the server using Avahi. (guix-publish): Pass the "avahi?" option to "run-publish-server". --- doc/guix.texi | 4 ++++ guix/scripts/publish.scm | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index e2361c25e3..cfbf495cbc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12151,6 +12151,10 @@ The signing key pair must be generated before @command{guix publish} is launched, using @command{guix archive --generate-key} (@pxref{Invoking guix archive}). +When the @option{--enable-avahi} option is passed, the publish server is +advertised on the local network as an Avahi service, using Guile-Avahi +bindings. + The general syntax is: @example diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index a12abf5b4d..34fcb682b5 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -41,6 +41,7 @@ #:use-module (web server) #:use-module (web uri) #:autoload (sxml simple) (sxml->xml) + #:use-module (guix avahi) #:use-module (guix base32) #:use-module (guix base64) #:use-module (guix config) @@ -82,6 +83,8 @@ Publish ~a over HTTP.\n") %store-directory) (display (G_ " -u, --user=USER change privileges to USER as soon as possible")) (display (G_ " + -a, --enable-avahi enable Avahi based discovery")) + (display (G_ " -C, --compression[=METHOD:LEVEL] compress archives with METHOD at LEVEL")) (display (G_ " @@ -156,6 +159,9 @@ usage." (option '(#\V "version") #f #f (lambda _ (show-version-and-exit "guix publish"))) + (option '(#\a "enable-avahi") #f #f + (lambda (opt name arg result) + (alist-cons 'enable-avahi? #t result))) (option '(#\u "user") #t #f (lambda (opt name arg result) (alist-cons 'user arg result))) @@ -1043,11 +1049,25 @@ methods, return the applicable compression." (x (not-found request))) (not-found request)))) +(define (service-name) + "Return the Avahi service name of the server." + (string-append "guix-publish-" (gethostname))) + +(define service-type + ;; Return the Avahi service type of the server. + "_guix_publish._tcp") + (define* (run-publish-server socket store #:key + avahi? port (compressions (list %no-compression)) (nar-path "nar") narinfo-ttl cache pool) + (when avahi? + (avahi-publish-service-thread (service-name) + #:type service-type + #:port port)) + (run-server (make-request-handler store #:cache cache #:pool pool @@ -1092,6 +1112,7 @@ methods, return the applicable compression." (lambda (arg result) (leave (G_ "~A: extraneous argument~%") arg)) %default-options)) + (avahi? (assoc-ref opts 'enable-avahi?)) (user (assoc-ref opts 'user)) (port (assoc-ref opts 'port)) (ttl (assoc-ref opts 'narinfo-ttl)) @@ -1152,6 +1173,8 @@ consider using the '--user' option!~%"))) (with-store store (run-publish-server socket store + #:avahi? avahi? + #:port port #:cache cache #:pool (and cache (make-pool workers #:thread-name -- 2.29.2