aboutsummaryrefslogtreecommitdiff
path: root/forge
diff options
context:
space:
mode:
authorArun Isaac2022-01-24 14:53:57 +0530
committerArun Isaac2022-01-24 15:04:31 +0530
commit00710bd2e82229cfc04c2e94c29f6155fcabfeb6 (patch)
tree1fa9e06662c89c19d4e3d5843d0779abf2357479 /forge
parent0dcb1e51a188df1dacf362fa1c2f45cd4e8bfb17 (diff)
downloadguix-forge-00710bd2e82229cfc04c2e94c29f6155fcabfeb6.tar.gz
guix-forge-00710bd2e82229cfc04c2e94c29f6155fcabfeb6.tar.lz
guix-forge-00710bd2e82229cfc04c2e94c29f6155fcabfeb6.zip
forge: Add with-packages.
with-packages allows for easy creation of G-expressions where a list of specified packages are available. It is to G-expressions what `guix shell' is to the shell. with-packages is frequently used in the definition of CI jobs. * forge/utils.scm: New file.
Diffstat (limited to 'forge')
-rw-r--r--forge/utils.scm65
1 files changed, 65 insertions, 0 deletions
diff --git a/forge/utils.scm b/forge/utils.scm
new file mode 100644
index 0000000..f0740f0
--- /dev/null
+++ b/forge/utils.scm
@@ -0,0 +1,65 @@
+;;; 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 utils)
+ #:use-module (ice-9 match)
+ #:use-module (guix derivations)
+ #:use-module (guix gexp)
+ #:use-module (guix monads)
+ #:use-module (guix profiles)
+ #:use-module (guix search-paths)
+ #:use-module (guix store)
+ #:export (with-packages))
+
+(define (profile-with-packages packages)
+ "Return profile with PACKAGES."
+ (with-store store
+ (run-with-store store
+ (mlet* %store-monad ((prof-drv (profile-derivation
+ (packages->manifest packages)))
+ (profile -> (derivation->output-path prof-drv)))
+ (mbegin %store-monad
+ (built-derivations (list prof-drv))
+ (return profile))))))
+
+(define (environment-with-packages packages)
+ "Return environment of a profile with PACKAGES. Return value is an
+association list mapping the name of an environment variable to its
+value."
+ (map (match-lambda
+ ((search-path . value)
+ (cons (search-path-specification-variable search-path)
+ value)))
+ (profile-search-paths (profile-with-packages packages))))
+
+(define (with-packages packages exp)
+ "Return a gexp executing EXP, another gexp, in an environment where
+PACKAGES are available and their search path environment variables
+have been set."
+ #~(begin
+ (use-modules (ice-9 match))
+ ;; Add a reference to the profile.
+ #$(profile-with-packages packages)
+ ;; Set the environment.
+ (for-each (match-lambda
+ ((variable . value)
+ (setenv variable value)))
+ '#$(environment-with-packages packages))
+ ;; Run the provided expression.
+ #$exp))