patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: Demi Marie Obenour <demiobenour@gmail.com>
Cc: Spectrum OS Development <devel@spectrum-os.org>
Subject: Re: [PATCH 1/2] Create Nix derivation for building verity images
Date: Thu, 13 Nov 2025 12:32:49 +0100	[thread overview]
Message-ID: <875xbei2vy.fsf@alyssa.is> (raw)
In-Reply-To: <e2ee3782-d72d-4cd2-a271-9e8d7df2e3dd@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6589 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> On 11/6/25 06:44, Alyssa Ross wrote:
>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>> 
>>> On 11/6/25 05:20, Alyssa Ross wrote:
>>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>>
>>>>> This gets rid of a lot of duplicated code and allows building the verity
>>>>> roothash and superblock only when needed.  It also removes a hack used
>>>>> to work around make limitations.  Furthermore,
>>>>> 'veritysetup --root-hash-file' is used to avoid an awk script.
>>>>>
>>>>> Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
>>>>> ---
>>>>> nix-shell --pure --run 'make run' in host/initramfs fails.  This is a
>>>>> preexisting bug and I will send a separate patch for it.
>>>>> ---
>>>>>  host/initramfs/Makefile  | 25 +++++--------------------
>>>>>  host/initramfs/shell.nix |  4 +++-
>>>>>  host/rootfs/Makefile     | 24 +++++-------------------
>>>>>  host/rootfs/shell.nix    |  3 +++
>>>>>  host/verity.nix          | 19 +++++++++++++++++++
>>>>>  lib/common.mk            |  1 -
>>>>>  pkgs/default.nix         |  1 +
>>>>>  release/live/Makefile    | 26 +++++---------------------
>>>>>  release/live/default.nix |  4 +++-
>>>>>  9 files changed, 44 insertions(+), 63 deletions(-)
>>>>
>>>>> diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile
>>>>> index 00d125774bb7b98736d0928c69cb307740cee034..bb602e2745fb5873204f453b35fc529c5c96f64a 100644
>>>>> --- a/host/rootfs/Makefile
>>>>> +++ b/host/rootfs/Makefile
>>>>> @@ -82,25 +82,11 @@ clean:
>>>>>  	rm -rf build
>>>>>  .PHONY: clean
>>>>>  
>>>>> -# veritysetup format produces two files, but Make only (portably)
>>>>> -# supports one output per rule, so we combine the two outputs then
>>>>> -# define two more rules to separate them again.
>>>>> -build/rootfs.verity: $(dest)
>>>>> -	$(VERITYSETUP) format $(dest) build/rootfs.verity.superblock.tmp \
>>>>> -	    | awk -F ':[[:blank:]]*' '$$1 == "Root hash" {print $$2; exit}' \
>>>>> -	    > build/rootfs.verity.roothash.tmp
>>>>> -	cat build/rootfs.verity.roothash.tmp build/rootfs.verity.superblock.tmp \
>>>>> -	    > $@
>>>>> -	rm build/rootfs.verity.roothash.tmp build/rootfs.verity.superblock.tmp
>>>>> -build/rootfs.verity.roothash: build/rootfs.verity
>>>>> -	head -n 1 build/rootfs.verity > $@
>>>>> -build/rootfs.verity.superblock: build/rootfs.verity
>>>>> -	tail -n +2 build/rootfs.verity > $@
>>>>>  
>>>>> -build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/rootfs.verity.superblock build/rootfs.verity.roothash $(dest)
>>>>> +build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk $(ROOT_FS_VERITY) $(ROOT_FS_VERITY_ROOTHASH) $(dest)
>>>>>  	../../scripts/make-gpt.sh $@.tmp \
>>>>> -	    build/rootfs.verity.superblock:verity:$$(../../scripts/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \
>>>>> -	    $(dest):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)")
>>>>> +	"$$ROOT_FS_VERITY:verity:$$(../../scripts/format-uuid.sh "$$(dd "if=$$ROOT_FS_VERITY_ROOTHASH" bs=32 skip=1 count=1 status=none)")" \
>>>>> +	    $(dest):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 "$$ROOT_FS_VERITY_ROOTHASH")")
>>>>>  	mv $@.tmp $@
>>>>>  
>>>>>  debug:
>>>>> @@ -110,7 +96,7 @@ debug:
>>>>>  	    $(VMLINUX)
>>>>>  .PHONY: debug
>>>>>  
>>>>> -run: build/live.img $(EXT_FS) build/rootfs.verity.roothash
>>>>> +run: build/live.img $(EXT_FS) $(ROOT_FS_VERITY_ROOTHASH)
>>>>>  	@set -x && \
>>>>>  	ext="$$(mktemp build/spectrum-rootfs-extfs.XXXXXXXXXX.img)" && \
>>>>>  	truncate -s 10G "$$ext" && \
>>>>> @@ -131,7 +117,7 @@ run: build/live.img $(EXT_FS) build/rootfs.verity.roothash
>>>>>  	    -device virtconsole,chardev=virtiocon0 \
>>>>>  	    -drive file=build/live.img,if=virtio,format=raw,readonly=on \
>>>>>  	    -drive file=/proc/self/fd/3,if=virtio,format=raw \
>>>>> -	    -append "earlycon console=hvc0 roothash=$$(< build/rootfs.verity.roothash) intel_iommu=on nokaslr" \
>>>>> +	    -append "earlycon console=hvc0 roothash=$$(< "$$ROOT_FS_VERITY_ROOTHASH") intel_iommu=on nokaslr" \
>>>>>  	    -device virtio-keyboard \
>>>>>  	    -device virtio-mouse \
>>>>>  	    -device virtio-gpu \
>>>>> diff --git a/host/rootfs/shell.nix b/host/rootfs/shell.nix
>>>>> index 1bf61bebf418333624e799cc8ca231f5783206f4..f16e4905adfbc8faebde19d0a1364ad9df90219b 100644
>>>>> --- a/host/rootfs/shell.nix
>>>>> +++ b/host/rootfs/shell.nix
>>>>> @@ -5,6 +5,7 @@
>>>>>  import ../../lib/call-package.nix (
>>>>>  { callSpectrumPackage, rootfs, pkgsStatic, srcOnly, stdenv
>>>>>  , btrfs-progs, cryptsetup, jq, netcat, qemu_kvm, reuse, util-linux
>>>>> +, verity
>>>>>  }:
>>>>>  
>>>>>  rootfs.overrideAttrs (
>>>>> @@ -20,5 +21,7 @@ rootfs.overrideAttrs (
>>>>>      KERNEL = "${passthru.kernel}/${stdenv.hostPlatform.linux-kernel.target}";
>>>>>      LINUX_SRC = srcOnly passthru.kernel.configfile;
>>>>>      VMLINUX = "${passthru.kernel.dev}/vmlinux";
>>>>> +    ROOT_FS_VERITY = "${verity}/rootfs.verity.superblock";
>>>>> +    ROOT_FS_VERITY_ROOTHASH = "${verity}/rootfs.verity.roothash";
>>>>>    };
>>>>>  })) (_: {})
>>>>
>>>> Surely this would break interactive development of the rootfs?
>>>> If I'm in a Nix shell, and make a change to any part of the rootfs, the
>>>> verity data in the environment will be out of date.  I'd have to leave
>>>> and re-enter the Nix shell after /any/ change, waiting for an evaluation
>>>> each time, as opposed to the current situation where that's only
>>>> necessary when modifying Nix code or other Spectrum components.
>>>
>>> It would.  Are there alternatives you can recommend?  I don't want the
>>> updater and the installer to have to use two different copies.
>> 
>> Have the host/rootfs derivation install the verity files alongside the
>> rootfs image.  Then host/rootfs/Makefile is the single place we generate
>> the verity images, and it will still be regenerated by make when in a
>> Nix shell.
>
> Is it okay to instead remove dm-verity protection for the verity images?
> Given that we discussed using virtiofs for live development, I don't think
> the verity protection is necessary.  It also slows down live development.

