Subject: Re: bug#40998: Guix System's initrd doesn't honor rootflags

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 28 Feb 2022 15:02:47 -0500

Hi Ludovic!

Ludovic Courtès <[email-masked]> writes:

> Hi!
>
> Maxim Cournoyer <[email-masked]> skribis:
>
>> This version field exposes the (already present) version information of a boot
>> parameters file.
>>
>> * gnu/system.scm (%boot-parameters-version): New variable.
>> (<boot-parameters>)[version]: New field.
>> (read-boot-parameters): Use it.
>> (operating-system-boot-parameters-file): Likewise.
>> * tests/boot-parameters.scm (test-read-boot-parameters): Use
>> %boot-parameters-version as the default version value in the template.
>
> [...]
>
>>  (define-record-type* <boot-parameters>
>>    boot-parameters make-boot-parameters boot-parameters?
>>    (label            boot-parameters-label)
>> @@ -322,7 +326,9 @@ (define-record-type* <boot-parameters>
>>    (kernel           boot-parameters-kernel)
>>    (kernel-arguments boot-parameters-kernel-arguments)
>>    (initrd           boot-parameters-initrd)
>> -  (multiboot-modules boot-parameters-multiboot-modules))
>> +  (multiboot-modules boot-parameters-multiboot-modules)
>> +  (version          boot-parameters-version  ;positive integer
>> +                    (default %boot-parameters-version)))
>
> [...]
>
>>    (match (read port)
>> -    (('boot-parameters ('version 0)
>> +    (('boot-parameters ('version (? version? version))
>>                         ('label label) ('root-device root)
>>                         ('kernel kernel)
>>                         rest ...)
>>       (boot-parameters
>> +      (version version)
>>        (label label)
>>        (root-device (device-sexp->device root))
>
> There’s no need to have a ‘version’ field in live <boot-parameters>
> records: have the ‘version’ field in the serialized format (the sexp)
> and make sure the deserializer correctly converts to the internal
> representation.
>
> Here, I think you can bump the version number in the serialized form,
> and have ‘read-boot-parameters’ automatically augment ‘kernel-arguments’
> when VERSION is 0 with “--root=XYZ”.

I initially went that route, as this was the idea you'd given me
initially.  However, 'read-boot-parameters' deals with serializing the
parameters file only; to add 'root', 'gnu.load' and 'gnu.system', the
operating-system object as well as the root device are needed.  The
reason 'gnu.load' and 'gnu.system' aren't written to the parameters file
to start with is because they would cause the system directory to no
longer be content-addressable; this is explained in the docstring of
'operating-system-boot-parameters-file':

    When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments such as 'root'
    and 'gnu.load' to the returned file (since the returned file is then usually
    stored into the content-addressed "system" directory, it's usually not a
    good idea to give it because the content hash would change by the content hash
    being stored into the "parameters" file).

So, unless we were to pack 'read-boot-parameters' with unrelated duties
and a 'system-kernel-arguments?' argument, it seems unavoidable to
expose the 'version' metadata.

> (It might be that you can even do that without bumping the version
> number.  Bumping is clearer but the downside is that an older Guix will
> abort when attempting to read ‘parameters’.  This could happen if you
> roll back to an earlier generation and try to run ‘guix system
> reconfigure’ or similar from there.)
>
> Also, you could write the ‘match’ pattern like this:
>
>   ('boot-parameters ('version (and version (or 0 1)))
>                     ('label label) …)

I think this patch's current form is preferable, as it means future
boot-parameters version bumps won't break older Guices (when
reconfiguring), as long as the version is an exact, non-negative integer
(e.g. when going from 1 to 2).

Let me know what you think!

Thank you,

Maxim