From 3ed8cb071a87134dd8749316a2e0fa6fd85c8dcd Mon Sep 17 00:00:00 2001
From: Dmitriy Kholkin <ataraxiadev@ataraxiadev.com>
Date: Tue, 16 Jul 2024 14:50:57 +0300
Subject: [PATCH] enable ccache

---
 machines/AMD-Workstation/default.nix |  2 +-
 profiles/ccache.nix                  | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 profiles/ccache.nix

diff --git a/machines/AMD-Workstation/default.nix b/machines/AMD-Workstation/default.nix
index 74b4532..c93f3e3 100644
--- a/machines/AMD-Workstation/default.nix
+++ b/machines/AMD-Workstation/default.nix
@@ -17,7 +17,7 @@
     customProfiles.wine-games
 
     customProfiles.ollama
-  ];
+    customProfiles.ccache
 
   security.pki.certificateFiles = [ ../../misc/mitmproxy-ca-cert.pem ];
 
diff --git a/profiles/ccache.nix b/profiles/ccache.nix
new file mode 100644
index 0000000..2606884
--- /dev/null
+++ b/profiles/ccache.nix
@@ -0,0 +1,28 @@
+{ config, lib, ... }: {
+  programs.ccache = {
+    enable = true;
+    cacheDir = "/var/lib/ccache";
+    # packageNames = [ "grub2" ];
+  };
+  nix.settings.extra-sandbox-paths = [ config.programs.ccache.cacheDir ];
+
+  persist.state.directories = lib.mkIf (config.deviceSpecific.devInfo.fileSystem != "zfs") [
+    config.programs.ccache.cacheDir
+  ];
+
+  nixpkgs.overlays = [
+    (final: prev: {
+      ccacheWrapper = prev.ccacheWrapper.override {
+        # export CCACHE_SLOPPINESS=random_seed,pch_defines,time_macros,include_file_mtime,include_file_ctime
+        extraConfig = ''
+          export CCACHE_NOCOMPRESS=true
+          export CCACHE_MAXSIZE=15G
+          export CCACHE_DIR="${config.programs.ccache.cacheDir}"
+          export CCACHE_UMASK=007
+          export CCACHE_SLOPPINESS=random_seed
+          export CCACHE_BASEDIR=$NIX_BUILD_TOP
+        '';
+      };
+    })
+  ];
+}