CCache system wide?

This depends on what it is you’re building. If you’re building an entire NixOS closure because you’re modifying stdenv (or something close to it) anyways, you would use the ccacheStdenv by default via Nixpkgs’ config.replaceStdenv argument. See https://github.com/NixOS/nixpkgs/blob/e24c4f8cbbf4b03999c0b1d4d48b148e75ace1b5/pkgs/top-level/all-packages.nix#L17670-L17672

This will, of course, result in a world rebuild.

If you only build a few leaf packages as part of a NixOS closure, use the ccache module and declare their attribute names in programs.ccache.packageNames.