summaryrefslogtreecommitdiff
path: root/Biz/Bild/CcacheWrapper.nix
blob: 78e5a08501c9cae21d0c1e7f25cc2aeb2c8f0c53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
self: super:

let
  # this should come from config.programs.ccache.cacheDir but I can't figure out
  # how to access that from a nixpkgs overlay, so just hardcode the default
  ccacheDir = "/var/cache/ccache";

  # https://github.com/NixOS/nixpkgs/pull/216363#issuecomment-1430356886
  fixwebkit = pkg:
    self.useCcacheStdenv (pkg.overrideAttrs (attrs: rec {
      preConfigure = attrs.preConfigure + ''
        # not sure which of these works so just do them both
        export NUMBER_OF_PROCESSORS=$NIX_BUILD_CORES
        ninjaFlagsArray+=("-l$NIX_BUILD_CORES")
      '';
    }));
in {
  ccacheWrapper = super.ccacheWrapper.override {
    extraConfig = ''
      export CCACHE_COMPRESS=1
      export CCACHE_DIR="${ccacheDir}"
      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
    '';
  };

  useCcacheStdenv = pkg: pkg.override { stdenv = super.ccacheStdenv; };

  cudann = self.useCcacheStdenv super.cudann;
  llvm = self.useCcacheStdenv super.llvm;
  magma = self.useCcacheStdenv super.magma;
  nvcc = self.useCcacheStdenv super.nvcc;
  onnx = self.useCcacheStdenv super.onnx;
  onnxruntime = self.useCcacheStdenv super.onnxruntime;
  webkit = fixwebkit super.webkit;
  webkitgtk = fixwebkit super.webkitgtk;
  webkitgtk_4_1 = fixwebkit super.webkitgtk_4_1;
  webkitgtk_5_0 = fixwebkit super.webkitgtk_5_0;
  webkitgtk_6_0 = fixwebkit super.webkitgtk_6_0;
}