From d234d9fa94d0c51c9125472e8c46408fa3dc8e18 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 2 Jan 2025 22:25:39 +0900 Subject: [PATCH] nongnu: Add a new nongnu-patches syntax. * nongnu/packages.scm: New file. Signed-off-by: John Kehayias --- nongnu/packages.scm | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 nongnu/packages.scm diff --git a/nongnu/packages.scm b/nongnu/packages.scm new file mode 100644 index 0000000..756f6cf --- /dev/null +++ b/nongnu/packages.scm @@ -0,0 +1,66 @@ +;;; SPDX-License-Identifier: GPL-3.0-or-later +;;; Copyright © 2015, 2018 Ludovic Courtès +;;; Copyright © 2025 Maxim Cournoyer + +(define-module (nongnu packages) + #:use-module (gnu packages) + #:use-module (guix diagnostics) + #:use-module (guix i18n) + #:use-module (ice-9 match) + #:use-module (srfi srfi-34) + #:replace (%patch-path + search-patch) + #:export (nongnu-patches)) + +;;; Commentary: +;;; +;;; This module refines the default value of some parameters from (gnu +;;; packages) and the syntax/procedures using those. This allows +;;; 'search-paths' and friends to work without any user intervention. +;;; +;;; Code: + +(define %nongnu-root-directory + ;; This is like %distro-root-directory from (gnu packages), with adjusted + ;; paths. + (letrec-syntax ((dirname* (syntax-rules () + ((_ file) + (dirname file)) + ((_ file head tail ...) + (dirname (dirname* file tail ...))))) + (try (syntax-rules () + ((_ (file things ...) rest ...) + (match (search-path %load-path file) + (#f + (try rest ...)) + (absolute + (dirname* absolute things ...)))) + ((_) + #f)))) + (try ("nongnu/packages/firmware.scm" nongnu/ packages/) + ("nongnu/ci.scm" nongnu/)))) + +(define %patch-path + ;; Define it after '%package-module-path' so that '%load-path' contains user + ;; directories, allowing patches in $GUIX_PACKAGE_PATH to be found. + (make-parameter + (map (lambda (directory) + (if (string=? directory %nongnu-root-directory) + (string-append directory "/nongnu/packages/patches") + directory)) + %load-path))) + +;;; XXX: The following must be redefined to make use of the overridden +;;; %patch-path parameter above. +(define (search-patch file-name) + "Search the patch FILE-NAME. Raise an error if not found." + (or (search-path (%patch-path) file-name) + (raise (formatted-message (G_ "~a: patch not found") + file-name)))) + +;;; XXX: `search-patches' being syntax, it can't be overridden by the module +;;; system, or so it seems, so we simply rename it. +(define-syntax-rule (nongnu-patches file-name ...) + "Return the list of absolute file names corresponding to each +FILE-NAME found in %PATCH-PATH." + (list (search-patch file-name) ...))