Hi all,

On 5/10/26 21:51, Hugo Buddelmeijer wrote:
What would be the easiest way to prevent any package from a specific
commit (or generation) to be garbage collected?

Maybe I can make a manifest with "all packages" and then filter out those that are not already in the store.  So the manifest will always build, since it would contain only already built packages.  Not really what a manifest normally should do, but I guess it could work.

A manifest with all packages seems rather simple, but I can't figure out how to only keep the packages that are already in the store.

I thought, I get the store path, and then check whether that exists. But what would be the best way to get the store path of a package?

Here my attempt; I found `package-file` [1] in `packages.scm`:

> Return as a monadic value the absolute file name of FILE within the
> OUTPUT directory of PACKAGE.  When FILE is omitted, return the name
> of the OUTPUT directory of PACKAGE.

Excellent!

> Note that this procedure does _not_ build PACKAGE.  Thus, the result
> might or might not designate an existing file.

Even better, sounds like exactly what I need.

>  We recommend not using this procedure unless you know what you
> are doing.

Uh oh....  But no alternatives are listed, so here we go:

```
(use-modules (gnu)
             (guix)
             (guix store))

(define store (open-connection))
;; (set-build-options store #:use-substitutes? #f)

(define packages-in-store
  (fold-packages
   (lambda (package lst)
     (run-with-store store
       (mlet %store-monad ((ppp (package-file package)))
         (if (file-exists? ppp)
             (cons package lst)
             lst))))
     '()))

(display (length packages-in-store))
(newline)
```

with the expectation that the above would list the number of packages of the current guix I have in my store.

But it does not do that at all! Depending whether `#:use-substitutes?` is set, it will either download all packages, or build them, despite the documentation claiming that packages would not be build..

Could someone perhaps give me a pointer on how to get the directory name of a package?

My own next plan is to actually look up how the store path is derived, that should help.

Thanks,
Hugo

[1 ]https://codeberg.org/guix/guix/src/branch/master/guix/packages.scm#L2172


Reply via email to