GNU bug report logs - #56114
Guix does not have a documented general and practical procedure for lowering a single lowerable object to the /gnu/store/... string.

Previous Next

Package: guix;

Reported by: Maxime Devos <maximedevos <at> telenet.be>

Date: Mon, 20 Jun 2022 21:03:02 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 56114 <at> debbugs.gnu.org
Subject: bug#56114: Guix does not have a documented general and practical procedure for lowering a single lowerable object to the /gnu/store/... string.
Date: Sun, 03 Jul 2022 22:50:40 +0200
[Message part 1 (text/plain, inline)]
Hi Maxime,

Maxime Devos <maximedevos <at> telenet.be> skribis:

> Seems like we are missing a general & documented & simple to use
> 'lower-object-completely' (or maybe 'compile-object'?) procedure for
> this ...  And maybe also a ,build-object REPL command?

How about the attached patch?

Sample session:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(gnu packages base)
scheme@(guile-user)> ,build coreutils
$11 = "/gnu/store/y8933036ljrz4ah9zcph09nmvdmmv5sf-coreutils-8.32-debug"
$12 = "/gnu/store/8fpk2cja3f07xls48jfnpgrzrljpqivr-coreutils-8.32"
scheme@(guile-user)> ,lower coreutils
$13 = #<derivation /gnu/store/nc93q3hmlzcgdn6jr7dv3j2m50ivn55f-coreutils-8.32.drv => /gnu/store/y8933036ljrz4ah9zcph09nmvdmmv5sf-coreutils-8.32-debug /gnu/store/8fpk2cja3f07xls48jfnpgrzrljpqivr-coreutils-8.32 7f0ebaf821e0>
scheme@(guile-user)> ,build (computed-file "foo" #~(begin (display "hi!\n")(mkdir #$output)(mkdir #$output:lib)))
$14 = "/gnu/store/axij9bkg56xv3k1z0l20gd6b0swn14sy-foo-lib"
$15 = "/gnu/store/h5s7k7m0fxk9n7q7729l3n4q7vyxnvpy-foo"
scheme@(guile-user)> ,build (computed-file "foo" #~(begin (display "Goeden dag!\n")(mkdir #$output)))
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://guix.bordeaux.inria.fr'... 100.0%
building /gnu/store/gplhka9g0bwv8b640zavw1z65y9zrvag-foo.drv...
$16 = "/gnu/store/ynvga6gxwj68mmk8ddj3i9sjhavkqah1-foo"
--8<---------------cut here---------------end--------------->8---

“lower” does what you would expect; “build” yields one value per output.

If that works for you, I’ll update the manual accordingly, and we can
always add more features (like build options) later on.  Thoughts?

Thanks,
Ludo’.

[Message part 2 (text/x-patch, inline)]
diff --git a/guix/monad-repl.scm b/guix/monad-repl.scm
index aefabdeebb..15c10efe01 100644
--- a/guix/monad-repl.scm
+++ b/guix/monad-repl.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2014, 2015, 2016, 2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -21,6 +21,12 @@ (define-module (guix monad-repl)
   #:use-module (guix monads)
   #:use-module (guix utils)
   #:use-module (guix packages)
+  #:use-module (guix status)
+  #:autoload   (guix gexp) (lower-object)
+  #:use-module ((guix derivations)
+                #:select (derivation?
+                          derivation->output-paths built-derivations))
+  #:use-module (ice-9 match)
   #:use-module (ice-9 pretty-print)
   #:use-module (system repl repl)
   #:use-module (system repl common)
@@ -69,16 +75,56 @@ (define (store-monad-language store)
                          #:guile-for-build guile)
                     'store-monad)))
 
+(define %build-verbosity 1)
+
+(define* (evaluate/print-with-store mvalue #:key build?)
+  "Run monadic value MVALUE in the store monad and print its value."
+  (with-store store
+    (set-build-options store
+                       #:print-build-trace #t
+                       #:print-extended-build-trace? #t
+                       #:multiplexed-build-output? #t)
+    (with-status-verbosity %build-verbosity
+      (let* ((guile  (or (%guile-for-build)
+                         (default-guile-derivation store)))
+             (values (run-with-store store
+                       (if build?
+                           (mlet %store-monad ((obj mvalue))
+                             (if (derivation? obj)
+                                 (mbegin %store-monad
+                                   (built-derivations (list obj))
+                                   (return
+                                    (match (derivation->output-paths obj)
+                                      (((_ . files) ...) files))))
+                                 (return (list obj))))
+                           (mlet %store-monad ((obj mvalue))
+                             (return (list obj))))
+                       #:guile-for-build guile)))
+        (for-each (lambda (value)
+                    (run-hook before-print-hook value)
+                    (pretty-print value))
+                  values)))))
+
 (define-meta-command ((run-in-store guix) repl (form))
   "run-in-store EXP
 Run EXP through the store monad."
-  (with-store store
-    (let* ((guile (or (%guile-for-build)
-                      (default-guile-derivation store)))
-           (value (run-with-store store (repl-eval repl form)
-                                  #:guile-for-build guile)))
-      (run-hook before-print-hook value)
-      (pretty-print value))))
+  (evaluate/print-with-store (repl-eval repl form)))
+
+(define-meta-command ((verbosity guix) repl (level))
+  "verbosity LEVEL
+Change build verbosity to LEVEL."
+  (set! %build-verbosity level))
+
+(define-meta-command ((lower guix) repl (form))
+  "lower OBJECT
+Lower OBJECT into a derivation and return it."
+  (evaluate/print-with-store (lower-object (repl-eval repl form))))
+
+(define-meta-command ((build guix) repl (form))
+  "build OBJECT
+Lower OBJECT and build it, returning its output file name(s)."
+  (evaluate/print-with-store (lower-object (repl-eval repl form))
+                             #:build? #t))
 
 (define-meta-command ((enter-store-monad guix) repl)
   "enter-store-monad

This bug report was last modified 3 years and 2 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.