If you can do it in a way that doesn't require modifying the rootfs
image.  I don't want it to have to do anything special to support
development builds that don't work like the real thing.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

  reply	other threads:[~2025-11-13 11:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 22:33 [PATCH 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-05 22:33 ` [PATCH 1/2] Create Nix derivation for building verity images Demi Marie Obenour
2025-11-06 10:20   ` Alyssa Ross
2025-11-06 10:55     ` Demi Marie Obenour
2025-11-06 11:44       ` Alyssa Ross
2025-11-07 19:24         ` Demi Marie Obenour
2025-11-13 11:32           ` Alyssa Ross [this message]
2025-11-05 22:33 ` [PATCH 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-08  4:47 ` [PATCH v2 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-08  4:47   ` [PATCH v2 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-08  4:47   ` [PATCH v2 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-12  0:59   ` [PATCH v3 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-12  0:59     ` [PATCH v3 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-13 11:46       ` Alyssa Ross
2025-11-13 22:33         ` Demi Marie Obenour
2025-11-14 11:53           ` Alyssa Ross
2025-11-12  0:59     ` [PATCH v3 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-13 11:57       ` Alyssa Ross
2025-11-13 22:42         ` Demi Marie Obenour
2025-11-14 11:58           ` Alyssa Ross
2025-11-19  8:15     ` [PATCH v4 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-19  8:15       ` [PATCH v4 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-25 12:27         ` Alyssa Ross
2025-11-25 12:31           ` Alyssa Ross
2025-11-19  8:15       ` [PATCH v4 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-22  1:21       ` [PATCH v5 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-22  1:21         ` [PATCH v5 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-25 12:34           ` Alyssa Ross
2025-11-22  1:21         ` [PATCH v5 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-25 12:41           ` Alyssa Ross
2025-11-26 19:10         ` [PATCH v6 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-26 19:10           ` [PATCH v6 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-27 19:23             ` Alyssa Ross
2025-11-26 19:10           ` [PATCH v6 2/2] Move UKI creation to a separate derivation Demi Marie Obenour
2025-11-28 10:47             ` Alyssa Ross
2025-11-28 19:27               ` Demi Marie Obenour
2025-11-28 11:02             ` Alyssa Ross
2025-11-28 19:25               ` Demi Marie Obenour
2025-11-28 20:12             ` Alyssa Ross
2025-11-26 18:58       ` [PATCH v5 0/2] Move verity and EFI creation to separate Nix derivations Demi Marie Obenour
2025-11-26 18:58         ` [PATCH v5 1/2] Build verity images in rootfs Nix derivation Demi Marie Obenour
2025-11-26 18:58         ` [PATCH v5 2/2] Move UKI creation to a separate derivation Demi Marie Obenour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875xbei2vy.fsf@alyssa.is \
    --to=hi@alyssa.is \
    --cc=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).