List-generations throws error: file 'nixos-config' was not found

When running the command nixos-rebuild list-generations throws this error

building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/store/cbbsvzjcqvzlylq9s7p6d2gyxh64q88p-source/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/cbbsvzjcqvzlylq9s7p6d2gyxh64q88p-source/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

How do I fix this? It is only happening on one of my machines. It was happening on my first NixOS machine and then it stopped and I cannot remember what might have resolved it.

Now it is happening on my second NixOS machine and I have no idea why.

1 Like

Having the exact same problem, but despite the error, the generations are shown correctly after it’s dismissed

1 Like

Having this same problem too. Started happening a few weeks ago. No idea why.

Don’t hesitate to open an issue yourself when you experience such an issue, and remember to cc the maintainer. Just opened nixos-rebuild list-generations is buggy · Issue #302267 · NixOS/nixpkgs · GitHub .