Fix octodns setup
This commit is contained in:
parent
78198f18b2
commit
404f6c8d3e
10 changed files with 238 additions and 178 deletions
modules/nixos
|
@ -85,6 +85,7 @@ in
|
|||
at = subdomain;
|
||||
zone = cfg.domain;
|
||||
value = "${cfg.tunnel}.cfargotunnel.com.";
|
||||
enableCloudflareProxy = true;
|
||||
};
|
||||
in
|
||||
lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at;
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
format = pkgs.formats.yaml { };
|
||||
cfg = config.satellite.dns;
|
||||
|
@ -13,47 +18,59 @@ in
|
|||
records = lib.mkOption {
|
||||
description = "List of records to create";
|
||||
default = [ ];
|
||||
type = lib.types.listOf (lib.types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
at = lib.mkOption {
|
||||
description = "Subdomain to use for entry";
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
};
|
||||
type = lib.types.listOf (
|
||||
lib.types.submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
at = lib.mkOption {
|
||||
description = "Subdomain to use for entry";
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
};
|
||||
|
||||
zone = lib.mkOption {
|
||||
description = "Zone this record is a part of";
|
||||
type = lib.types.str;
|
||||
default = cfg.domain;
|
||||
};
|
||||
zone = lib.mkOption {
|
||||
description = "Zone this record is a part of";
|
||||
type = lib.types.str;
|
||||
default = cfg.domain;
|
||||
};
|
||||
|
||||
type = lib.mkOption {
|
||||
type = lib.types.enum [ "A" "AAAA" "TXT" "CNAME" "MX" ];
|
||||
description = "The type of the DNS record";
|
||||
};
|
||||
type = lib.mkOption {
|
||||
type = lib.types.enum [
|
||||
"A"
|
||||
"AAAA"
|
||||
"TXT"
|
||||
"CNAME"
|
||||
"MX"
|
||||
];
|
||||
description = "The type of the DNS record";
|
||||
};
|
||||
|
||||
to = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = "Shorthand for CNMAE-ing to a subdomain of the given zone";
|
||||
default = null;
|
||||
};
|
||||
to = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = "Shorthand for CNMAE-ing to a subdomain of the given zone";
|
||||
default = null;
|
||||
};
|
||||
|
||||
value = lib.mkOption {
|
||||
type = format.type;
|
||||
description = "The value assigned to the record, in octodns format";
|
||||
};
|
||||
value = lib.mkOption {
|
||||
type = format.type;
|
||||
description = "The value assigned to the record, in octodns format";
|
||||
};
|
||||
|
||||
ttl = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
description = "The TTL assigned to the record";
|
||||
default = 300;
|
||||
};
|
||||
ttl = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
description = "The TTL assigned to the record";
|
||||
default = 300;
|
||||
};
|
||||
|
||||
enableCloudflareProxy = lib.mkEnableOption "proxying using cloudflare";
|
||||
};
|
||||
enableCloudflareProxy = lib.mkEnableOption "proxying using cloudflare";
|
||||
};
|
||||
|
||||
config.value = lib.mkIf (config.type == "CNAME" && config.to != null)
|
||||
"${config.to}.${config.zone}.";
|
||||
}));
|
||||
config.value = lib.mkIf (
|
||||
config.type == "CNAME" && config.to != null
|
||||
) "${config.to}.${config.zone}.";
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{ config, lib, ... }:
|
||||
let cfg = config.satellite.nginx;
|
||||
let
|
||||
cfg = config.satellite.nginx;
|
||||
in
|
||||
{
|
||||
options.satellite.nginx = {
|
||||
|
@ -11,88 +12,102 @@ in
|
|||
|
||||
at = lib.mkOption {
|
||||
description = "Per-subdomain nginx configuration";
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, config, ... }: {
|
||||
options.subdomain = lib.mkOption {
|
||||
description = ''
|
||||
Subdomain to use for host generation.
|
||||
Only required if `host` is not set manually.
|
||||
'';
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, config, ... }:
|
||||
{
|
||||
options.subdomain = lib.mkOption {
|
||||
description = ''
|
||||
Subdomain to use for host generation.
|
||||
Only required if `host` is not set manually.
|
||||
'';
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
|
||||
options.host = lib.mkOption {
|
||||
description = "Host to route requests from";
|
||||
type = lib.types.str;
|
||||
};
|
||||
options.host = lib.mkOption {
|
||||
description = "Host to route requests from";
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
config.host = "${config.subdomain}.${cfg.domain}";
|
||||
config.host = "${config.subdomain}.${cfg.domain}";
|
||||
|
||||
options.url = lib.mkOption {
|
||||
description = "External https url used to access this host";
|
||||
type = lib.types.str;
|
||||
};
|
||||
options.url = lib.mkOption {
|
||||
description = "External https url used to access this host";
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
config.url = "https://${config.host}";
|
||||
config.url = "https://${config.host}";
|
||||
|
||||
options.port = lib.mkOption {
|
||||
description = "Port to proxy requests to";
|
||||
type = lib.types.nullOr lib.types.port;
|
||||
default = null;
|
||||
};
|
||||
options.port = lib.mkOption {
|
||||
description = "Port to proxy requests to";
|
||||
type = lib.types.nullOr lib.types.port;
|
||||
default = null;
|
||||
};
|
||||
|
||||
options.files = lib.mkOption {
|
||||
description = "Path to serve files from";
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
};
|
||||
}));
|
||||
options.files = lib.mkOption {
|
||||
description = "Path to serve files from";
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
assertions =
|
||||
let assertSingleTarget = config:
|
||||
{
|
||||
let
|
||||
assertSingleTarget = config: {
|
||||
assertion = (config.port == null) == (config.files != null);
|
||||
message = ''
|
||||
Precisely one of the options 'satellite.nginx.at.${config.subdomain}.port'
|
||||
and 'satellite.nginx.at.${config.subdomain}.files' must be specified.
|
||||
'';
|
||||
};
|
||||
in lib.mapAttrsToList (_: assertSingleTarget) cfg.at;
|
||||
in
|
||||
lib.mapAttrsToList (_: assertSingleTarget) cfg.at;
|
||||
|
||||
services.nginx.virtualHosts =
|
||||
let mkNginxConfig = { host, port, files, ... }: {
|
||||
name = host;
|
||||
value =
|
||||
let extra =
|
||||
if port != null then {
|
||||
locations."/" = {
|
||||
proxyPass = "http://localhost:${toString port}";
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
let
|
||||
mkNginxConfig = args: {
|
||||
name = args.host;
|
||||
value =
|
||||
let
|
||||
extra =
|
||||
if args.port != null then
|
||||
{
|
||||
locations."/" = {
|
||||
proxyPass = "http://localhost:${toString args.port}";
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
}
|
||||
else
|
||||
{ root = args.files; };
|
||||
in
|
||||
{
|
||||
enableACME = true;
|
||||
acmeRoot = null;
|
||||
forceSSL = true;
|
||||
}
|
||||
else {
|
||||
root = files;
|
||||
};
|
||||
in
|
||||
{
|
||||
enableACME = true;
|
||||
acmeRoot = null;
|
||||
forceSSL = true;
|
||||
} // extra;
|
||||
};
|
||||
in lib.attrsets.mapAttrs' (_: mkNginxConfig) cfg.at;
|
||||
// extra;
|
||||
};
|
||||
in
|
||||
lib.attrsets.mapAttrs' (_: mkNginxConfig) cfg.at;
|
||||
|
||||
satellite.dns.records =
|
||||
let mkDnsRecord = { subdomain, ... }: {
|
||||
type = "CNAME";
|
||||
zone = cfg.domain;
|
||||
at = subdomain;
|
||||
to = "${config.networking.hostName}.${cfg.domain}.";
|
||||
};
|
||||
in lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at;
|
||||
let
|
||||
mkDnsRecord =
|
||||
{ subdomain, ... }:
|
||||
{
|
||||
type = "CNAME";
|
||||
zone = cfg.domain;
|
||||
at = subdomain;
|
||||
to = config.networking.hostName;
|
||||
};
|
||||
in
|
||||
lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue