Force full redownload and rebuild with nix-build

Is there a way to force a re-fetchFromGitHub and rebuild (completely clean rebuild) using nix-build? Basically I’ve noticed a few situations where the package sources are not pulled properly, for example when I forget to add the fetchSubmodules flag or when I change the version to clone. (Also sometimes when I just want to do a rebuild to 100% verify that that the package file is correct and I’m not being fooled by cached results.)

The only way I have found to trigger it manually is to corrupt the sha256 hash, but surely there is a better way? The build command I am using is:

nix-build -v --keep-failed -E "with import <nixpkgs> {}; callPackage ./default.nix {}"

You can either change the name of the fixed output derivation, change its hash or delete the output store path from your nix store to force a rebuild (although in the latter case the path may be substituted from binary caches still).

There’s no flag to invalidate fixed output derivations I’m aware of.

This is the normal way. If two fixed-output derivations have the same name and the same hash, Nix assumes they’re literally the same thing as far as their results go. If they weren’t, they wouldn’t have the same hash, right? It’s an optimization that’s nice for avoiding massive rebuilds when the means for performing the download have changed but the expected results haven’t.

I do appreciate the optimisation, but I had hoped there was a --force or --rebuild option so it can be selectively triggered.

I think the problem is also ergonomics; Fixed output derivations are rarely built directly, but usually as dependencies of other derivations. So the question is, what should --rebuild do? If it meant refetch all fixed output derivations, it’d (at least) refetch everything from the stdenv bootstrap tarball.