From 2b8d1603a7b9479ab3c92154882a36d175bf6957 Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Fri, 25 Nov 2022 19:15:14 +0800 Subject: [PATCH] services: Add cloudflare-tunnel-service-type. rosenthal/services/child-error.scm: New file. (): New data type. (cloudflare-tunnel-service-type): New variable. --- rosenthal/services/child-error.scm | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 rosenthal/services/child-error.scm diff --git a/rosenthal/services/child-error.scm b/rosenthal/services/child-error.scm new file mode 100644 index 0000000..8888d78 --- /dev/null +++ b/rosenthal/services/child-error.scm @@ -0,0 +1,84 @@ +;; SPDX-FileCopyrightText: 2022 Hilton Chain +;; +;; SPDX-License-Identifier: GPL-3.0-or-later + +(define-module (rosenthal services child-error) + #:use-module (ice-9 match) + #:use-module (guix records) + #:use-module (guix gexp) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:use-module (gnu services) + #:use-module (gnu services configuration) + #:use-module (gnu services shepherd) + #:use-module (rosenthal utils home-services-utils) + #:export (cloudflare-tunnel-configuration + cloudflare-tunnel-service-type)) + +;; Child-error: services for packages not available in Guix, currently this +;; means some Go and Rust apps I build locally but don't want to package. + + + +;; +;; Cloudflare Tunnel +;; + + +(define-record-type* + cloudflare-tunnel-configuration make-cloudflare-tunnel-configuration + cloudflare-tunnel-configuration? + (cloudflared cloudflare-tunnel-configuration-cloudflared ;string + (default "/bin/cloudflared")) + ;; Tunnel command options + (metrics cloudflare-tunnel-configuration-metrics ;string + (default "localhost:")) + (log-level cloudflare-tunnel-configuration-log-level ;string + (default "info")) + (log-file cloudflare-tunnel-configuration-log-file ;string + (default "/var/log/cloudflared.log")) + ;; Subcommand options + (token cloudflare-tunnel-configuration-token ;string + (default #f)) + (http2-origin? cloudflare-tunnel-configuration-http2-origin? ;boolean + (default #f)) + (post-quantum? cloudflare-tunnel-configuration-post-quantum? ;boolean + (default #f)) + (extra-options cloudflare-tunnel-configuration-extra-options ;list of string + (default '()))) + +(define cloudflare-tunnel-shepherd-service + (match-lambda + (($ cloudflared metrics + log-level log-file + token http2-origin? post-quantum? + extra-options) + (let ((tunnel-options + (list "--no-autoupdate" "--metrics" metrics "--loglevel" log-level))) + (list (shepherd-service + (documentation "Run cloudflared.") + (provision '(cloudflare-tunnel)) + (requirement '(loopback networking user-processes)) + (start #~(make-forkexec-constructor + (list #$cloudflared "tunnel" #$@tunnel-options "run" + "--token" #$token + #$@(if http2-origin? + '("--http2-origin") + '()) + #$@(if post-quantum? + '("--post-quantum") + '()) + #$@extra-options) + #:user "nobody" + #:group "nogroup" + #:log-file #$log-file)) + (stop #~(make-kill-destructor)))))))) + +(define cloudflare-tunnel-service-type + (service-type + (name 'cloudflare-tunnel) + (extensions + (list (service-extension shepherd-root-service-type + cloudflare-tunnel-shepherd-service))) + (default-value (cloudflare-tunnel-configuration)) + (description "Run cloudflared, the Cloudflare Tunnel daemon.")))