summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2024-04-10 18:13:45 -0400
committerBen Sima <ben@bsima.me>2024-04-11 09:23:43 -0400
commit5526ce4b19d1dd5bee09f1d274bc88260853485c (patch)
tree3677343dc7a90b4e03e4e2c217837cece08bc51e /Biz
parent544bf574297b5bcca765e9f495a6bace9d9866cd (diff)
Use ccache in builds
Add ccache support to the OsBase definition, so it's automatically setup for all machines. Hopefully this can speed up builds and at least prevent the worst case performance. Unfortunately, if I modify the stdenv of any upstream targets, the cache is invalidated and I have to rebuild the whole package. In particular webkitgtk is a pain to build, and it has crashed my machine a number of times. I was able to build it once, after enabling zram, which should be enabled anyway like why not? - https://nixos.wiki/wiki/CCache - https://github.com/NixOS/nixpkgs/issues/195522#issuecomment-2043999608 - https://github.com/NixOS/nixpkgs/pull/216363#issuecomment-2043998790
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Bild.nix3
-rw-r--r--Biz/Bild/CcacheWrapper.nix57
-rw-r--r--Biz/Bild/Nixpkgs.nix4
-rw-r--r--Biz/OsBase.nix5
4 files changed, 66 insertions, 3 deletions
diff --git a/Biz/Bild.nix b/Biz/Bild.nix
index 077f364..c92f749 100644
--- a/Biz/Bild.nix
+++ b/Biz/Bild.nix
@@ -7,7 +7,8 @@ let
stable = {
inherit (nixpkgs.nixos-23_05)
sources lib makeWrapper ccacheStdenv haskellPackages haskell
- lispPackages_new python3 nixos mkShell dockerTools stdenv;
+ lispPackages_new python3 nixos mkShell dockerTools;
+ stdenv = nixpkgs.nixos-23_05.ccacheStdenv;
};
# for exposing packages as bild.pkgs
diff --git a/Biz/Bild/CcacheWrapper.nix b/Biz/Bild/CcacheWrapper.nix
new file mode 100644
index 0000000..78e5a08
--- /dev/null
+++ b/Biz/Bild/CcacheWrapper.nix
@@ -0,0 +1,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;
+}
diff --git a/Biz/Bild/Nixpkgs.nix b/Biz/Bild/Nixpkgs.nix
index f0e8698..3de56c4 100644
--- a/Biz/Bild/Nixpkgs.nix
+++ b/Biz/Bild/Nixpkgs.nix
@@ -16,7 +16,7 @@ in {
inherit system config;
overlays = [
(_: _: { inherit sources; })
-
+ (import ./CcacheWrapper.nix)
(import ./Functions.nix)
# override pinned deps with our sources, this must come before other
@@ -33,6 +33,7 @@ in {
inherit system config;
overlays = [
(_: _: { inherit sources; })
+ (import ./CcacheWrapper.nix)
(import ./Functions.nix)
(import ./Deps.nix)
];
@@ -42,6 +43,7 @@ in {
inherit system config;
overlays = [
(_: _: { inherit sources; })
+ (import ./CcacheWrapper.nix)
(import ./Functions.nix)
(import ./Deps.nix)
];
diff --git a/Biz/OsBase.nix b/Biz/OsBase.nix
index 50899d2..a9407ab 100644
--- a/Biz/OsBase.nix
+++ b/Biz/OsBase.nix
@@ -1,4 +1,4 @@
-{ pkgs, ... }:
+{ pkgs, config, ... }:
let ports = import ./Cloud/Ports.nix;
in {
boot.tmp.cleanOnBoot = true;
@@ -19,6 +19,8 @@ in {
nix.gc.dates = "Sunday 02:15";
nix.optimise.automatic = true;
nix.optimise.dates = [ "Sunday 02:30" ];
+ nix.settings.extra-sandbox-paths = [ config.programs.ccache.cacheDir ];
+ programs.ccache.enable = true;
programs.mosh.enable = true;
programs.mosh.withUtempter = true;
security.acme.defaults.email = "ben@bsima.me";
@@ -34,4 +36,5 @@ in {
services.openssh.settings.PasswordAuthentication = false;
services.openssh.settings.PermitRootLogin = "prohibit-password";
system.autoUpgrade.enable = false; # 'true' breaks our nixpkgs pin
+ zramSwap.enable = true;
}