[bug#75647,v2,1/2] profiles: Add #:build? argument to lower-manifest-entry.

Message ID 367d0f5cffef102e3e4cdbaabcc093e94a74b180.1737201981.git.iyzsong@member.fsf.org
State New
Headers
Series [bug#75647,v2,1/2] profiles: Add #:build? argument to lower-manifest-entry. |

Commit Message

Alexis Praga via Guix-patches via Jan. 18, 2025, 12:07 p.m. UTC
  From: 宋文武 <iyzsong@member.fsf.org>

* guix/profiles.scm (lower-manifest-entry): Add #:build? keyword argument.

Change-Id: Ifb86d581156034897377f3614fac67b7748e0ec3
---
 guix/profiles.scm | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)


base-commit: 87045f0982bd7aebb07b380cbf322651227546f4
  

Comments

Ludovic Courtès Jan. 27, 2025, 4:34 p.m. UTC | #1
Hi,

iyzsong@envs.net skribis:

> From: 宋文武 <iyzsong@member.fsf.org>
>
> * guix/profiles.scm (lower-manifest-entry): Add #:build? keyword argument.
>
> Change-Id: Ifb86d581156034897377f3614fac67b7748e0ec3

[...]

> @@ -319,12 +320,20 @@ (define* (lower-manifest-entry entry system #:key target)
>  
>    (let ((item (manifest-entry-item entry)))
>      (if (string? item)
> -        (with-monad %store-monad
> +        (mbegin %store-monad
> +          (build (list item))
> +          (if build?
> +              (build (list item))
> +              (return #t))
>            (return entry))
> -        (mlet %store-monad ((drv (lower-object item system
> +        (mlet* %store-monad ((drv (lower-object item system
>                                                 #:target target))
> +
>                              (dependencies (recurse entry))
> -                            (output -> (manifest-entry-output entry)))
> +                            (output -> (manifest-entry-output entry))
> +                            (built (if build?
> +                                       (built-derivations (list (cons drv output)))

Overall, I think that building things individually is a bad idea because
it prevents parallelism and makes things overall slower (even if the
“build handler” mechanism mitigates that¹).

You wrote:

> Hello, these patches make each profile hook run upon its specified interested
> inputs, eg: the 'info-dir-file' hook only get inputs with info manuals,
> install a package without info files won't trigger it.  Thus reduce the chance
> and time to rerun them when your profile changed.

The ‘info-dir-file’ hooks runs instantly when there are no Info files,
so that’s probably not a good example.

> Years ago tried in <https://issues.guix.gnu.org/29928>, now it seems I don't
> need some hack like 'eval-gexp', just need all manifest entries built before
> hooks.

Yeah, I’m not sure how to move forward.

Perhaps you could identify specific cases of profile hooks that may
often run and use resources for no good reason?

Thanks,
Ludo’.

¹ https://guix.gnu.org/en/blog/2020/grafts-continued/
  

Patch

diff --git a/guix/profiles.scm b/guix/profiles.scm
index a28cf872cf..0f47268541 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -3,7 +3,7 @@ 
 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
 ;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
-;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
+;;; Copyright © 2015, 2025 宋文武 <iyzsong@envs.net>
 ;;; Copyright © 2016, 2017, 2018, 2019, 2021, 2022 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
@@ -308,9 +308,10 @@  (define (manifest-entry-lookup manifest)
       ((_ . entry) entry)
       (#f          #f))))
 
-(define* (lower-manifest-entry entry system #:key target)
+(define* (lower-manifest-entry entry system #:key target
+                               (build? #f))
   "Lower ENTRY for SYSTEM and TARGET such that its 'item' field is a store
-file name."
+file name.  When BUILD? is true, build the entry before returning."
   (define (recurse entry)
     (mapm/accumulate-builds (lambda (entry)
                               (lower-manifest-entry entry system
@@ -319,12 +320,20 @@  (define* (lower-manifest-entry entry system #:key target)
 
   (let ((item (manifest-entry-item entry)))
     (if (string? item)
-        (with-monad %store-monad
+        (mbegin %store-monad
+          (build (list item))
+          (if build?
+              (build (list item))
+              (return #t))
           (return entry))
-        (mlet %store-monad ((drv (lower-object item system
+        (mlet* %store-monad ((drv (lower-object item system
                                                #:target target))
+
                             (dependencies (recurse entry))
-                            (output -> (manifest-entry-output entry)))
+                            (output -> (manifest-entry-output entry))
+                            (built (if build?
+                                       (built-derivations (list (cons drv output)))
+                                       (return #t))))
           (return (manifest-entry
                     (inherit entry)
                     (item (derivation->output-path drv output))