services: Use match-record.

* rosenthal/services/bittorrent.scm (qbittorrent-configuration)[qbittorrent]:
Change field type to file-like.
(qbittorrent-activation,qbittorrent-shepherd-service): Use match-record-lambda
* rosenthal/services/child-error.scm (miniflux-configuration)[miniflux],
(cloudflare-tunnel-configuration)[cloudflared]: Change field type to file-like
(clash-activation,clash-shepherd-service,cloudflare-tunnel-shepherd-service)
(cloudflare-warp-shepherd-service,miniflux-shepherd-service)
(home-wakapi-shepherd-service,home-socks2http-shepherd-service): Use
match-record-lambda.
* rosenthal/services/dns.scm (smartdns-configuration)[smartdns]: Change field
type to file-like.
(smartdns-shepherd-service): Use match-record-lambda.
* rosenthal/services/networking.scm (iwd-configuration)[iwd]: Change field
type to file-like.
(iwd-shepherd-service,iwd-etc-service): Use match-record-lambda.
pull/1/head
Hilton Chain 1 year ago
parent b1fc64d837
commit 060204c29e
No known key found for this signature in database
GPG Key ID: ACC66D09CA528292
  1. 30
      rosenthal/services/bittorrent.scm
  2. 188
      rosenthal/services/child-error.scm
  3. 15
      rosenthal/services/dns.scm
  4. 62
      rosenthal/services/networking.scm

