Compare commits

..

2 Commits

Author SHA1 Message Date
Hilton Chain
f58f1b0583
utils: Add toml-file.
* modules/rosenthal/utils/file.scm (toml-file): New procedure.
* modules/rosenthal/services/web.scm (conduit-shepherd, iocaine-etc)
(navidrome-shepherd-service): Use it.
2026-02-26 10:26:42 +08:00
Hilton Chain
19a9eaa029
rosenthal: Add guile-toml.
* modules/rosenthal/packages/patches/guile-toml-support-boolean.patch: New file.
* modules/rosenthal/packages/guile-xyz.scm (guile-toml): New variable.
2026-02-26 10:24:29 +08:00
4 changed files with 125 additions and 26 deletions

View File

@ -0,0 +1,47 @@
;;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Copyright © 2026 Hilton Chain <hako@ultrarare.space>
(define-module (rosenthal packages guile-xyz)
;; Utilities
#:use-module (guix gexp)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (rosenthal utils packages)
;; Guix origin methods
#:use-module (guix git-download)
;; Guix build systems
#:use-module (guix build-system guile)
;; Guix packages
#:use-module (gnu packages guile)
#:use-module (gnu packages guile-xyz))
(define-public guile-toml
(let ((commit "ecb24deb407ef76ef7cf7e9f0115060c98366a6b")
(revision "0"))
(package
(name "guile-toml")
(version (git-version "0.0.0" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/hylophile/guile-toml")
(commit commit)))
(file-name (git-file-name name version))
(sha256
(base32
"1iqxivxcb0dcjbd5ba3c0g3mj71b32qjxfdmljyv9r297yykfd02"))
(patches
(rosenthal-patches "guile-toml-support-boolean.patch"))))
(build-system guile-build-system)
(arguments
(list #:phases
#~(modify-phases %standard-phases
(add-after 'unpack 'avoid-test-installation
(lambda _
(delete-file-recursively "test"))))))
(native-inputs (list guile-3.0))
(propagated-inputs (list guile-json-4))
(home-page "https://github.com/hylophile/guile-toml")
(synopsis "TOML module for GNU Guile")
(description "")
(license license:gpl3+))))

View File

@ -0,0 +1,37 @@
From 2f7e3c6f46233f9c9159fac61ca4121fe342107f Mon Sep 17 00:00:00 2001
From: Hilton Chain <hako@ultrarare.space>
Date: Thu, 26 Feb 2026 09:57:51 +0800
Subject: [PATCH] builder: Support boolean value.
* toml/builder.scm (toml-build-boolean): New procedure.
(toml-build-value): Use it.
---
toml/builder.scm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/toml/builder.scm b/toml/builder.scm
index f6bdcea..3531c6f 100644
--- a/toml/builder.scm
+++ b/toml/builder.scm
@@ -74,6 +74,9 @@
(else (string c))))
(string->list s))))
+(define (toml-build-boolean b port)
+ (put-string port (if b "true" "false")))
+
(define (toml-build-string s port)
(define quote-type (if (or
(string-contains s "\\")
@@ -198,7 +201,7 @@
(scm port #:key (newline? #t) (inline? #f))
(cond
;; ((eq? scm null) (toml-build-null port))
- ;; ((boolean? scm) (toml-build-boolean scm port))
+ ((boolean? scm) (toml-build-boolean scm port))
;; ((symbol? scm) (toml-build-string (symbol->string scm) port))
;; TODO float (nan, inf)
--
2.52.0

View File

@ -185,7 +185,7 @@ reload its configuration file."))
(string "/var/lib/conduit")
"")
(config
file-like
gexp
"")
;; Account
(group-id
@ -235,6 +235,7 @@ reload its configuration file."))
(define conduit-shepherd
(match-record-lambda <conduit-configuration>
(conduit config auto-start? shepherd-provision shepherd-requirement)
(let ((config-file (toml-file "conduit.toml" config)))
(list (shepherd-service
(provision shepherd-provision)
(requirement `(networking user-processes ,@shepherd-requirement))
@ -245,10 +246,10 @@ reload its configuration file."))
#:group "conduit"
#:log-file "/var/log/conduit.log"
#:environment-variables
(list (string-append "CONDUIT_CONFIG=" #$config))))
(list (string-append "CONDUIT_CONFIG=" #$config-file))))
(stop #~(make-kill-destructor))
(actions
(list (shepherd-configuration-action config)))))))
(list (shepherd-configuration-action config-file))))))))
(define conduit-service-type
(service-type
@ -384,7 +385,7 @@ reload its configuration file."))
(file-like iocaine)
"")
(config
file-object
gexp
"")
(log-file
(string "/var/log/iocaine.log")
@ -425,7 +426,7 @@ reload its configuration file."))
(define iocaine-etc
(match-record-lambda <iocaine-configuration>
(config)
`(("iocaine/iocaine.toml" ,config))))
`(("iocaine/iocaine.toml" ,(toml-file "iocaine.toml" config)))))
(define iocaine-shepherd-service
(match-record-lambda <iocaine-configuration>
@ -743,8 +744,8 @@ test its configuration file."))
(auto-start?
(boolean #t)
"")
(extra-config
(string "")
(config
(gexp #~'())
"")
(no-serialization))
@ -765,14 +766,13 @@ test its configuration file."))
(define navidrome-shepherd-service
(match-record-lambda <navidrome-configuration>
(navidrome ffmpeg auto-start? extra-config)
(navidrome ffmpeg auto-start? config)
(let ((config-file
(mixed-text-file
"navidrome.toml"
"DataFolder = '/var/lib/navidrome'\n"
"CacheFolder = '/var/lib/navidrome/cache'\n"
"EnableInsightsCollector = false\n"
extra-config)))
(toml-file "navidrome.toml"
#~`(("DataFolder" . "/var/lib/navidrome")
("CacheFolder" . "/var/lib/navidrome/cache")
("EnableInsightsCollector" . #f)
,@#$config))))
(list (shepherd-service
(documentation "Run Navidrome.")
(provision '(navidrome))

View File

@ -9,12 +9,14 @@
;; Guix packages
#:use-module (gnu packages guile)
#:use-module (gnu packages guile-xyz)
#:use-module (rosenthal packages guile-xyz)
#:export (computed-substitution-with-inputs
file-content
hidden-desktop-entry
ini-file
json-file
toml-file
yaml-file))
;; XXX: substitute* doesn't fully support Unicode:
@ -80,6 +82,19 @@ format."
(call-with-output-file #$output
(cut scm->json #$exp <> #:pretty #t))))))
;; https://github.com/hylophile/guile-toml
;; TODO: TOML writing support is incomplete.
;; See https://github.com/hylophile/guile-toml/blob/main/toml/builder.scm.
(define (toml-file name exp)
"Return file-like object NAME, serialized from G-expression EXP in TOML
format."
(computed-file name
(with-extensions (list guile-json-4 guile-toml)
#~(begin
(use-modules (srfi srfi-26) (toml))
(call-with-output-file #$output
(cut scm->toml #$exp <>))))))
;; https://gitlab.com/yorgath/guile-yamlpp
(define (yaml-file name exp)
"Return file-like object NAME, serialized from G-expression EXP in YAML