Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find and document automation to dump/load hosts /nix/store db #196

Open
thkoch2001 opened this issue Jan 25, 2024 · 2 comments
Open

find and document automation to dump/load hosts /nix/store db #196

thkoch2001 opened this issue Jan 25, 2024 · 2 comments

Comments

@thkoch2001
Copy link
Contributor

The hosts /nix/store is mounted inside the microvm. However nix inside the VM does not use objects from /nix/store. It does not know these objects since they are not in the Nix database (/nix/var/nix/db).

Probably the best solution is currently worked on as [RFC 0152] local-overlay store.

A workaround is to use nix-store --dump-db on the host and nix-store --load-db in the guest VM.

Of course this is a hack. But for my use case of local project development VMs it should work fine.

I've not yet figured out a nice automation for this. Ideally, a db-dump would be made on microvm boot, copied in the VM and loaded inside the VM.

@thkoch2001
Copy link
Contributor Author

Documenting my current implementation here before I forget any details.

I'm running my microvm as a user systemd service, templated by the vm name. There is a dependency on a virtiofsd service. Before starting the VM, the microvm service does:

[Service]
ExecStartPre=/usr/bin/sh -c "[ /nix/var/nix/db/db.sqlite -ot %h/.local/share/microvm/nix-store-db-dump ] || nix-store --dump-db >%h/.local/share/microvm/nix-store-db-dump"
ExecStartPre=ln -f -t %h/.local/share/microvm/vms/%i/persistent/ %h/.local/share/microvm/nix-store-db-dump

The first line dumps the hosts nix database to ~/.local/share/microvm/nix-store-db-dump if the db.sqlite is not older than the dump file.
The second line hard-links the dump into a folder that gets mounted into the VM.

In the microvm flake.nix I got:

              systemd.services.loadnixdb = {
                description = "import hosts nix database";
                path = [pkgs.nix];
                wantedBy = ["multi-user.target"];
                requires = ["nix-daemon.service"];
                script = "cat ${persistencePath}/nix-store-db-dump|nix-store --load-db";
              };

@Dummyc0m
Copy link

Dummyc0m commented Sep 9, 2024

It looks like local-overlay stores have been merged as an experimental feature. https://nix.dev/manual/nix/2.22/store/types/experimental-local-overlay-store

I'm curious if there's any interest/development in the VM guest use case... If no one has tried it yet I might spend a weekend working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants