2023-03-05 03:50:04 +00:00
|
|
|
{ config, lib, sane-lib, ... }:
|
2023-03-05 01:03:59 +00:00
|
|
|
|
|
|
|
let
|
2023-03-05 06:30:29 +00:00
|
|
|
inherit (lib) mkIf mkMerge mkOption types;
|
|
|
|
inherit (config.programs.ccache) cacheDir;
|
2023-03-05 01:03:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.sane.roles.build-machine = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
2023-03-05 06:30:29 +00:00
|
|
|
config = mkMerge [
|
|
|
|
{
|
2023-03-05 09:24:59 +00:00
|
|
|
# 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}"
|
|
|
|
# '';
|
|
|
|
# };
|
|
|
|
# })
|
|
|
|
# ];
|
2023-03-05 06:30:29 +00:00
|
|
|
}
|
|
|
|
(mkIf config.sane.roles.build-machine {
|
|
|
|
# serve packages to other machines that ask for them
|
|
|
|
sane.services.nixserve.enable = true;
|
2023-03-05 01:03:59 +00:00
|
|
|
|
2023-03-05 06:30:29 +00:00
|
|
|
# enable cross compilation
|
|
|
|
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
|
|
|
|
# nixpkgs.config.allowUnsupportedSystem = true;
|
2023-03-05 03:13:11 +00:00
|
|
|
|
2023-03-05 06:30:29 +00:00
|
|
|
# granular compilation cache
|
|
|
|
# docs: <https://nixos.wiki/wiki/CCache>
|
|
|
|
# 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 <nixpkgs:nixos/modules/programs/ccache.nix>
|
|
|
|
# TODO: configure without compression (leverage fs-level compression), and enable file-clone (i.e. hardlinks)
|
|
|
|
programs.ccache.enable = true;
|
2023-03-05 09:24:59 +00:00
|
|
|
nix.settings.extra-sandbox-paths = [ cacheDir ];
|
2023-03-05 06:30:29 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2023-03-05 01:03:59 +00:00
|
|
|
}
|