]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/nginx/sourcephile.fr/nix-serve.nix
losurdo: improve X11 and Bluetooth support
[sourcephile-nix.git] / hosts / losurdo / nginx / sourcephile.fr / nix-serve.nix
1 { domain, ... }:
2 { pkgs, lib, config, hostName, ... }:
3 let
4 inherit (config) networking;
5 inherit (config.security) gnupg;
6 inherit (config.services) nginx nix-serve;
7 inherit (config.users) users groups;
8 srv = "nix-serve";
9 in
10 {
11 nix.trustedUsers = [ users."nix-serve".name ];
12 users.users."nix-serve".extraGroups = [ groups."keys".name ];
13 security.gnupg.secrets."nix/binary-cache-key/1" = {
14 user = users."nix-serve".name;
15 systemdConfig = {
16 before = [ "nix-serve.service" ];
17 wantedBy = [ "nix-serve.service" ];
18 };
19 };
20 services.nix-serve = {
21 enable = true;
22 secretKeyFile = gnupg.secrets."nix/binary-cache-key/1".path;
23 bindAddress = "127.0.0.1";
24 };
25 services.nginx = let vhostConfig = priority:
26 {
27 #onlySSL = true;
28 #addSSL = true;
29 forceSSL = true;
30 useACMEHost = domain;
31 extraConfig = ''
32 #access_log /var/log/nginx/${domain}/${srv}/access.log json buffer=32k;
33 #error_log /var/log/nginx/${domain}/${srv}/error.log warn;
34 access_log off;
35 error_log /dev/null crit;
36 '';
37 locations."/nix-cache-info" = {
38 # cache.nixos.org has priority 40
39 return = ''200 "StoreDir: ${builtins.storeDir}\nWantMassQuery: 1\nPriority: ${toString priority}\n"'';
40 extraConfig = ''
41 ${nginx.configs.https_add_headers}
42 add_header Content-Type text/plain;
43 '';
44 };
45 locations."/".extraConfig = ''
46 proxy_pass http://localhost:${toString nix-serve.port};
47 proxy_set_header Host $host;
48 proxy_set_header X-Real-IP $remote_addr;
49 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
50 '';
51 };
52 in {
53 virtualHosts."nix-localcache.${domain}" = vhostConfig 30;
54 virtualHosts."nix-extracache.${domain}" = vhostConfig 60 // {
55 serverAliases = [ "${srv}.${domain}" ];
56 };
57 };
58 systemd.services.nginx = {
59 serviceConfig = {
60 LogsDirectory = lib.mkForce ["nginx/${domain}/${srv}"];
61 };
62 };
63 }