Hello all,

I would like to gc root my operating system derivation to keep all
inputs necessary to build the system in store even on gc colleting,
preferably also the ungrafted versions. One way would be to make
multiple calls to the guix system build and gc root them out of the
store myself, but I would rather not use that option, I would like this
to be in the operating-system itself.

I went through NixOS code to see how they do something like that,
because they have an option to gc root the build inputs. They just gc
root the system derivation similarly to what gc-root-service-type does
in Guix, this should keep all the build inputs of the operating system
as the drv references them.

I started figuring out how to get a .drv file in the gc root service
type, for now I have this procedure that will take an os and make a new
os from it that will have the original system derivation gc rooted.
---
(define (operating-system-with-build-inputs os)
  (operating-system
    (inherit os)
    (services (operating-system-user-services os))
    (services
     (cons*
      (simple-service 'gc-root-system-derivation
                      gc-root-service-type
                      (list
                       (derivation-file-name
                        (with-store %store
                          (run-with-store %store
                            (operating-system-derivation os))))
                       (with-store %store
                         (run-with-store %store
                           (without-grafting
                            (operating-system-derivation os))))
                       (derivation-file-name
                        (with-store %store
                          (run-with-store %store
                            (without-grafting
                             (operating-system-derivation os)))))))
      (operating-system-user-services os)))))
---

This somewhat works, but it seems to me like this slows down the
evaluation and build because there are actually multiple consequent
builds through the daemon happening rather than doing all the builds at
one because of the multiple run-with-store calls. I can't seem to figure
out a way to reference derivation file without doing something like this
- is there a different way to reference drv of a package/operating
system instead? It seems to me like everything in gexps operates with
the outputs of derivations rather than the derivations themselves, but
maybe I am just missing a procedure to reference derivation or
something?

Apart from that I was trying to also gc root the ungrafted operating
system output and derivation, but that doesn't seem to work well - or at
least the derivation and output gc rooted is different than one obtained
with --no-grafts of the original system. I suppose that could be because
it is being grafted afterwards? But still, it's not the same path as the
grafted one, so something strange is going on.

Regards,
Rutherther

Reply via email to