How do I rebuild with nix-build

I’m a bit confused.

When I try to build it again, it just prompts and doesn’t build my Raspberry Pi image

nix-build  '<nixpkgs/nixos>' -A -I nixos-config=./rpi4-image.nix

I tried to search and found a —rebuild flag, but that was for “nix build” and not “nix-build” and still, that didn’t rebuild it either;)

Do I really need the --rebuild to rebuild the image when I change the nix file?

If so, then how do I rebuild?:wink:

If the build completes immediately, then whatever change you made didn’t change the evaluation and resulting derivation. Aka, it is building the image you requested, it just happens to already be built.

Generally you don’t really ever, ever need to use --rebuild unless you’re dealing with a flaky build failure (even then, you shouldn’t need it), or if you’re trying to check reproducibility by building again.

That all said, --rebuild will generally trigger a rebuild, but it might only be of the toplevel derivation which might be like a simple compression for the pi image, etc.

There’s no easy way to rebuild everything in the dependency graph for the derivation you’re trying to rebuild. nix build nixpkgs#hello --rebuild will only build hello-world for example, it won’t rebuild glibc, or gcc (the inputs).

If you want that to happen, a quick way to do it is:

  • nix build nixpkgs#hello --store ./tmpstore --substituters ""

Nix bugs notwithstanding, this should truly rebuild everything in the dependency graph from source once again, in a new nix store without any substituters, make sure to get rid of ./tmpstore when you’re done as it may take up a ton of space.

Welp, looks like there’s nix bugs, but it should work in the future when fixed :smiley: