1
Fork 0

Better octodns file structure

This commit is contained in:
prescientmoon 2024-10-13 02:34:34 +02:00
parent 190dde841e
commit 35bc79265c
Signed by: prescientmoon
SSH key fingerprint: SHA256:WFp/cO76nbarETAoQcQXuV+0h7XJsEsOCI0UsyPIy6U
33 changed files with 219 additions and 381 deletions

View file

@ -9,15 +9,3 @@ This directory contains custom module definitions used throughout my config.
| [common](./common) | Modules usable in both HM and nixos (and perhaps other places) |
| [nixos](./nixos) | Nixos specific functionality |
| [home-manager](./home-manager) | Home manager specific functionality |
## Common modules
| Name | Attribute | Description |
| ----------------------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------- |
| [toggles](./common/toggles.nix) | `satellite.toggles` | Generic interface for feature flags |
| [lua-lib](./common/lua-lib.nix) | `satellite.lib.lua` | Helpers for working with lua code |
| [korora-lua](./common/korora-lua.nix) | - | Nix -> lua encoder typechecked using [korora](https://github.com/adisbladis/korora) |
| [korora-neovim](./common/korora-neovim.nix) | - | Nix -> neovim config helpers typechecked using [korora](https://github.com/adisbladis/korora) |
| [theming](./common/theming.nix) | `satellite.theming` | [stylix](https://github.com/danth/stylix) theming helpers and configuration |
| [lua-colorscheme](./common/lua-colorscheme.nix) | `satellite.colorscheme.lua` | Base16 theme to lua module generation |
| [octodns](./common/octodns.nix) | `satellite.dns.octodns` | Octodns config generation |

View file

@ -10,11 +10,3 @@
| [korora-neovim](korora-neovim.nix) | - | Nix -> neovim config helpers |
| [theming](theming.nix) | `satellite.theming` | Stylix theming helpers |
| [lua-colorscheme](lua-colorscheme.nix) | `satellite.colorscheme.lua` | Base16 theme -> lua |
## Other modules
These are special-purpose modules that are used for other purposes
| Name | Attribute | Description |
| ---------------------- | ----------------------- | ------------------------- |
| [octodns](octodns.nix) | `satellite.dns.octodns` | Octodns config generation |

View file

@ -1,48 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
format = pkgs.formats.yaml { };
cfg = config.satellite.dns;
in
{
options.satellite.dns.octodns = lib.mkOption {
description = "Derivation building a directory containing all the zone files";
type = lib.types.path;
};
config.satellite.dns.octodns =
let
grouped = builtins.groupBy (entry: entry.zone) cfg.records;
cpLines = lib.mapAttrsToList (
zone: group:
let
grouped = builtins.groupBy (entry: entry.at) group;
contents = lib.mapAttrs (
at: entries:
lib.lists.forEach entries (
entry:
let
content =
if builtins.typeOf entry.value == "list" then
{ values = entry.value; }
else
{ inherit (entry) value; };
cloudflare = if entry.enableCloudflareProxy then { octodns.cloudflare.proxied = true; } else { };
in
{ inherit (entry) ttl type; } // content // cloudflare
)
) grouped;
file = format.generate "${zone}.yaml" contents;
in
"cp ${file} $out/${zone}.yaml"
) grouped;
in
pkgs.runCommand "octodns-zones" { } ''
mkdir $out
${lib.concatStringsSep "\n" cpLines}
'';
}

View file

@ -1,11 +1,9 @@
# Nixos modules
| Name | Attribute | Description |
| ------------------------------------ | ----------------------- | ------------------------------------ |
| [pounce](pounce.nix) | `services.pounce` | Pounce & calico configuration |
| [nginx](nginx.nix) | `satellite.nginx` | Nginx configuration |
| [ports](ports.nix) | `satellite.ports` | Global port specification |
| [cloudflared](cloudflared.nix) | `satellite.cloudflared` | Cloudflare tunnel configuration |
| [pilot](pilot.nix) | `satellite.pilot` | Defines the concept of a "main user" |
| [dns](dns.nix) | `satellite.dns` | DNS record creation |
| [dns-assertions](dns-assertions.nix) | `satellite.dns` | DNS record validation |
| Name | Attribute | Description |
| ------------------------------ | ----------------------- | ------------------------------------ |
| [pounce](pounce.nix) | `services.pounce` | Pounce & calico configuration |
| [nginx](nginx.nix) | `satellite.nginx` | Nginx configuration |
| [ports](ports.nix) | `satellite.ports` | Global port specification |
| [cloudflared](cloudflared.nix) | `satellite.cloudflared` | Cloudflare tunnel configuration |
| [pilot](pilot.nix) | `satellite.pilot` | Defines the concept of a "main user" |

View file

@ -7,6 +7,4 @@
nginx = ./nginx.nix;
pilot = ./pilot.nix;
pounce = ./pounce.nix;
dns = ./dns.nix;
dns-assertions = ./dns-assertions.nix;
}

View file

@ -1,17 +0,0 @@
# This must only be loaded on actual Nixos, otherwise `assertions`
# won't be defined when running `evaluateModules`.
{ config, ... }:
let cfg = config.satellite.dns;
in
{
config.assertions =
let assertProperToUsage = config:
{
assertion = (config.to == null) || (config.type == "CNAME");
message = ''
The option `satellite.dns.records[*].to` can only be used with `CNAME` records.
This was not the case for ${config.type} record at ${config.at}.${config.zone}.
'';
};
in builtins.map assertProperToUsage cfg.records;
}

View file

@ -1,76 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
format = pkgs.formats.yaml { };
cfg = config.satellite.dns;
in
{
options.satellite.dns = {
domain = lib.mkOption {
description = "Default zone to include records in";
type = lib.types.str;
};
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;
};
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";
};
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";
};
ttl = lib.mkOption {
type = lib.types.int;
description = "The TTL assigned to the record";
default = 300;
};
enableCloudflareProxy = lib.mkEnableOption "proxying using cloudflare";
};
config.value = lib.mkIf (
config.type == "CNAME" && config.to != null
) "${config.to}.${config.zone}.";
}
)
);
};
};
}