diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-01 21:56:57 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-01 21:56:57 +0100 |
commit | 4d10fbcad9f9a730a776f3eb197cb4821c9f6edc (patch) | |
tree | 063f6903526c8a31c32c57d3a9952d6283f93e57 | |
parent | 66ee0051417702eab280d158bc5c39387d672bd0 (diff) |
create eth.sites.go for a go "vanity import" site
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/sites/go.nix | 52 |
2 files changed, 53 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0fd6318..8aff9af 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -9,6 +9,7 @@ ./programs/steam.nix ./services/ambience.nix ./services/catbus-lgtv.nix + ./sites/go.nix ./services/catbus-lifx.nix ./services/catbus-networkpresence.nix ./services/catbus-snapcast.nix diff --git a/nixos/modules/sites/go.nix b/nixos/modules/sites/go.nix new file mode 100644 index 0000000..7682469 --- /dev/null +++ b/nixos/modules/sites/go.nix @@ -0,0 +1,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); + }; + }; +} |