From patchwork Sun Nov 22 15:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 25285 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 4C12627BBF7; Sun, 22 Nov 2020 15:58:16 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3CA3627BBF9 for ; Sun, 22 Nov 2020 15:58:15 +0000 (GMT) Received: from localhost ([::1]:49074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgrkk-0001kh-G0 for patchwork@mira.cbaines.net; Sun, 22 Nov 2020 10:58:14 -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 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" X-getmail-retrieved-from-mailbox: Patches * 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