nixos-config/machines/orbi/service-nix-cache.nix

63 lines
1.7 KiB
Nix
Raw Normal View History

2024-08-29 03:26:04 +02:00
{
config,
lib,
pkgs,
...
}:
2024-07-20 13:56:03 +02:00
{
# nixpkgs.config.packageOverrides = p: {
# nix-serve = p.haskellPackages.nix-serve-ng;
# };
# generate private key with:
# nix-store --generate-binary-cache-key my-secret-key my-public-key
clan.core.facts.services."nix-serve" = {
secret."nix-serve.key" = { };
public."nix-serve.pub" = { };
2024-08-29 03:26:04 +02:00
generator.path = with pkgs; [
coreutils
nix
];
2024-07-20 13:56:03 +02:00
generator.script = ''
nix-store --generate-binary-cache-key "cache.${config.networking.hostName}.wg0" nix-serve.key nix-serve.pub
mv nix-serve.key "$secrets"/nix-serve.key
mv nix-serve.pub "$facts"/nix-serve.pub
'';
};
services.nix-serve = {
enable = true;
secretKeyFile = config.clan.core.facts.services.nix-serve.secret."nix-serve.key".path;
port = 5005;
};
healthchecks.closed.public.ports.nix-serve = [ config.services.nix-serve.port ];
healthchecks.http.nix-serve = {
2024-09-16 02:06:03 +02:00
url = "cache.${config.networking.hostName}.wg0/nix-cache-info";
expectedContent = "Priority: 50";
};
2024-07-20 13:56:03 +02:00
services.nginx = {
enable = true;
virtualHosts."cache.${config.networking.hostName}.wg0" = {
locations."/".extraConfig = ''
proxy_pass http://localhost:${toString config.services.nix-serve.port};
allow ${config.wireguard.wg0.subnet};
deny all;
'';
2024-09-11 05:34:52 +02:00
# curl https://cache.nixos.org/nix-cache-info
# lower priority means ask first.
2024-07-20 13:56:03 +02:00
locations."= /nix-cache-info".extraConfig = ''
alias ${pkgs.writeText "cache-info" ''
StoreDir: /nix/store
WantMassQuery: 1
2024-09-11 05:34:52 +02:00
Priority: 50
2024-07-20 13:56:03 +02:00
''};
allow ${config.wireguard.wg0.subnet};
deny all;
'';
};
};
}