From a56b31cdac546ea3f5e88aaf640de3ee4795719d Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 5 Mar 2023 09:24:59 +0000 Subject: [PATCH] get moby packages to selectively use ccache this is a liiittle bit weird: we might want to just apply it to everything. --- flake.nix | 2 +- hosts/common/cross/default.nix | 2 +- hosts/modules/roles/build-machine.nix | 42 +++++++++----------- nixpatches/2023-03-04-ccache-cross-fix.patch | 40 ++++++++++++++++++- overlays/optimizations.nix | 4 +- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/flake.nix b/flake.nix index e887e79c..2c6fc7bb 100644 --- a/flake.nix +++ b/flake.nix @@ -95,7 +95,7 @@ self.overlays.default self.overlays.passthru self.overlays.pins - self.overlays.optimizations + # self.overlays.optimizations ]; nixpkgs.hostPlatform = target; # nixpkgs.buildPlatform = local; # set by instantiate.nix instead diff --git a/hosts/common/cross/default.nix b/hosts/common/cross/default.nix index 2c74fe4c..0fca46c5 100644 --- a/hosts/common/cross/default.nix +++ b/hosts/common/cross/default.nix @@ -101,7 +101,7 @@ let # because they don't affect the result -- only the build process -- so we can disable them as an optimization. crossOnlyUniversalOverlays = [ (import ./../../../overlays/disable-flakey-tests.nix) - # (import ./../../../overlays/optimizations.nix) + (import ./../../../overlays/optimizations.nix) ]; universalOverlays = [ (import ./../../../overlays/pkgs.nix) diff --git a/hosts/modules/roles/build-machine.nix b/hosts/modules/roles/build-machine.nix index 4f445777..d47ab232 100644 --- a/hosts/modules/roles/build-machine.nix +++ b/hosts/modules/roles/build-machine.nix @@ -12,7 +12,23 @@ in config = mkMerge [ { - nix.settings.extra-sandbox-paths = [ cacheDir ]; + # programs.ccache.cacheDir = "/var/cache/ccache"; # nixos default + # programs.ccache.cacheDir = "/homeless-shelter/.ccache"; # ccache default (~/.ccache) + + # if the cache doesn't reside at ~/.ccache, then CCACHE_DIR has to be set. + # we can do that manually as commented out below, or let nixos do it for us by telling it to use ccache on a dummy package: + programs.ccache.packageNames = [ "dummy-pkg-to-force-ccache-config" ]; + # nixpkgs.overlays = [ + # (self: super: { + # # XXX: if the cache resides not at ~/.ccache (i.e. /homeless-shelter/.ccache) + # # then we need to explicitly tell ccache where that is. + # ccacheWrapper = super.ccacheWrapper.override { + # extraConfig = '' + # export CCACHE_DIR="${cacheDir}" + # ''; + # }; + # }) + # ]; } (mkIf config.sane.roles.build-machine { # serve packages to other machines that ask for them @@ -31,35 +47,13 @@ in # TODO: whitelist `--verbose` in # TODO: configure without compression (leverage fs-level compression), and enable file-clone (i.e. hardlinks) programs.ccache.enable = true; - programs.ccache.cacheDir = "/homeless-shelter/.ccache"; + nix.settings.extra-sandbox-paths = [ cacheDir ]; sane.persist.sys.plaintext = [ { group = "nixbld"; mode = "0775"; directory = config.programs.ccache.cacheDir; } ]; sane.fs."${cacheDir}/ccache.conf" = sane-lib.fs.wantedText '' max_size = 50G ''; - - nixpkgs.overlays = [ - (self: super: { - # TODO: if we link /homeless-shelter/.ccache into the nix environment, - # then maybe we get better use of upstream caches? - ccacheWrapper = super.ccacheWrapper.override { - extraConfig = '' - export CCACHE_DIR="${cacheDir}" - ''; - }; - }) - ]; - # programs.ccache.packageNames = [ - # # these have to exist in toplevel package set: - # # nixpkgs config creates an overlay which overrides each of these packages to build with ccache - # # note a potential bootstrapping problem: if the cache directory above hasn't yet been created, then this blocks deployment. - # # solution is to manually disable all these entries on the first deployment - # # TODO: distribute these elsewhere; make sure it works on cross-compiled builds - # "firefox-esr" - # # "qtwebengine" - # "webkitgtk" - # ]; }) ]; } diff --git a/nixpatches/2023-03-04-ccache-cross-fix.patch b/nixpatches/2023-03-04-ccache-cross-fix.patch index 5d81e109..5248d7c5 100644 --- a/nixpatches/2023-03-04-ccache-cross-fix.patch +++ b/nixpatches/2023-03-04-ccache-cross-fix.patch @@ -1,5 +1,5 @@ diff --git a/pkgs/development/tools/misc/ccache/default.nix b/pkgs/development/tools/misc/ccache/default.nix -index cad25a942d6..d02d212cec0 100644 +index cad25a942d6..9130097ab07 100644 --- a/pkgs/development/tools/misc/ccache/default.nix +++ b/pkgs/development/tools/misc/ccache/default.nix @@ -2,7 +2,7 @@ @@ -20,3 +20,41 @@ index cad25a942d6..d02d212cec0 100644 }) ]; +@@ -71,7 +71,7 @@ let ccache = stdenv.mkDerivation rec { + passthru = { + # A derivation that provides gcc and g++ commands, but that + # will end up calling ccache for the given cacheDir +- links = {unwrappedCC, extraConfig}: stdenv.mkDerivation { ++ links = {unwrappedCC, extraConfig, targetPrefix ? ""}: stdenv.mkDerivation { + name = "ccache-links"; + passthru = { + isClang = unwrappedCC.isClang or false; +@@ -83,7 +83,7 @@ let ccache = stdenv.mkDerivation rec { + mkdir -p $out/bin + + wrap() { +- local cname="$1" ++ local cname="${targetPrefix}$1" + if [ -x "${unwrappedCC}/bin/$cname" ]; then + makeWrapper ${ccache}/bin/ccache $out/bin/$cname \ + --run ${lib.escapeShellArg extraConfig} \ +diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix +index cb6fd2f0c4d..da4aadff3cb 100644 +--- a/pkgs/top-level/all-packages.nix ++++ b/pkgs/top-level/all-packages.nix +@@ -17383,10 +17383,12 @@ with pkgs; + # should be owned by user root, group nixbld with permissions 0770. + ccacheWrapper = makeOverridable ({ extraConfig, cc }: + cc.override { +- cc = ccache.links { ++ cc = ccache.links ({ + inherit extraConfig; + unwrappedCC = cc.cc; +- }; ++ } // lib.optionalAttrs (cc ? targetPrefix) { ++ inherit (cc) targetPrefix; ++ }); + }) { + extraConfig = ""; + inherit (stdenv) cc; + diff --git a/overlays/optimizations.nix b/overlays/optimizations.nix index 1901e387..e143544f 100644 --- a/overlays/optimizations.nix +++ b/overlays/optimizations.nix @@ -16,7 +16,9 @@ in { # export CCACHE_DIR="/homeless-shelter/.ccache" # ''; # }; - firefox-esr = ccache-able super.firefox-esr; + # firefox-esr = ccache-able super.firefox-esr; + # firefox/librewolf distribution is wacky: it grabs the stdenv off of `rustc.llvmPackages`, and really wants those to match. + # buildMozillaMach = opts: ccache-able (super.buildMozillaMach opts); webkitgtk = ccache-able super.webkitgtk; mesa = ccache-able super.mesa; # webkitgtk = (ccache-able super.webkitgtk).overrideAttrs (_upstream: {