1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-06-16 11:14:06 +02:00
Files
Giacomo Leidi 0b8e838208 services: configuration: Add environment variable serializer.
This patch implements a general API to serialize configuration records
to list of pairs representing environment variables. The car of each
pair represents the variable name and the cdr the variable value.

* gnu/services/configuration/environment-variables.scm: New file.
(serialize-string-environment-variable)
(serialize-maybe-string-environment-variable)
(serialize-boolean-environment-variable)
(serialize-maybe-boolean-environment-variable)
(serialize-number-environment-variable)
(serialize-maybe-number-environment-variable): New variables.
(serialize-environment-variables): New variable.
* gnu/services/configuration/utils.scm: New file.
(uglify-snake-case): New variable.
* tests/services/configuration.scm: Add tests for environment serializer.
(wrong type for a field): Adjust error location.
* doc/guix.texi: Document it.

Change-Id: I81a166576f94d3c8f5bf78c82a02183689a3091c
Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
2026-04-12 17:23:42 +02:00

36 lines
1.4 KiB
Scheme

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2026 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu services configuration utils)
#:use-module (ice-9 string-fun)
#:export (uglify-snake-case))
(define (uglify-snake-case field-name)
"Serializes FIELD-NAME, a field name from @code{(gnu services configuration)},
to a downcased, snake case string representation of the field name. Trailing
@code{?} in the name are dropped and dashes are replaced with underscores.
For example the procedure would convert @code{'A-Field?} to @code{\"a_field\"}."
(define str (symbol->string field-name))
(string-downcase
(string-replace-substring
(if (string-suffix? "?" str)
(string-drop-right str 1)
str)
"-" "_")))