ludo@gnu.org (Ludovic Courtès) writes: > Hi Chris, > > Chris Marusich skribis: > >> I saw this in guix/scripts.build.scm: >> >> (and (build-derivations store drv mode) >> (for-each show-derivation-outputs drv) >> (for-each (cut register-root store <> <>) >> (map (lambda (drv) >> (map cdr >> (derivation->output-paths drv))) >> drv) >> roots)) >> >> Here, we build the derivations, and then we add indirect GC roots. My >> question is: what guarantee is there that the output paths will not be >> garbage collected after we build the derivations but before we add the >> indirect GC roots? > > For the duration of the connection to the build daemon, build results > are registered as GC roots, so we’re fine. > > You can see it in the ‘DerivationGoal’ constructor in libstore/build.cc: > > /* Prevent the .chroot directory from being > garbage-collected. (See isActiveTempFile() in gc.cc.) */ > worker.store.addTempRoot(drvPath); > > Likewise in ‘SubstitutionGoal::init’. > > HTH, > Ludo’. That's exactly what I was missing. Thank you for the information. My understanding is that Nix builds derivations in a temporary directory. My understanding is that eventually, we copy the results of the build into the final, content-addressed store path. Since we don't know the final, content-addressed store path until after we calculate the hash of the output, how do we prevent that final store path from being garbage collected while the build process is running? Do we use addTempRoot to add the final, content-addressed store path as a temporary root, too? I looked in the code but couldn't figure this out. -- Chris