# Help using ccache for kernel build

**URL:** https://discourse.nixos.org/t/help-using-ccache-for-kernel-build/63010
**Category:** Help
**Created:** [April 13, 2025, 1:07pm UTC](https://discourse.nixos.org/t/help-using-ccache-for-kernel-build/63010 "2025-04-13T13:07:45Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![bjackman](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bjackman/32/31928_2.png) [@bjackman](https://discourse.nixos.org/u/bjackman)
#### Post date: [April 16, 2025, 7:31pm UTC](https://discourse.nixos.org/t/help-using-ccache-for-kernel-build/63010/3 "2025-04-16T19:31:26Z")

</div>

OK yeah so I followed the definition of the kernel packages in nixpkgs and it turns out the `buildLinux` function accepts a field called `stdenv`, and if I set that to `pkgs.ccacheStdenv`, it just gets applied directly to the kernel.

The immediate result is a bit confusing, because that wrapper script that’s embedded in the `extraConfig` (omitted in my comment) doesn’t behave anything like a C compiler if it doesn’t see `/var/cache/ccache`, so the kernel build system says “sorry, your C compiler isn’t supported” and you don’t actually get the nice helpful error message.

Anyway, once I created it and set `extra-sandbox-paths = /var/cache/ccache` in `/etc/nix/nix.conf`, it started building the kernel. Weirdly, the ccache statistics don’t show much happening:

```auto
❯❯ CCACHE_DIR=/var/cache/ccache sudo ccache -s
Local storage:
  Cache size (GiB): 0.0 / 5.0 ( 0.00%)

```

But I can see files appearing in `/var/cache/ccache`… so hopefully something is working.

So yeah, some remaining awkwardness, i.e. now my flake won’t compile without setup on the build host, and in that case it prints an extremely unhelpful message. But, it seems like it should be achievable to make the ccache usage optional, and print a more helpful message. In the meantime maybe I have something that Works On My Machine.

[Here’s the commit](https://github.com/bjackman/nixos-flake/commit/7240412673140d8bccd43e0d32823dc1813e7e16) where I _think_ I got things working.

---

_[View the full topic](https://discourse.nixos.org/t/help-using-ccache-for-kernel-build/63010)._
