1 { config, pkgs, lib, ... }:
5 cfg = config.programs.ccache;
7 options.programs.ccache = {
9 enable = mkEnableOption (lib.mdDoc "CCache");
12 description = lib.mdDoc "CCache directory";
13 default = "/var/cache/ccache";
15 # target configuration
16 packageNames = mkOption {
17 type = types.listOf types.str;
18 description = lib.mdDoc "Nix top-level packages to be compiled using CCache";
20 example = [ "wxGTK32" "ffmpeg" "libav_all" ];
27 systemd.tmpfiles.rules = [ "d ${cfg.cacheDir} 0770 root nixbld -" ];
29 # "nix-ccache --show-stats" and "nix-ccache --clear"
30 security.wrappers.nix-ccache = {
35 source = pkgs.writeScript "nix-ccache.pl" ''
36 #!${pkgs.perl}/bin/perl
38 %ENV=( CCACHE_DIR => '${cfg.cacheDir}' );
41 return '-C' if $v eq '-C' || $v eq '--clear';
42 return '-V' if $v eq '-V' || $v eq '--version';
43 return '-s' if $v eq '-s' || $v eq '--show-stats';
44 return '-z' if $v eq '-z' || $v eq '--zero-stats';
45 exec('${pkgs.ccache}/bin/ccache', '-h');
47 exec('${pkgs.ccache}/bin/ccache', map { untaint $_ } @ARGV);
52 # target configuration
53 (mkIf (cfg.packageNames != []) {
55 (self: super: genAttrs cfg.packageNames (pn: super.${pn}.override { stdenv = builtins.trace "with ccache: ${pn}" self.ccacheStdenv; }))
58 ccacheWrapper = super.ccacheWrapper.override {
60 export CCACHE_COMPRESS=1
61 export CCACHE_DIR="${cfg.cacheDir}"
62 export CCACHE_UMASK=007
63 if [ ! -d "$CCACHE_DIR" ]; then
65 echo "Directory '$CCACHE_DIR' does not exist"
66 echo "Please create it with:"
67 echo " sudo mkdir -m0770 '$CCACHE_DIR'"
68 echo " sudo chown root:nixbld '$CCACHE_DIR'"
72 if [ ! -w "$CCACHE_DIR" ]; then
74 echo "Directory '$CCACHE_DIR' is not accessible for user $(whoami)"
75 echo "Please verify its access permissions"