From 29de2edfbbed21ac016f73a45d399795fc2e4dfb Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 23 Feb 2024 21:22:55 +0100 Subject: system, home: Validate ‘services’ field value. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This guides newcomers who might stick a single (service …) form in this field. * gnu/services.scm (validate-service-list): New macro. (%validate-service-list): New procedure. * gnu/system.scm ()[services]: Add ‘sanitize’. * gnu/home.scm ()[services]: Add ‘sanitize’. Change-Id: I9e29bd9a078e87b627ab766fd669ba9de79f8473 --- gnu/services.scm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'gnu/services.scm') diff --git a/gnu/services.scm b/gnu/services.scm index 59481af10f..88593e8091 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2015-2023 Ludovic Courtès +;;; Copyright © 2015-2024 Ludovic Courtès ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2020, 2021 Ricardo Wurmus @@ -91,6 +91,8 @@ for-home for-home? + validate-service-list + service-error? missing-value-service-error? missing-value-service-error-type @@ -1271,4 +1273,19 @@ Home service rather than a System service." (syntax-parameterize ((for-home? (identifier-syntax #t))) exp ...)) +(define-with-syntax-properties (validate-service-list (value properties)) + (%validate-service-list value properties)) + +(define (%validate-service-list value properties) + (match value + (((? service?) ...) value) + (_ + (raise + (make-compound-condition + (condition + (&error-location + (location (source-properties->location properties)))) + (formatted-message + (G_ "'services' field must contain a list of services"))))))) + ;;; services.scm ends here. -- cgit v1.2.3