How to update grub entries with NixOS config built with nix-build


I’ve taken the plunge recently into NixOS, and one of the things that bothered
me and I’m taking steps to remedy is the dependence of the system
configuration on external state like environment variables, nix-channels etc.

I created a self-contained configuration out of a bunch of nix expressions and
it builds fine with nix-build and works when switching to it via
result/bin/switch-to-configuration switch. Also settings it as the default
for the profile with sudo nix-env --profile /nix/var/nix/profiles/system --set ./result.

The only problem is that the grub entries are not updated. It seems that
nixos-rebuild switch does more than what I described above. I tried looking
at the nixos-rebuild bash script but could not find any clues to that extra
step. What can I do to force updating the grub entries? One ugly hack is
to run nixos-rebuild switch with any configuration just to force an update,
and it works, but I would prefer a different way of solving this.

Any help is greatly appreciated! Thanks!


As a side note (not crucial, but just for the record), I also tried setting
NIX_PATH to point back to the nix expression which I’m using to pin nixpkgs
for my system configuration, and to point /etc/nixos/configuration.nix to my
self-contained configuration, and it seems to not work due to option
__ignoreNulls not being defined which I have no idea how to tackle. Trying
to build an ultra simple configuration works and does not get the
__ignoreNulls error so at least I know that the redirections are fine.
Anyways, This approach is not ideal as I depend on an environment variable.

Solved it.

My mistake was that I first did the switch-to-configuration and then the system profile set, while the nixos-rebuild did it in the opposite order.

Doing it in the opposite order, like nixos-rebuild does, updated the grub entries with the latest configuration.