aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorArun Isaac2022-03-08 22:47:15 +0530
committerArun Isaac2022-03-08 22:47:15 +0530
commit36dbe925601d7be5dfd5c1beaa2406b1d5dbc00c (patch)
tree26912069ac6563caddf66639e6601a0e258603f6 /guix
parentafba9bc7d2927c3a31c6b46d75c1b63b598d2776 (diff)
downloadguix-forge-36dbe925601d7be5dfd5c1beaa2406b1d5dbc00c.tar.gz
guix-forge-36dbe925601d7be5dfd5c1beaa2406b1d5dbc00c.tar.lz
guix-forge-36dbe925601d7be5dfd5c1beaa2406b1d5dbc00c.zip
forge: Add with-profile utility.
* guix/forge/build/utils.scm: New file.
Diffstat (limited to 'guix')
-rw-r--r--guix/forge/build/utils.scm61
1 files changed, 61 insertions, 0 deletions
diff --git a/guix/forge/build/utils.scm b/guix/forge/build/utils.scm
new file mode 100644
index 0000000..a9391b3
--- /dev/null
+++ b/guix/forge/build/utils.scm
@@ -0,0 +1,61 @@
+;;; guix-forge --- Guix software forge meta-service
+;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
+;;;
+;;; This file is part of guix-forge.
+;;;
+;;; guix-forge 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.
+;;;
+;;; guix-forge 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 guix-forge. If not, see
+;;; <https://www.gnu.org/licenses/>.
+
+(define-module (forge build utils)
+ #:use-module (rnrs exceptions)
+ #:use-module (ice-9 match)
+ #:use-module (guix build utils)
+ #:use-module (guix gexp)
+ #:use-module (guix profiles)
+ #:use-module (guix search-paths)
+ #:use-module (guix store)
+ #:use-module (guix utils)
+ #:export (with-profile))
+
+;;;
+;;; Commentary:
+;;;
+;;; This module provides various build-side utilities.
+;;;
+
+;;; Code:
+
+(define (with-profile profile exp)
+ "Return a gexp referencing PROFILE and executing EXP, another gexp,
+in the environment of PROFILE."
+ #~(begin
+ ;; Reference the profile.
+ #$profile
+ ;; Set the environment.
+ ;; We pull out match-lambda using module-ref instead of using
+ ;; use-modules because this gexp will be substituted into other
+ ;; gexps and use-modules only works at the top-level.
+ (let-syntax ((match-lambda (macro-transformer
+ (module-ref (resolve-module '(ice-9 match))
+ 'match-lambda))))
+ (for-each (match-lambda
+ ((variable . value)
+ (setenv variable value)))
+ '#$(map (match-lambda
+ ((search-path . value)
+ (cons (search-path-specification-variable search-path)
+ value)))
+ (profile-search-paths profile))))
+ ;; Run the provided expression.
+ #$exp))