blob: 76824697a5294a5e93379ddb76bc54724bf83cda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.eth.sites.go;
mkLocation = virtualHost: module: url: {
name = "/${module}";
value = {
extraConfig = ''
if ($args = "go-get=1") {
add_header Content-Type text/html;
return 200 '<meta name="go-import" content="${virtualHost}/${module} git ${url}">';
}
return 302 ${url};
'';
};
};
in {
options.eth.sites.go = {
enable = mkEnableOption "Whether to enable the Go site.";
https = mkOption {
type = types.bool;
default = true;
description = "Whether to enable HTTPS.";
};
virtualHost = mkOption {
type = types.str;
default = "_";
description = "Virtual Host to install the site under in Nginx.";
example = "go.eth.moe";
};
modules = mkOption {
type = types.attrsOf types.str;
description = "A set of modules and their underlying git repos.";
example = { catbus = "https://git.eth.moe/go-catbus"; };
};
};
config = mkIf cfg.enable {
services.nginx.virtualHosts.${cfg.virtualHost} = {
forceSSL = cfg.https;
enableACME = cfg.https;
locations = listToAttrs (mapAttrsToList (mkLocation cfg.virtualHost) cfg.modules);
};
};
}
|