Flake doesn't respect change in python version - only partially replicable

I’m having an issue with certain flakes for building packages/shells on my machine that I cannot fully replicate, but nethertheless it happens.

On packages I’ve been working on, sometimes the version of python I’m using (defined in the flake) gets stuck when either entering a development shell or building a package.

I have something like this (note I’ve tried without flake-utils as a debug test):

{
	description = "A very basic flake";

	inputs = {
		nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
		flake-utils.url = "github:numtide/flake-utils";
	};


	outputs = { self, nixpkgs, flake-utils, ... }:
		flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" ] (system:
			let
				pkgs = import nixpkgs { inherit system; };
				python-interp = pkgs.python38;
			in
			{
				devShells.default = pkgs.mkShell {
					buildInputs = with pkgs; [ python-interp ];
				};
			});
}

If you change the python-interp value to a different python version (e.g. python311), then ordinarily this is fine and works. However, when a particular build directory has ended up with this issue, it no longer respects changing. What’s weird even further is that when using nix repl it shows the derivation has the proper python38. This also happens when building packages.

I recorded an asciinema of it happening: python version change - asciinema

Any thoughts on what’s going on? Or how to try and diagnose further?

What happens if you commit all your changes, and do a nix flake update?

Just tried and the behaviour doesn’t change…