On Mon, May 12, 2025 at 10:08:33AM -0400, Greg Hogan wrote:
> How many grafts are currently on the master branch? My (potentially
> naive and) simple regex returns less than a dozen, but when building
> packages I see counts like "applying 100 grafts for ...". Is the
> latter a recursive count?

Grafts are created by adding a replacement to a package:

------
$ git grep '(replacement ' gnu/packages                                         
                   
gnu/packages/backup.scm:    (replacement libarchive/fixed)
gnu/packages/base.scm:   (replacement glibc/fixed)
gnu/packages/bootstrap.scm:             (replacement (and=> 
(package-replacement p)
gnu/packages/cups.scm:    (replacement cups-minimal/fixed)
gnu/packages/curl.scm:    (replacement curl/fixed)
gnu/packages/curl.scm:     (replacement curl/fixed)
gnu/packages/emacs.scm:    ;; Note: When using (replacement …), ensure that 
comp-native-version-dir
gnu/packages/emacs.scm:                 (let ((replacement (false-if-exception
gnu/packages/engineering.scm:                (let ((replacement (string-append 
(make-string 6 #\space)
gnu/packages/gtk.scm:    (replacement cairo-1.18.4)
gnu/packages/linux.scm:    (replacement eudev-fixed)
gnu/packages/xml.scm:    (replacement expat/fixed)
gnu/packages/xml.scm:    (replacement expat/fixed)
------

There are some red herrings but the number of results is small enough to
understand.

Grafts are applied when packages are built. For example, during `guix
build`, `guix install`, `guix system build`, `guix shell`, etc. At the
conclusion of those builds, Guix scans the resulting store items for
references to other paths in the store, and the resulting network of
references in stored in the Guix database, /var/guix/db.

For example, we see above that libarchive has been replaced by
libarchive/fixed.

When Guix applies the libarchive graft, it is applied to every store
item that is part of the package or profile build that contains a
reference to libarchive. Each reference is replaced with a reference to
libarchive/fixed. This is done by using the store reference information
in the Guix database. A new store item is created that refers to
libarchive/fixed instead of libarchive.

So, although there are only 7 grafts in our codebase, almost every
package will have some references replaced after it is built, because we
only use grafts for packages upon which a large number of other packages
depend.

> Ungrafts are (seemingly) difficult to locate, hard to track, and
> something we are typically not thinking about.

Hopefully that illustrates that grafts are easy to locate, and that they
are tracked precisely by Guix itself in its database of references
within the store. It is a completely deterministic mechanism.

Reply via email to