Flakes and filterSource

I have flake structured like this

    overlay=final: prev:{
      a=final.Package calling b;

I’m modifying a package such that only flake.nix get changed,not the other source files,creating spurious rebuilding of b.I’ve tried to replace b.src with a filterSource that excludes flake.nix (on the reasoning that if the changes to it would need a rebuild,itwould already change the drv) but apparently filterSource is not supported in restricted mode.Why?

Could you try src = self;? That seemed to work for me, but I haven’t looked into the details to verify what it is doing.

No,the problem is that I’m editing the a expression in flake.nix but b keeps recompiling as it depends on the source flake itself

Also I’ve tried to replace src=self with

src = with builtins;filterSource(path: type: 
          null!=match "flake.*" path

But I’ve still got error

error: string '/nix/store/cw25vzzrmlhn16alzi5dgvadjkpfhb0p-source' cannot refer to other paths, at /nix/store/cw25vzzrmlhn16alzi5dgvadjkpfhb0p-source/flake.nix:65:29

Ah, you are right. I have src = self; and I tried making a trivial change to my flake.nix file, a newline, and it rebuilds my package.

Currently, the derivation b depends on the whole repository flake belongs to. To avoid that you need to filter the source. Normally you could use filterSource but not with flakes. When you use filterSource in a flake (you need to pass ./. instead of self, since the latter will coerce to a string with a context), you will realize that b will still keep rebuilding when flake.nix changed. This is because the name of the directory created by filterSource will depend on the initial directory, which will change when flake.nix does. The solution is to use builtins.path and explicitly specify the name. See How to make `src = ./.` in a flake.nix not change a lot? for more details.