2 { pkgs, lib, config, inputs, hostName, ... }:
4 inherit (config) networking;
5 inherit (config.security) gnupg;
6 inherit (config.services) nginx nix-serve;
7 inherit (config.users) users groups;
11 nix.settings.trusted-users = [ users."nix-serve".name ];
12 users.users."nix-serve" = {
14 group = groups."nix-serve".name;
15 extraGroups = [ groups."keys".name ];
17 users.groups."nix-serve" = {};
18 security.gnupg.secrets."nix/binary-cache-key/1" = {
19 user = users."nix-serve".name;
21 before = [ "nix-serve.service" ];
22 wantedBy = [ "nix-serve.service" ];
25 services.nix-serve = {
27 secretKeyFile = gnupg.secrets."nix/binary-cache-key/1".path;
28 bindAddress = "127.0.0.1";
30 nix.settings.allowed-users = [ users."nix-ssh".name ];
33 keys = users."julm".openssh.authorizedKeys.keys;
36 systemd.services.nginx.after = ["wireguard-wg-intra.service"];
37 services.nginx = let virtualHost = priority:
40 #access_log /var/log/nginx/${domain}/${srv}/access.json json buffer=32k;
41 #error_log /var/log/nginx/${domain}/${srv}/error.log warn;
43 error_log /dev/null crit;
45 locations."/nix-cache-info" = {
46 # cache.nixos.org has priority 40
47 return = ''200 "StoreDir: ${builtins.storeDir}\nWantMassQuery: 1\nPriority: ${toString priority}\n"'';
49 ${nginx.configs.https_add_headers}
50 add_header Content-Type text/plain;
53 locations."/".extraConfig = ''
54 proxy_pass http://localhost:${toString nix-serve.port};
55 proxy_set_header Host $host;
56 proxy_set_header X-Real-IP $remote_addr;
57 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
61 # cache.nixos.org has priority over extracache
62 virtualHosts."nix-extracache.${hostName}.wg" = virtualHost 60 // {
63 listenAddresses = [ "nix-extracache.${hostName}.wg" ];
66 # localcache has priority over cache.nixos.org
67 virtualHosts."nix-localcache.${hostName}.wg" = virtualHost 30 // {
68 listenAddresses = [ "nix-localcache.${hostName}.wg" ];
72 systemd.services.nginx = {
74 LogsDirectory = lib.mkForce ["nginx/${domain}/${srv}"];