Skip to content

Commit 2efa94d

Browse files
committed
feat: serve the local store and fallback to the s3 bucket if it 404's
1 parent 34d9e30 commit 2efa94d

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
!hosts/
88

99
!hosts/best/
10+
!hosts/best/cache/
1011
!hosts/best/garage/
11-
!hosts/best/nix-serve/
1212
!hosts/best/hercules/
1313

1414
!hosts/cube/

hosts/best/cache.nix

Lines changed: 0 additions & 18 deletions
This file was deleted.

hosts/best/cache/default.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ self, config, lib, pkgs, ... }: let
2+
inherit (config.networking) domain;
3+
inherit (lib) enabled merge;
4+
5+
fqdn = "cache.${domain}";
6+
7+
portNixServe = 8006;
8+
in {
9+
imports = [(self + /modules/nginx.nix)];
10+
11+
secrets.nixServeKey = {
12+
file = ./key.age;
13+
owner = "nix-serve";
14+
};
15+
16+
services.nix-serve = enabled {
17+
package = pkgs.nix-serve-ng;
18+
secretKeyFile = config.secrets.nixServeKey.path;
19+
20+
# Not ::1 because nix-serve doesn't like that.
21+
bindAddress = "127.0.0.1";
22+
port = portNixServe;
23+
};
24+
25+
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate {
26+
extraConfig = /* nginx */ ''
27+
proxy_intercept_errors on;
28+
error_page 404 = @fallback;
29+
'';
30+
31+
locations."= /".return = "301 https://${domain}/404";
32+
33+
locations."/".proxyPass = "http://127.0.0.1:${toString portNixServe}";
34+
35+
locations."@fallback" = {
36+
extraConfig = /* nginx */ ''
37+
proxy_set_header Host "hercules.${config.services.garage.settings.s3_web.root_domain}";
38+
'';
39+
40+
proxyPass = "http://${config.services.garage.settings.s3_web.bind_addr}";
41+
};
42+
};
43+
}

hosts/best/cache/key.age

426 Bytes
Binary file not shown.

rebuild.nu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def main --wrapped [
2222
}
2323

2424
if $host != (hostname) {
25+
ssh -q -tt $host $"
26+
rm -rf ncc
27+
"
28+
2529
git ls-files
2630
| sync --files-from - ./ ($host + ":ncc")
2731

secrets.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ in {
55
"hosts/best/id.age".publicKeys = [ best ] ++ admins;
66
"hosts/best/password.the.age".publicKeys = [ best ] ++ admins;
77

8+
"hosts/best/cache/key.age".publicKeys = [ best ] ++ admins;
9+
810
"hosts/best/garage/environment.age".publicKeys = [ best ] ++ admins;
911

1012
"hosts/best/hercules/caches.age".publicKeys = [ best ] ++ admins;

0 commit comments

Comments
 (0)