Repository navigation
fix: keep the overlay's Nix database in sync with the base image - #55
Open
raphaelcoeffic wants to merge 1 commit into
Open
raphaelcoeffic wants to merge 1 commit into
raphaelcoeffic wants to merge 1 commit into
Conversation
The base image ships its Nix database, but the first `pkg install` copies it up into the overlay. After a base image upgrade, that copy hides the new database: the new base store paths are unknown to Nix, and the next garbage collection (`pkg remove`) deletes them. Upgrading from 0.2.6 to 0.2.7 then removing a package deleted the whole base image (742 MiB): zsh, vim, curl, ... gone, and the shell failing. When the overlay is mounted (no session running) and the base image changed since it was last synced: - remove the whiteouts in the upper layer hiding base store paths, which repairs overlays already hit by the garbage collection, - register the base store paths into the overlay's database, if it has its own, with `nix-store --load-db` in a chroot where /nix is the overlay, as the owner of the database seen through the overlay, - record the base image hash, so this runs once per base image. Also make the fork thread-count test tolerate other tests running in parallel: it failed whenever more library tests ran at the same time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Upgrading dive breaks the environment for anyone who installed a package before the upgrade:
pkg install treepkg remove tree→ garbage collection deletes 742 MiB, the whole new base image: zsh, vim, curl, jq, sngrep, … are gone and interactive sessions fail (exit 127)The same steps on a fresh 0.2.7 state, without upgrade, only free the package and the nixpkgs source.
Cause
The base image ships its Nix database (
var/nix/db), but the firstpkg installcopies it up into the overlay's upper layer. After an upgrade, that copy hides the new database: it doesn't know the new base store paths (checked: 0 matches for the new base root, vs. 1 in the new image's database), so garbage collection deletes them. On disk, the base image is intact: the deletions are overlayfs whiteouts in the upper layer.Fix
New
base_syncmodule, run fromSharedMountBuilder::make_mountwhen it mounts the overlay (holding the lock, no session running), if the base image hash differs from the one recorded in{rootful,rootless}/base.sha256:upper/storehiding store paths of the base image — this repairs overlays already broken by the bug.nix-store --load-db < /nix/.base.reginfo(shipped in the base image), in a forked child chrooted into a root where/nixis the overlay (reusing the image builder'sbind_mount_all_dir). The child acts as the owner of/nix/var/nix/dbseen through the overlay: root with an id-mapped overlay, the user for rootless containers.Without its own database (no package ever installed), the overlay uses the base image's database: only the hash is recorded.
Also:
fork::tests::counts_threadsasserted an exact process-wide thread count, which fails whenever other tests run in parallel — it failed consistently once more library tests were added. It now asserts a lower bound.Testing
alpine:3.22container, scratch state directory:restored 132 base image store paths,registering base image store paths→ all base tools work,pkg install/pkg removecycle afterwards only frees the package (252 MiB), base intact, interactive shell works. Upper layer files still owned by the user (no root-owned files: id mapping respected).pkg install tree, then this build upgrades the base image (-bwith the base image artifact of main run #198): paths registered on the first session,treeand base tools work,pkg remove treekeeps the base image, no resync on the next session.