nix-serve -> harmonia for nix-cache

This commit is contained in:
Ingolf Wagner 2025-02-14 21:46:45 +13:00
parent 83ef3a0b9b
commit 9a33ca1283
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B

View file

@ -4,12 +4,11 @@
pkgs, pkgs,
... ...
}: }:
let
port = 5005;
in
{ {
# nixpkgs.config.packageOverrides = p: {
# nix-serve = p.haskellPackages.nix-serve-ng;
# };
# generate private key with: # generate private key with:
# nix-store --generate-binary-cache-key my-secret-key my-public-key # nix-store --generate-binary-cache-key my-secret-key my-public-key
clan.core.facts.services."nix-serve" = { clan.core.facts.services."nix-serve" = {
@ -26,34 +25,31 @@
''; '';
}; };
services.nix-serve = { services.harmonia = {
enable = true; enable = true;
secretKeyFile = config.clan.core.facts.services.nix-serve.secret."nix-serve.key".path; signKeyPaths = [ config.clan.core.facts.services.nix-serve.secret."nix-serve.key".path ];
port = 5005; settings = {
bind = "127.0.0.1:${toString port}";
priority = 100;
};
}; };
healthchecks.closed.public.ports.nix-serve = [ config.services.nix-serve.port ]; healthchecks.closed.public.ports.nix-cache = [ port ];
healthchecks.http.nix-serve = { healthchecks.http.nix-cache = {
url = "cache.${config.networking.hostName}.wg0/nix-cache-info"; url = "cache.${config.networking.hostName}.wg0/nix-cache-info";
expectedContent = "Priority: 50"; expectedContent = "Priority: ${toString config.services.harmonia.settings.priority}";
}; };
services.nginx = { services.nginx = {
enable = true; enable = true;
virtualHosts."cache.${config.networking.hostName}.wg0" = { virtualHosts."cache.${config.networking.hostName}.wg0" = {
locations."/".extraConfig = '' locations."/".extraConfig = ''
proxy_pass http://localhost:${toString config.services.nix-serve.port}; proxy_pass http://localhost:${toString port};
allow ${config.wireguard.wg0.subnet}; proxy_set_header Host $host;
deny all; proxy_http_version 1.1;
''; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# curl https://cache.nixos.org/nix-cache-info proxy_set_header Upgrade $http_upgrade;
# lower priority means ask first. proxy_set_header Connection $connection_upgrade;
locations."= /nix-cache-info".extraConfig = ''
alias ${pkgs.writeText "cache-info" ''
StoreDir: /nix/store
WantMassQuery: 1
Priority: 50
''};
allow ${config.wireguard.wg0.subnet}; allow ${config.wireguard.wg0.subnet};
deny all; deny all;
''; '';