@ -4,7 +4,6 @@
(define-module (rosenthal services bittorrent) (define-module (rosenthal services bittorrent)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records) #:use-module (guix records)
#:use-module (gnu packages admin) #:use-module (gnu packages admin)
#:use-module (gnu packages bittorrent) #:use-module (gnu packages bittorrent)
@ -20,9 +19,9 @@
;; ;;
(define-configuration/no-serialization qbittorrent-configuration (define-configuration qbittorrent-configuration
(qbittorrent (qbittorrent
(package qbittorrent-nox) (file-like qbittorrent-nox)
"The qBittorrent package to use, we need @command{qbittorrent-nox}.") "The qBittorrent package to use, we need @command{qbittorrent-nox}.")
(log-file (log-file
(string "/var/log/qbittorrent.log") (string "/var/log/qbittorrent.log")
@ -35,7 +34,8 @@
"Directory to store configuration files in.") "Directory to store configuration files in.")
(extra-options (extra-options
(list-of-strings '()) (list-of-strings '())
"List of extra options.")) "List of extra options.")
(no-serialization))
(define %qbittorrent-accounts (define %qbittorrent-accounts
(list (user-group (name "qbittorrent") (system? #t)) (list (user-group (name "qbittorrent") (system? #t))
@ -47,17 +47,19 @@
(home-directory "/var/empty") (home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin"))))) (shell (file-append shadow "/sbin/nologin")))))
(define (qbittorrent-activation config) (define qbittorrent-activation
#~(begin (match-record-lambda <qbittorrent-configuration>
(use-modules (guix build utils)) (qbittorrent log-file webui-port profile-directory extra-options)
(let ((profile-directory #$(qbittorrent-configuration-profile-directory config)) #~(begin
(user (getpwnam "qbittorrent"))) (use-modules (guix build utils))
(mkdir-p profile-directory) (let ((profile-directory #$profile-directory)
(chown profile-directory (passwd:uid user) (passwd:gid user))))) (user (getpwnam "qbittorrent")))
(mkdir-p profile-directory)
(chown profile-directory (passwd:uid user) (passwd:gid user))))))
(define (qbittorrent-shepherd-service config) (define qbittorrent-shepherd-service
(match-record config <qbittorrent-configuration> (match-record-lambda <qbittorrent-configuration>
(qbittorrent log-file webui-port profile-directory extra-options) (qbittorrent log-file webui-port profile-directory extra-options)
(list (shepherd-service (list (shepherd-service
(documentation "Run qbittorrent.") (documentation "Run qbittorrent.")
(provision '(qbittorrent)) (provision '(qbittorrent))

@ -3,10 +3,8 @@
;; SPDX-License-Identifier: GPL-3.0-or-later ;; SPDX-License-Identifier: GPL-3.0-or-later
(define-module (rosenthal services child-error) (define-module (rosenthal services child-error)
#:use-module (ice-9 match)
#:use-module (guix records) #:use-module (guix records)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (gnu home services) #:use-module (gnu home services)
#:use-module (gnu home services shepherd) #:use-module (gnu home services shepherd)
#:use-module (gnu packages admin) #:use-module (gnu packages admin)
@ -37,16 +35,12 @@
home-socks2http-configuration home-socks2http-configuration
home-socks2http-service-type)) home-socks2http-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.
;; ;;
;; Clash ;; Clash
;; ;;
(define-configuration/no-serialization clash-configuration (define-configuration clash-configuration
(clash (clash
(file-like clash-bin) (file-like clash-bin)
"The clash package.") "The clash package.")
@ -58,7 +52,8 @@
"Where to store data.") "Where to store data.")
(config (config
(file-like (plain-file "empty" "")) (file-like (plain-file "empty" ""))
"Clash configuration file.")) "Clash configuration file.")
(no-serialization))
(define %clash-accounts (define %clash-accounts
(list (user-group (name "clash") (system? #t)) (list (user-group (name "clash") (system? #t))
@ -70,32 +65,32 @@
(shell (file-append shadow "/sbin/nologin"))))) (shell (file-append shadow "/sbin/nologin")))))
(define clash-activation (define clash-activation
(match-lambda (match-record-lambda <clash-configuration>
(($ <clash-configuration> clash log-file data-directory config) (clash log-file data-directory config)
#~(begin #~(begin
(use-modules (guix build utils)) (use-modules (guix build utils))
(let ((config-dest (string-append #$data-directory "/config.yaml")) (let ((config-dest (string-append #$data-directory "/config.yaml"))
(user (getpwnam "clash"))) (user (getpwnam "clash")))
(mkdir-p #$data-directory) (mkdir-p #$data-directory)
(chown #$data-directory (passwd:uid user) (passwd:gid user)) (chown #$data-directory (passwd:uid user) (passwd:gid user))
(if (file-exists? config-dest) (if (file-exists? config-dest)
(delete-file config-dest)) (delete-file config-dest))
(symlink #$config config-dest)))))) (symlink #$config config-dest)))))
(define clash-shepherd-service (define clash-shepherd-service
(match-lambda (match-record-lambda <clash-configuration>
(($ <clash-configuration> clash log-file data-directory config) (clash log-file data-directory config)
(list (shepherd-service (list (shepherd-service
(documentation "Run clash.") (documentation "Run clash.")
(provision '(clash)) (provision '(clash))
(requirement '(loopback networking)) (requirement '(loopback networking))
(start #~(make-forkexec-constructor (start #~(make-forkexec-constructor
(list #$(file-append clash "/bin/clash") (list #$(file-append clash "/bin/clash")
"-d" #$data-directory) "-d" #$data-directory)
#:user "clash" #:user "clash"
#:group "clash" #:group "clash"
#:log-file #$log-file)) #:log-file #$log-file))
(stop #~(make-kill-destructor))))))) (stop #~(make-kill-destructor))))))
(define clash-service-type (define clash-service-type
(service-type (service-type
@ -110,16 +105,15 @@
(default-value (clash-configuration)) (default-value (clash-configuration))
(description "Run Clash."))) (description "Run Clash.")))
;; ;;
;; Cloudflare Tunnel ;; Cloudflare Tunnel
;; ;;
(define-configuration/no-serialization cloudflare-tunnel-configuration (define-configuration cloudflare-tunnel-configuration
(cloudflared (cloudflared
(package cloudflared) (file-like cloudflared)
"The cloudflared executable.") "The cloudflared executable.")
;; Tunnel options ;; Tunnel options
@ -151,41 +145,39 @@ headers. This can expose sensitive information in your logs.")
"Create an experimental post-quantum secure tunnel.") "Create an experimental post-quantum secure tunnel.")
(extra-options (extra-options
(list-of-strings '()) (list-of-strings '())
"List of extra options.")) "List of extra options.")
(no-serialization))
(define cloudflare-tunnel-shepherd-service (define cloudflare-tunnel-shepherd-service
(match-lambda (match-record-lambda <cloudflare-tunnel-configuration>
(($ <cloudflare-tunnel-configuration> cloudflared metrics (cloudflared metrics log-level log-file extra-tunnel-options
log-level log-file token http2-origin? post-quantum? extra-options)
extra-tunnel-options (list (shepherd-service
token http2-origin? post-quantum? (documentation "Run cloudflared.")
extra-options) (provision '(cloudflare-tunnel))
(list (shepherd-service (requirement '(loopback networking))
(documentation "Run cloudflared.") (start #~(make-forkexec-constructor
(provision '(cloudflare-tunnel)) (list #$(file-append cloudflared "/bin/cloudflared")
(requirement '(loopback networking)) "tunnel"
(start #~(make-forkexec-constructor "--no-autoupdate"
(list #$(file-append cloudflared "/bin/cloudflared") "--metrics" #$metrics
"tunnel" "--loglevel" #$log-level
"--no-autoupdate" #$@extra-tunnel-options
"--metrics" #$metrics
"--loglevel" #$log-level "run"
#$@extra-tunnel-options #$@(if http2-origin?
'("--http2-origin")
"run" '())
#$@(if http2-origin? #$@(if post-quantum?
'("--http2-origin") '("--post-quantum")
'()) '())
#$@(if post-quantum? #$@extra-options)
'("--post-quantum") #:user "nobody"
'()) #:group "nogroup"
#$@extra-options) #:log-file #$log-file
#:user "nobody" #:environment-variables
#:group "nogroup" (list (format #f "TUNNEL_TOKEN=~a" #$token))))
#:log-file #$log-file (stop #~(make-kill-destructor))))))
#:environment-variables
(list (format #f "TUNNEL_TOKEN=~a" #$token))))
(stop #~(make-kill-destructor)))))))
(define cloudflare-tunnel-service-type (define cloudflare-tunnel-service-type
(service-type (service-type
@ -202,14 +194,15 @@ headers. This can expose sensitive information in your logs.")
;; ;;
(define-configuration/no-serialization cloudflare-warp-configuration (define-configuration cloudflare-warp-configuration
(cloudflare-warp (cloudflare-warp
(file-like cloudflare-warp-bin) (file-like cloudflare-warp-bin)
"The Cloudflare Warp package.")) "The Cloudflare Warp package.")
(no-serialization))
(define (cloudflare-warp-shepherd-service config) (define cloudflare-warp-shepherd-service
(match-record config <cloudflare-warp-configuration> (match-record-lambda <cloudflare-warp-configuration>
(cloudflare-warp) (cloudflare-warp)
(list (shepherd-service (list (shepherd-service
(documentation "Run warp-svc.") (documentation "Run warp-svc.")
(provision '(cloudflare-warp)) (provision '(cloudflare-warp))
@ -234,16 +227,18 @@ headers. This can expose sensitive information in your logs.")
;; Miniflux ;; Miniflux
;; ;;
(define-configuration/no-serialization miniflux-configuration
(define-configuration miniflux-configuration
(miniflux (miniflux
(package miniflux) (file-like miniflux)
"The miniflux package.") "The miniflux package.")
(log-file (log-file
(string "/var/log/miniflux.log") (string "/var/log/miniflux.log")
"Where the logs go.") "Where the logs go.")
(options (options
(alist '()) (alist '())
"Association list of miniflux configuration options.")) "Association list of miniflux configuration options.")
(no-serialization))
(define %miniflux-accounts (define %miniflux-accounts
(list (user-account (list (user-account
@ -258,9 +253,9 @@ headers. This can expose sensitive information in your logs.")
(name "miniflux") (name "miniflux")
(create-database? #t)))) (create-database? #t))))
(define (miniflux-shepherd-service config) (define miniflux-shepherd-service
(match-record config <miniflux-configuration> (match-record-lambda <miniflux-configuration>
(miniflux log-file options) (miniflux log-file options)
(let ((config-file (mixed-text-file (let ((config-file (mixed-text-file
"miniflux.conf" "miniflux.conf"
(apply string-append (apply string-append
@ -298,27 +293,28 @@ headers. This can expose sensitive information in your logs.")
;; ;;
(define-configuration/no-serialization home-wakapi-configuration (define-configuration home-wakapi-configuration
(wakapi (wakapi
(file-like wakapi-bin) (file-like wakapi-bin)
"The wakapi package.") "The wakapi package.")
(config (config
(yaml-config '()) (yaml-config '())
"Association list of Wakapi configurations.")) "Association list of Wakapi configurations.")
(no-serialization))
(define home-wakapi-shepherd-service (define home-wakapi-shepherd-service
(match-lambda (match-record-lambda <home-wakapi-configuration>
(($ <home-wakapi-configuration> wakapi config) (wakapi config)
(let ((config-file (mixed-text-file (let ((config-file (mixed-text-file
"wakapi.yaml" "wakapi.yaml"
#~(string-append #$@(serialize-yaml-config config) "\n")))) #~(string-append #$@(serialize-yaml-config config) "\n"))))
(list (shepherd-service (list (shepherd-service
(documentation "Run wakapi.") (documentation "Run wakapi.")
(provision '(wakapi)) (provision '(wakapi))
(start #~(make-forkexec-constructor (start #~(make-forkexec-constructor
(list #$(file-append wakapi "/bin/wakapi") (list #$(file-append wakapi "/bin/wakapi")
"-config" #$config-file))) "-config" #$config-file)))
(stop #~(make-kill-destructor)))))))) (stop #~(make-kill-destructor)))))))
(define home-wakapi-service-type (define home-wakapi-service-type
(service-type (service-type
@ -347,9 +343,9 @@ headers. This can expose sensitive information in your logs.")
"HTTP proxy address to serve.") "HTTP proxy address to serve.")
(no-serialization)) (no-serialization))
(define (home-socks2http-shepherd-service config) (define home-socks2http-shepherd-service
(match-record config <home-socks2http-configuration> (match-record-lambda <home-socks2http-configuration>
(socks2http socks-address http-address) (socks2http socks-address http-address)
(list (shepherd-service (list (shepherd-service
(documentation "Run socks2http.") (documentation "Run socks2http.")
(provision '(socks2http)) (provision '(socks2http))

@ -4,7 +4,6 @@
(define-module (rosenthal services dns) (define-module (rosenthal services dns)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records) #:use-module (guix records)
#:use-module (gnu services) #:use-module (gnu services)
#:use-module (gnu services configuration) #:use-module (gnu services configuration)
@ -17,17 +16,19 @@
;; Smartdns ;; Smartdns
;; ;;
(define-configuration/no-serialization smartdns-configuration
(define-configuration smartdns-configuration
(smartdns (smartdns
(package smartdns) (file-like smartdns)
"The Smartdns package.") "The Smartdns package.")
(config-file (config-file
(file-like (plain-file "empty" "")) (file-like (plain-file "empty" ""))
"Configuration file for Smartdns.")) "Configuration file for Smartdns.")
(no-serialization))
(define (smartdns-shepherd-service config) (define smartdns-shepherd-service
(match-record config <smartdns-configuration> (match-record-lambda <smartdns-configuration>
(smartdns config-file) (smartdns config-file)
(list (shepherd-service (list (shepherd-service
(documentation "Run smartdns.") (documentation "Run smartdns.")
(provision '(smartdns dns)) (provision '(smartdns dns))

@ -3,10 +3,9 @@
;; SPDX-License-Identifier: BSD-3-Clause ;; SPDX-License-Identifier: BSD-3-Clause
(define-module (rosenthal services networking) (define-module (rosenthal services networking)
#:use-module (ice-9 match) #:use-module ((guix import utils) #:select (flatten))
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix import utils) #:use-module (guix records)
#:use-module (guix packages)
#:use-module (gnu packages dns) #:use-module (gnu packages dns)
#:use-module (gnu packages base) #:use-module (gnu packages base)
#:use-module (gnu packages networking) #:use-module (gnu packages networking)
@ -15,10 +14,7 @@
#:use-module (gnu services base) #:use-module (gnu services base)
#:use-module (gnu services shepherd) #:use-module (gnu services shepherd)
#:use-module (gnu services configuration) #:use-module (gnu services configuration)
#:use-module ((rosenthal utils home-services-utils) #:use-module (rosenthal utils home-services-utils)
#:select (ini-config?
maybe-object->string
generic-serialize-ini-config))
#:export (iwd-service-type #:export (iwd-service-type
iwd-configuration)) iwd-configuration))
@ -40,39 +36,41 @@
#:serialize-field serialize-field #:serialize-field serialize-field
#:fields config)) #:fields config))
(define-configuration/no-serialization iwd-configuration (define-configuration iwd-configuration
(iwd (iwd
(package iwd) (file-like iwd)
"The iwd package.") "The iwd package.")
(config (config
(ini-config '()) (ini-config '())
"Association list of iwd configurations.")) "Association list of iwd configurations.")
(no-serialization))
(define iwd-shepherd-service (define iwd-shepherd-service
(match-lambda (match-record-lambda <iwd-configuration>
(($ <iwd-configuration> iwd _) (iwd config)
(let ((environment #~(list (string-append (let ((environment
"PATH=" #~(list (string-append
(string-append #$openresolv "/sbin") "PATH=" (string-join
":" (list (file-append openresolv "/sbin")
(string-append #$coreutils "/bin"))))) (file-append coreutils "/bin"))
(list (shepherd-service ":")))))
(documentation "Run iwd") (list (shepherd-service
(provision '(iwd networking)) (documentation "Run iwd")
(requirement '(user-processes dbus-system loopback)) (provision '(iwd networking))
(start #~(make-forkexec-constructor (requirement '(user-processes dbus-system loopback))
(list (string-append #$iwd "/libexec/iwd")) (start #~(make-forkexec-constructor
#:log-file "/var/log/iwd.log" (list (string-append #$iwd "/libexec/iwd"))
#:environment-variables #$environment)) #:log-file "/var/log/iwd.log"
(stop #~(make-kill-destructor)))))))) #:environment-variables #$environment))
(stop #~(make-kill-destructor)))))))
(define iwd-etc-service (define iwd-etc-service
(match-lambda (match-record-lambda <iwd-configuration>
(($ <iwd-configuration> _ config) (iwd config)
`(("iwd/main.conf" `(("iwd/main.conf"
,(apply mixed-text-file ,(apply mixed-text-file
"main.conf" "main.conf"
(serialize-ini-config config))))))) (serialize-ini-config config))))))
(define add-iwd-package (compose list iwd-configuration-iwd)) (define add-iwd-package (compose list iwd-configuration-iwd))

Loading…
Cancel
Save