Really low CCache hit rates when overriding a package

Hi! I have a package that I’ve overridden to build from a local source tree. I’ve gotten it to build, and now I’m trying to speed up recompilation for small changes to the code, using CCache.

The build is indeed using CCache, but the hit rate is 0.35% in my tests which just change a string literal in one file. Can this be improved?

For context this is the kdeconnect-kde package that I’m overriding, from kdePackages. It’s a CMake project, written in C++ and using Qt.

Also nix-ccache --show-stats says that ~70% of all calls were cacheable, so it’s not that most calls are uncacheable. They’re just missing. The cache isn’t full or anything either. This makes me think maybe I’m doing it wrong.

The overlays I’m using:

  nixpkgs.overlays = [
    # from https://nixos.wiki/wiki/CCache
    (self: super: {
      ccacheWrapper = super.ccacheWrapper.override {
      extraConfig = ''
          export CCACHE_COMPRESS=1
          export CCACHE_DIR="${config.programs.ccache.cacheDir}"
          export CCACHE_UMASK=007
          if [ ! -d "$CCACHE_DIR" ]; then
          echo "====="
          echo "Directory '$CCACHE_DIR' does not exist"
          echo "Please create it with:"
          echo "  sudo mkdir -m0770 '$CCACHE_DIR'"
          echo "  sudo chown root:nixbld '$CCACHE_DIR'"
          echo "====="
          exit 1
          fi
          if [ ! -w "$CCACHE_DIR" ]; then
          echo "====="
          echo "Directory '$CCACHE_DIR' is not accessible for user $(whoami)"
          echo "Please verify its access permissions"
          echo "====="
          exit 1
          fi
      '';
      };
    })

    (final: prev: {
      kdePackages = prev.kdePackages.overrideScope (kfinal: kprev: {
        kdeconnect-kde = kprev.kdeconnect-kde.overrideAttrs (oldAttrs: {
          src = builtins.fetchGit /home/bharadwaj/dev/kde/kdeconnect-kde;
        });
      });
    })

    (final: prev: {
      kdePackages = prev.kdePackages.overrideScope (kfinal: kprev: {
        kdeconnect-kde = kprev.kdeconnect-kde.override { mkKdeDerivation = kprev.mkKdeDerivation.override { stdenv = prev.ccacheStdenv; }; };
      });
    })
  ];
1 Like

I tested out ccache a couple of years ago and found that I needed to add these to get any kind of decent hit rate:

export CCACHE_NOHASHDIR=true
export CCACHE_BASEDIR="$NIX_BUILD_TOP"

Don’t ask me how I determined that or what it means, because I’ve long forgotten :stuck_out_tongue:

1 Like

Thank you! This made the hit rate improve to 1.71% now, which is better but still way too slow for what I hoped to use this for.

3 Likes

Thank you, this was it. With this the hit rate is now 99.66%.

1 Like