buzz working
This commit is contained in:
1 parent
8ef626a16b
commit
217b122c67
9 files changed
+204
-20
No files matched your search
@@ -12,6 +12,7 @@ server/
|
||||
├── admin.nix # skyg.server.admin — www-data group/user for shared web data
|
||||
├── exporters.nix # skyg.server.exporters — Prometheus node exporter (:9100)
|
||||
├── timers.nix # skyg.server.timers — generic attrset → systemd timer+oneshot service
|
||||
├── acme/ # skyg.server.acme — Let's Encrypt certs via DNS-01 (lego), no internet exposure
|
||||
├── arrs/ # *arr media-automation stack (prowlarr/sonarr/radarr) + postgres
|
||||
├── dns/ # Local DNS resolver, certbot, local CA
|
||||
├── k3s/ # Single-binary K3s cluster role
|
||||
@@ -36,6 +37,7 @@ server/
|
||||
skyg.server.admin.enable → admin.nix
|
||||
skyg.server.exporters.enable → exporters.nix
|
||||
skyg.server.timers.<name> → timers.nix
|
||||
skyg.server.acme.* → acme/
|
||||
skyg.server.arrs.* → arrs/
|
||||
skyg.server.dns.* → dns/
|
||||
skyg.nixos.server.k3s.* → k3s/
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# modules/nixos/server/acme/
|
||||
|
||||
Let's Encrypt certificates via **DNS-01**, wrapped around NixOS
|
||||
`security.acme` (lego) with this repo's conventions. Domain ownership is
|
||||
proven through DNS records at the provider, so **nothing needs to be
|
||||
reachable from the internet** — no port forwards, no public listeners.
|
||||
|
||||
## Options (`skyg.server.acme.*`)
|
||||
|
||||
| Option | Default | Purpose |
|
||||
| ------------------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `enable` | `false` | Master switch, per host. |
|
||||
| `email` | `admin@sosnovsky.ca` | Let's Encrypt account contact (expiry notices). |
|
||||
| `dnsProvider` | `"cloudflare"` | lego DNS provider name (see lego docs). |
|
||||
| `credentialsFile` | — | Env file with provider API credentials (e.g. `CLOUDFLARE_DNS_API_TOKEN=...`). Point at an agenix secret — never the Nix store. |
|
||||
| `certs."<domain>"` | `{ }` | One block per certificate; the attribute name is the primary domain. |
|
||||
| `certs.*.extraDomains` | `[ ]` | Extra names on the same cert (SANs). |
|
||||
| `certs.*.reloadServices` | `[ ]` | Native systemd services reloaded after each renewal. |
|
||||
| `certs.*.postRun` | `""` | Shell command after each renewal (e.g. `docker restart <container>` for compose stacks). |
|
||||
| `certs.*.orderBefore` | `[ ]` | `systemd.services` attribute names (no `.service` suffix) that start only after the cert exists (first boot — otherwise Docker bind-mounts empty dirs over the missing cert files). |
|
||||
|
||||
## Usage
|
||||
|
||||
```nix
|
||||
age.secrets.cloudflare-dns.file = ../secrets/cloudflare-dns.age;
|
||||
skyg.server.acme = {
|
||||
enable = true;
|
||||
credentialsFile = config.age.secrets.cloudflare-dns.path;
|
||||
certs."app.home.sosnovsky.ca" = {
|
||||
postRun = "${pkgs.docker}/bin/docker restart my-stack-caddy-1";
|
||||
orderBefore = [ "container-services-my-stack" ];
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Certs land in `/var/lib/acme/<domain>/` (`fullchain.pem`, `key.pem`, …),
|
||||
renewed automatically by the `acme-<domain>.service` timer; hooks run after
|
||||
each renewal. The secret contains one line: `CLOUDFLARE_DNS_API_TOKEN=<token>`
|
||||
(token scope: Zone → DNS → Edit, restricted to the one zone).
|
||||
|
||||
## ⚠ Cloudflare zone lives elsewhere (for now)
|
||||
|
||||
The `sosnovsky.ca` zone and the Cloudflare account/API token are managed in
|
||||
`~/Projects/Homelab/homelab` (Terraform `tf-dns.tf`, cert-manager) until
|
||||
DNS/SSL management migrates into this repo. When that migration happens, only
|
||||
the token's provenance changes — this module is unaffected.
|
||||
|
||||
## Notes
|
||||
|
||||
- Supersedes `skyg.server.dns.certbot` (HTTP-01 + nginx, disabled) for hosts
|
||||
that are not publicly reachable. The certbot module is left untouched.
|
||||
- For internal-only services whose clients all use the system trust store,
|
||||
the lab CA (`skyg ca`, see `configs/pki/ABOUTME.md`) is the simpler option —
|
||||
no public name needed.
|
||||
@@ -0,0 +1,99 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.skyg.server.acme;
|
||||
in
|
||||
{
|
||||
# Let's Encrypt certificates via DNS-01 (NixOS security.acme / lego).
|
||||
# Proves domain ownership through DNS records at the provider — nothing
|
||||
# needs to be reachable from the internet.
|
||||
options.skyg.server.acme = {
|
||||
enable = mkEnableOption "Let's Encrypt certificates via DNS-01";
|
||||
|
||||
email = mkOption {
|
||||
type = types.str;
|
||||
default = "admin@sosnovsky.ca";
|
||||
description = "Contact email for the Let's Encrypt account (expiry notices).";
|
||||
};
|
||||
|
||||
dnsProvider = mkOption {
|
||||
type = types.str;
|
||||
default = "cloudflare";
|
||||
description = "lego DNS provider used to prove ownership (see lego docs for names).";
|
||||
};
|
||||
|
||||
credentialsFile = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
File with the DNS provider's API credentials in lego's env-var format
|
||||
(e.g. CLOUDFLARE_DNS_API_TOKEN=... for cloudflare). Point at an agenix
|
||||
secret so the token never enters the Nix store.
|
||||
'';
|
||||
};
|
||||
|
||||
certs = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
extraDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Extra names covered by the same certificate (SANs).";
|
||||
};
|
||||
reloadServices = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Native systemd services reloaded after each renewal.";
|
||||
};
|
||||
postRun = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "Shell command run after each renewal (e.g. restart a container).";
|
||||
};
|
||||
orderBefore = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
systemd.services attribute names (without the .service suffix)
|
||||
that must start only after this cert exists (first boot).
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
description = "Certificates to issue; the attribute name is the primary domain.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
security.acme = {
|
||||
acceptTerms = true;
|
||||
defaults.email = cfg.email;
|
||||
certs = mapAttrs
|
||||
(domain: certCfg: {
|
||||
inherit (cfg) dnsProvider;
|
||||
environmentFile = cfg.credentialsFile;
|
||||
extraDomainNames = certCfg.extraDomains;
|
||||
reloadServices = certCfg.reloadServices;
|
||||
postRun = certCfg.postRun;
|
||||
})
|
||||
cfg.certs;
|
||||
};
|
||||
|
||||
# First-boot ordering: consumers start only after the cert exists.
|
||||
systemd.services = mkMerge (flatten (
|
||||
mapAttrsToList
|
||||
(domain: certCfg:
|
||||
map
|
||||
(unit: {
|
||||
${unit} = {
|
||||
after = [ "acme-${domain}.service" ];
|
||||
wants = [ "acme-${domain}.service" ];
|
||||
};
|
||||
})
|
||||
certCfg.orderBefore)
|
||||
cfg.certs
|
||||
));
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
imports = [
|
||||
./exporters.nix
|
||||
./admin.nix
|
||||
./acme
|
||||
./arrs
|
||||
./k8s
|
||||
./k3s
|
||||
|
||||
Reference in new issue
Block a user