From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id +Cm7Dm8JvV9lTAAA0tVLHw (envelope-from ) for ; Tue, 24 Nov 2020 13:23:59 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id kIqjCm8JvV+4BwAAB5/wlQ (envelope-from ) for ; Tue, 24 Nov 2020 13:23:59 +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 D8BE69402C8 for ; Tue, 24 Nov 2020 13:23:58 +0000 (UTC) Received: from localhost ([::1]:34866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khYIX-0004Nx-SP for larch@yhetil.org; Tue, 24 Nov 2020 08:23:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khYHf-00049j-OH for guix-patches@gnu.org; Tue, 24 Nov 2020 08:23:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khYHe-0007A4-VO for guix-patches@gnu.org; Tue, 24 Nov 2020 08:23:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1khYHe-0007r8-S3 for guix-patches@gnu.org; Tue, 24 Nov 2020 08:23:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44800] [PATCH v2 2/3] publish: Add avahi support. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 24 Nov 2020 13:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44800 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44800@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 44800-submit@debbugs.gnu.org id=B44800.160622415330120 (code B ref 44800); Tue, 24 Nov 2020 13:23:02 +0000 Received: (at 44800) by debbugs.gnu.org; 24 Nov 2020 13:22:33 +0000 Received: from localhost ([127.0.0.1]:58230 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1khYHB-0007pj-Ed for submit@debbugs.gnu.org; Tue, 24 Nov 2020 08:22:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33100) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1khYHA-0007pR-7B for 44800@debbugs.gnu.org; Tue, 24 Nov 2020 08:22:32 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:42956) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khYH5-0006xg-1o for 44800@debbugs.gnu.org; Tue, 24 Nov 2020 08:22:27 -0500 Received: from [2a01:e0a:19b:d9a0:3c14:dca1:bc4:a96f] (port=50234 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1khYGr-0003Tw-4d; Tue, 24 Nov 2020 08:22:15 -0500 From: Mathieu Othacehe Date: Tue, 24 Nov 2020 14:21:44 +0100 Message-Id: <20201124132145.217751-3-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201124132145.217751-1-othacehe@gnu.org> References: <20201124132145.217751-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: IbHPN/oDrtWa * guix/scripts/publish.scm (%options): Add "--enable-avahi" option. (show-help): Document it. (service-name): New procedure, (publish-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". * gnu/services/base.scm (): Add "enable-avahi?" field. (guix-publish-shepherd-service): Honor it. --- doc/guix.texi | 4 ++++ gnu/services/base.scm | 8 +++++++- guix/scripts/publish.scm | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index e9cf25fc90..f8efc34310 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12170,6 +12170,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/gnu/services/base.scm b/gnu/services/base.scm index 029df5ac16..87c247bdf1 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -1743,6 +1743,8 @@ proxy of 'guix-daemon'...~%") (default 80)) (host guix-publish-configuration-host ;string (default "localhost")) + (enable-avahi? guix-publish-enable-avahi? ;boolean + (default #f)) (compression guix-publish-configuration-compression (thunked) (default (default-compression this-record @@ -1789,7 +1791,8 @@ raise a deprecation warning if the 'compression-level' field was used." lst)))) (match-record config - (guix port host nar-path cache workers ttl cache-bypass-threshold) + (guix port host nar-path cache workers ttl cache-bypass-threshold + enable-avahi?) (list (shepherd-service (provision '(guix-publish)) (requirement '(guix-daemon)) @@ -1800,6 +1803,9 @@ raise a deprecation warning if the 'compression-level' field was used." #$@(config->compression-options config) (string-append "--nar-path=" #$nar-path) (string-append "--listen=" #$host) + #$@(if enable-avahi? + #~("--enable-avahi") + #~()) #$@(if workers #~((string-append "--workers=" #$(number->string diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 2a2185e2b9..d2bb7ae982 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -42,6 +42,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) @@ -70,6 +71,7 @@ signed-string open-server-socket + publish-service-type run-publish-server guix-publish)) @@ -83,6 +85,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_ " @@ -157,6 +161,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))) @@ -1069,11 +1076,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 publish-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 publish-service-type + #:port port)) + (run-server (make-request-handler store #:cache cache #:pool pool @@ -1119,6 +1140,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)) @@ -1179,6 +1201,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