Deleting build-vm

For a vm created with nixos-rebuild build-vm. What is the recommended way to clear out that VM?

Ken

1 Like

As in just reset its hard disk? Just delete the qcow2 file. That should be the only state for the VM.

I mean more like make it like it never existed, and clear out the result link and the associated entry in /nix/store

The simple answer: just remove the result link and run garbage collection. This will remove all paths that aren’t reachable from gc roots.

To get an overview of the gc roots:

❯ nix-store --gc --print-roots 

If you only want to delete stuff that a specific build pulled in, you’ll probably have to do some more work, I came up with this:

p=$(readlink result)
rm result
for i in $(nix-store --query --requisites $p); do
  nix-store --delete $i
done

You could probably make this a bit more efficient by filtering nix-store -qR $p with nix-store --gc --print-dead .

3 Likes

That is what I needed. Thank you very much.

Ken