2 { lib, config, hostName, ... }:
4 inherit (config.security) gnupg;
5 inherit (config.services) nginx nix-serve;
6 inherit (config.users) users groups;
10 nix.settings.trusted-users = [ users."nix-serve".name ];
11 users.users."nix-serve" = {
13 group = groups."nix-serve".name;
14 extraGroups = [ groups."keys".name ];
16 users.groups."nix-serve" = { };
17 security.gnupg.secrets."nix/binary-cache-key/1" = {
18 user = users."nix-serve".name;
20 before = [ "nix-serve.service" ];
21 wantedBy = [ "nix-serve.service" ];
24 services.nix-serve = {
26 secretKeyFile = gnupg.secrets."nix/binary-cache-key/1".path;
27 bindAddress = "127.0.0.1";
29 nix.settings.allowed-users = [ users."nix-ssh".name ];
32 keys = users."julm".openssh.authorizedKeys.keys;
35 systemd.services.nginx.after = [ "wireguard-wg-intra.service" ];
38 virtualHost = priority:
41 #access_log /var/log/nginx/${domain}/${srv}/access.json json buffer=32k;
42 #error_log /var/log/nginx/${domain}/${srv}/error.log warn;
44 error_log /dev/null crit;
46 locations."/nix-cache-info" = {
47 # cache.nixos.org has priority 40
48 return = ''200 "StoreDir: ${builtins.storeDir}\nWantMassQuery: 1\nPriority: ${toString priority}\n"'';
50 ${nginx.configs.https_add_headers}
51 add_header Content-Type text/plain;
54 locations."/".extraConfig = ''
55 proxy_pass http://localhost:${toString nix-serve.port};
56 proxy_set_header Host $host;
57 proxy_set_header X-Real-IP $remote_addr;
58 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
63 # cache.nixos.org has priority over extracache
64 virtualHosts."nix-extracache.${hostName}.wg" = virtualHost 60 // {
65 listenAddresses = [ "nix-extracache.${hostName}.wg" ];
68 # localcache has priority over cache.nixos.org
69 virtualHosts."nix-localcache.${hostName}.wg" = virtualHost 30 // {
70 listenAddresses = [ "nix-localcache.${hostName}.wg" ];
74 systemd.services.nginx = {
76 LogsDirectory = lib.mkForce [ "nginx/${domain}/${srv}" ];