diff options
author | Arun Isaac | 2024-10-28 23:29:38 +0000 |
---|---|---|
committer | Arun Isaac | 2024-11-06 00:37:11 +0000 |
commit | 32ed0b083fd241bfd51cf3881c748b01fcd4e4d5 (patch) | |
tree | e9a01d85c2f09f6c2f23fbc2d5009022a52bada1 | |
parent | 366d5a94b07a879abf4d85dc11ef7bf3b3369aae (diff) | |
download | ravanan-32ed0b083fd241bfd51cf3881c748b01fcd4e4d5.tar.gz ravanan-32ed0b083fd241bfd51cf3881c748b01fcd4e4d5.tar.lz ravanan-32ed0b083fd241bfd51cf3881c748b01fcd4e4d5.zip |
command-line-tool: Support packages in SoftwareRequirement.
* ravanan/command-line-tool.scm: Import (gnu packages).
(specifications->environment): New function.
(build-command-line-tool-script)[software-package->package-specification]:
New function.
Build environment from packages if specified.
-rw-r--r-- | ravanan/command-line-tool.scm | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm index 6f95b88..ca78e4c 100644 --- a/ravanan/command-line-tool.scm +++ b/ravanan/command-line-tool.scm @@ -25,6 +25,7 @@ #:use-module (ice-9 filesystem) #:use-module (ice-9 format) #:use-module (ice-9 match) + #:use-module (gnu packages) #:use-module ((gnu packages gnupg) #:select (guile-gcrypt)) #:use-module ((gnu packages guile-xyz) #:select (guile-filesystem)) #:use-module (guix derivations) @@ -612,6 +613,27 @@ in a Guix inferior with @var{channels}." (manifest->environment (load-manifest manifest-file) guix-daemon-socket))) +(define (specifications->environment specifications channels guix-daemon-socket) + "Build a profile with package @var{specifications} and return an association list +of environment variables to set to use the built profile. Connect to the Guix +daemon specified by @var{guix-daemon-socket}. If @var{channels} is not +@code{#f}, look up packages in a Guix inferior with @var{channels}." + (define packages->environment + (compose (cut manifest->environment <> guix-daemon-socket) + packages->manifest)) + + (if channels + (call-with-inferior (inferior-for-channels channels) + (lambda (inferior) + (packages->environment + (map (lambda (specification) + (match (lookup-inferior-packages inferior specification) + ((inferior-package _ ...) + inferior-package))) + specifications)))) + (packages->environment + (map specification->package specifications)))) + (define (manifest->environment manifest guix-daemon-socket) "Build @var{manifest} and return an association list of environment variables to set to use the built profile. Connect to the Guix daemon specified @@ -656,6 +678,14 @@ same as in @code{run-workflow} from @code{(ravanan workflow)}." "envValue")))) (assoc-ref* env-var-requirement "envDef")))) + (define (software-package->package-specification package) + (string-append (assoc-ref* package "package") + (from-maybe + (maybe-bind (maybe-assoc-ref (just package) "version") + (compose just + (cut string-append "@" <>))) + ""))) + (define (files-to-stage initial-work-dir-requirement) (vector-map->list (lambda (listing-entry) (if (string? listing-entry) @@ -809,11 +839,18 @@ same as in @code{run-workflow} from @code{(ravanan workflow)}." (initial-work-dir-requirement (find-requirement requirements "InitialWorkDirRequirement")) (manifest-file + (from-maybe (maybe-assoc-ref + (find-requirement requirements "SoftwareRequirement") + "manifest") + manifest-file)) + (package-specifications (from-maybe - (maybe-bind (find-requirement requirements "SoftwareRequirement") - (compose just - (cut assoc-ref* <> "manifest"))) - manifest-file))) + (maybe-let* ((packages (maybe-assoc-ref + (find-requirement requirements "SoftwareRequirement") + "packages"))) + (just (vector-map->list software-package->package-specification + packages))) + '()))) (with-imported-modules (source-module-closure '((ravanan work command-line-tool) (ravanan work monads) (ravanan work ui) @@ -1015,9 +1052,19 @@ directory of the workflow." (for-each (match-lambda ((name . value) (setenv name value))) - '#$(manifest-file->environment manifest-file - channels - guix-daemon-socket)) + '#$(match package-specifications + ;; No package specifications; try the manifest + ;; file. + (() + (manifest-file->environment manifest-file + channels + guix-daemon-socket)) + ;; Use package specifications to build an + ;; environment. + (_ + (specifications->environment package-specifications + channels + guix-daemon-socket)))) (call-with-temporary-directory (lambda (inputs-directory) |