Nixos-rebuild switch error: adding a file to tree builder

Hi all,

Run several nixos machines which all largely share the same configuration. However I’m now encountering an issue on one machine which refuses to rebuild (see output below).

[root@aelita:/home/aelita]# nixos-rebuild boot --flake github:TimoVerbrugghe/homelab-monorepo?dir=nixos#aelita --refresh --impure --no-write-lock-file
error:
       … while updating the lock file of flake 'github:TimoVerbrugghe/homelab-monorepo/248850a31b308ca1013d6c60dc56890b679c0274?dir=nixos&narHash=sha256-EJaNmNJXfpIuJu/RWUhNeosI3TxYww7YXQARPTywu5U%3D'

       … while updating the flake input 'nixpkgs'

       … while fetching the input 'github:NixOS/nixpkgs/nixos-24.11'

       error: adding a file to a tree builder: failed to insert entry: invalid object specified - libvirtd.nix

I don’t have a file called libvirtd.nix and I’m not even using libvirtd options…

Configuration.nix & hardware-configuration.nix can be found here: homelab-monorepo/nixos/machines/aelita at master · TimoVerbrugghe/homelab-monorepo · GitHub

Flake.nix here: homelab-monorepo/nixos/flake.nix at baff57724444dcf2152002c86da66d7e3341c2c6 · TimoVerbrugghe/homelab-monorepo · GitHub

Any inputs I use in the flake and files I import in the configuration.nix, I also import/use in some of my other nixos machines and they all rebuild with no issues…

I also built the configuration an another nixos machine and used nix-copy to copy & activate it on the machine encountering errors. That worked and I could verify because nix updated from version 2.24.11 to 2.24.12. But still same issue happening

I’m seeing when I run nix-info -m that nixpkgs is not found?

[root@aelita:/home/aelita]# nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.13.7, NixOS, 24.11 (Vicuna), 24.11.20250320.7105ae3`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.12`
 - nixpkgs: `not found`

Whelp, that’ll be impossible to figure out without having the machine to test on then.

Can you get rid of the --impure? That’ll probably show you whatever is causing the issue, at the very least, even if it won’t be immediately obvious why.

Inscrutable errors like these are generally nix bugs/regressions, which there seem to be a lot of lately…

Use nix 2.18 or lix. In your config, add a line like the following:

nix.package = pkgs.nixVersions.nix_2_18; # or pkgs.lix

Though, I fear, you’ll need that same version of nix on PATH to rebuild your current config:

nix shell github:NixOS/nixpkgs/nixos-24.11#nixVersions.nix_2_18
nixos-rebuild boot <rest of your commmand here>
1 Like

Even with impure, same error:

[root@aelita:/home/aelita]# nixos-rebuild boot --flake github:TimoVerbrugghe/homelab-monorepo?dir=nixos#aelita --refresh --no-write-lock-file
error:
       … while updating the lock file of flake 'github:TimoVerbrugghe/homelab-monorepo/baff57724444dcf2152002c86da66d7e3341c2c6?dir=nixos&narHash=sha256-nnoAT%2BUIyoEPZjL4mUZimKtohnfUsImSLw5JQ5Rul70%3D'

       … while updating the flake input 'nixpkgs'

       … while fetching the input 'github:NixOS/nixpkgs/nixos-24.11'

       error: adding a file to a tree builder: failed to insert entry: invalid object specified - libvirtd.nix
1 Like

Problem here is that even using nix shell gives me the same error:

[root@aelita:/home/aelita]# nix shell github:NixOS/nixpkgs/nixos-24.11#nixVersions.nix_2_18
error:
       … while fetching the input 'github:NixOS/nixpkgs/nixos-24.11'

       error: adding a file to a tree builder: failed to insert entry: invalid object specified - libvirtd.nix

Which is why I built the config on another machine (“yumi” in my configs but in short: very similar setup as “aelita”, same nix version, etc…) and then used nix copy to transfer it over to the machine encountering the error. That worked and it got updated. But even after that update, still same error…

Worst case, I’ll have to destroy machine & rebuild… The config builds on another machine, so some major hiccup happened that I can’t figure out why…

Oh, right, I didn’t consider that that’s also using a flake reference.

nix shell --impure --expr '(import (builtins.fetchTarball "https://channels.nixos.org/nixos-24.11/nixexprs.tar.xz") {}).nixVersions.nix_2_18'

Should get you in a shell with nix 2.18.

EDIT: If even fetchTarball fails…here’s the hackier option.

You can download a static build of lix (sorry, I couldn’t figure out how to provide a hydra link to static nix 2.18) from here:
https://hydra.nixos.org/job/nixpkgs/trunk/lixStatic.x86_64-linux/latest/download-by-type/file/binary-dist

Make sure the file is named nix, rename it if it isn’t, and mark it executable.

Then do something like export PATH="/newpath:$PATH" to temporarily add it to PATH. (where /newpath is the directory containing the file you downloaded).

Then continue with your nixos-rebuild.

That will be a waste of your time, it’s a nix bug, rebuilding the same config with the same nix will lead to the same result.

2 Likes

Thanks for the help on this one @waffle8946. But unfortunately nothing worked :(. Tried nix shell --impure… but same error.

Then I downloaded lix as you suggested, renamed it to nix, changed the path, but still same error. I then tried to do a nix build but using the lix executable:

/home/aelita/nix build github:TimoVerbrugghe/homelab-monorepo?dir=nixos#nixosConfigurations.aelita.config.system.build.toplevel --refresh --impure --no-write-lock-file

But still same error.

So unfortunately, I just built the machine from scratch. Luckily it was a vm, so I set up a new vm, installed the flake onto it, copied files from the previous vm and now everything is working again (nixos-rebuild, nix-shell -p commands, etc…)

So really don’t know what happened here, but this was my only way to resolve it.

Hm, I wonder if the flake eval cache (in ~/.cache/nix) was corrupted? Either way glad it’s resolved.