{ config, lib, sane-lib, ... }: let inherit (lib) mkIf mkMerge mkOption types; inherit (config.programs.ccache) cacheDir; in { options.sane.roles.build-machine = mkOption { type = types.bool; default = false; }; config = mkMerge [ { # 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 sane.services.nixserve.enable = true; # enable cross compilation # TODO: do this via stdenv injection, linking into /run/binfmt the stuff in boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; # corresponds to env var: NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 # nixpkgs.config.allowUnsupportedSystem = true; # granular compilation cache # docs: # investigate the cache with: # - `nix-ccache --show-stats` # - `build '.#ccache' # - `sudo CCACHE_DIR=/var/cache/ccache ./result/bin/ccache --show-stats -v` # TODO: whitelist `--verbose` in # TODO: configure without compression (leverage fs-level compression), and enable file-clone (i.e. hardlinks) programs.ccache.enable = true; 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 ''; }) ]; }