Hi, writing a followup with my new findings. I figured out that the reason I was gettng `#<procedure 7f46536035c0 at gnu/services.scm:435:2 (state)>: invalid G-expression input` is that there is no gexp compiler for procedure I am passing to gc-root-service-type. So I got into defining gexp compilers for 1. derivation name and 2. operating system, 3. non-grafted derivation.
The result is below, along with usage to gc root the os derivation and non-grafted output. Though I still am not really sure if my non-grafting works, because the derivation I am getting is different than when I do --no-grafts and guix system build with the original os. IMO it's quite confusing that there is a function operating-system-derivation that returns just a raw procedure rather than a derivation record type, which I would expect based on the name, while this is fine if used without gexps, it cannot be ungexped, as it doesn't have its compiler - and I suppose that a compiler cannot be made for an anonymous prodecure? or can it? > 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? Yes, there is, by making a procedure that accepts the store (can be made with mlet* %store-monad) and returns (derivation-file-name derivation) > 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? This is quite confused on my part, gexps don't care what it is as long as there is a compiler for the type. There is an ungexp for derivation, package etc., those are what dictate what is produced, be it output path of derivation, or the drv itself. It is perfectly possible to make a record type drv-name that when used with a derivation as (drv-name my-derivation), will produce .drv file name. > > 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. I am still confused about how the grafts work exactly and can't figure out if I did what was needed yet, or not. Why doesn't the derivation match? Regards, Rutherther My current code for gc rooting operating system: --- (define (derivation->drv-name drv) (mlet* %store-monad ((drv drv)) (return (derivation-file-name drv)))) (use-modules (srfi srfi-9) (ice-9 match)) (define-record-type <non-grafted> (non-grafted derivation) non-grafted? (derivation non-grafted-derivation)) (define-gexp-compiler (non-grafted-compiler (non-grafted <non-grafted>) system target) (without-grafting (non-grafted-derivation non-grafted))) (define-record-type <drv-name> (drv-name derivation) drv-name? (derivation drv-name-derivation)) (define-gexp-compiler (drv-name-compiler (drv-name <drv-name>) system target) (derivation->drv-name (drv-name-derivation drv-name))) (define <operating-system> (@@ (gnu system) <operating-system>)) (define-gexp-compiler (os-compiler (os <operating-system>) system target) (operating-system-derivation os)) ;; Takes an operating system and gc roots its derivation (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 (drv-name (operating-system-derivation os)) (non-grafted (operating-system-derivation os)))) (operating-system-user-services os)))))