Certbot+DNS+flake upadte

This commit is contained in:
ari committed 2026-06-01 13:32:35 -04:00
1 parent b23ab9be23
commit acafdbbdd2
20 files changed
+393 -180

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ in
options = {
skyg.home-manager.version = mkOption {
type = types.str;
default = "24.11";
default = "26.05";
description = "The home-manager state version";
};
skyg.home-manager.extraImports = mkOption {
+1 -1
View File
@@ -1,4 +1,4 @@
{ stateVersion ? "24.11" }:
{ stateVersion ? "26.05" }:
let
makeCommonGitConfigs = (import ./git.nix).makeCommonGitConfigs;
programsModule = (import ./programs.nix);
+5 -5
View File
@@ -72,7 +72,7 @@ in
makeNixOs =
{ system ? "x86_64-linux"
, hostName
, systemStateVersion ? "24.05"
, systemStateVersion ? "26.05"
, configuration ? [ ]
}: nixpkgs.lib.nixosSystem {
specialArgs = specialArgs // {
@@ -93,8 +93,8 @@ in
makeIso =
{ system ? "x86_64-linux"
, hostName
, systemStateVersion ? "25.11"
, homeManagerVersion ? "25.11"
, systemStateVersion ? "26.05"
, homeManagerVersion ? "26.05"
, configuration ? [ ]
}: nixpkgs.lib.nixosSystem {
specialArgs = specialArgs // {
@@ -118,8 +118,8 @@ in
makeDarwinModule =
{ system ? "x86_64-darwin"
, user
, homeManagerVersion ? "25.11"
, systemStateVersion ? "25.11"
, homeManagerVersion ? "26.05"
, systemStateVersion ? "26.05"
, hostName
, configuration ? [ ]
}:
+1 -1
View File
@@ -16,6 +16,6 @@
email = lib.mkDefault user.email;
};
skyg.core.hostName = hostName;
skyg.home-manager.version = lib.mkDefault "24.11";
skyg.home-manager.version = lib.mkDefault "26.05";
system.stateVersion = systemStateVersion;
}
+1
View File
@@ -9,5 +9,6 @@
./services
./timers.nix
./dns
./certbot.nix
];
}
@@ -0,0 +1,74 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.skyg.server.dns.certbot;
in
{
options = {
skyg.server.dns.certbot = {
enable = mkEnableOption "Let's Encrypt certificate management with certbot for DNS domains";
publicDomains = mkOption {
description = "List of public domains for which to obtain Let's Encrypt certificates";
type = types.listOf types.str;
default = [ ];
};
email = mkOption {
description = "Email address for Let's Encrypt account registration";
type = types.str;
example = "admin@example.com";
};
testMode = mkOption {
description = "Use certbot in test mode (dry-run) for development/testing";
type = types.bool;
default = false;
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.certbot pkgs.certbot-nginx ];
# Set up systemd service for certificate renewal
systemd.services.certbot-renew = {
description = "Renew Let's Encrypt certificates";
serviceConfig = {
Type = "oneshot";
User = "root";
ExecStart =
if cfg.testMode then
"${pkgs.certbot}/bin/certbot renew --dry-run --nginx"
else
"${pkgs.certbot}/bin/certbot renew --nginx";
};
};
# Set up systemd timer for certificate renewal
systemd.timers.certbot-renew = {
description = "Daily renewal of Let's Encrypt certificates";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
# Enable the renewal timer
systemd.timers.certbot-renew.enable = true;
# Configure nginx with virtual hosts for public domains
services.nginx = {
enable = true;
};
# Create a simple certbot command that can be run manually
environment.shellAliases = {
"certbot-get-certs" =
"${pkgs.certbot}/bin/certbot certonly --nginx --non-interactive --agree-tos --email ${cfg.email} --expand ${concatMapStrings (domain: " --domains ${domain}") cfg.publicDomains}";
};
};
}
+6 -86
View File
@@ -1,88 +1,8 @@
{ config, lib, ... }:
with lib;
let
cfg = config.skyg.server.dns;
# Each { domain, ip } generates both exact and wildcard dnsmasq address entries
addressEntries = concatMap
({ domain, ip }: [
"/${domain}/${ip}"
"/.${domain}/${ip}"
])
cfg.addresses;
in
{ ... }:
{
options = {
skyg.server.dns = {
enable = mkEnableOption "local DNS resolver via dnsmasq";
addresses = mkOption {
description = "Static domain-to-IP mappings. Each entry generates both exact and wildcard dnsmasq address= entries.";
type = types.listOf (types.submodule {
options = {
domain = mkOption { type = types.str; };
ip = mkOption { type = types.str; };
};
});
default = [ ];
};
addressesSecretName = mkOption {
description = ''
Name of an agenix secret whose decrypted content is a dnsmasq config
fragment (address= lines). Included via dnsmasq conf-file. Set null to skip.
'';
type = types.nullOr types.str;
default = null;
example = "dns-addresses.conf";
};
upstreamServers = mkOption {
description = "Upstream DNS servers to forward unresolved queries to.";
type = types.listOf types.str;
default = [ "1.1.1.1" "1.0.0.1" ];
};
listenAddresses = mkOption {
description = "IPs to bind. Empty list means listen on all interfaces (dnsmasq default).";
type = types.listOf types.str;
default = [ ];
};
openFirewall = mkOption {
description = "Open port 53 UDP/TCP in the firewall.";
type = types.bool;
default = false;
};
};
};
config = mkIf cfg.enable {
age.secrets = mkIf (cfg.addressesSecretName != null) {
${cfg.addressesSecretName} = {
file = ../../../../secrets + "/${cfg.addressesSecretName}.age";
};
};
services.dnsmasq = {
enable = true;
settings = {
address = addressEntries;
server = cfg.upstreamServers;
}
// optionalAttrs (cfg.listenAddresses != [ ]) {
listen-address = cfg.listenAddresses;
}
// optionalAttrs (cfg.addressesSecretName != null) {
conf-file = config.age.secrets.${cfg.addressesSecretName}.path;
};
};
networking.firewall = mkIf cfg.openFirewall {
allowedUDPPorts = [ 53 ];
allowedTCPPorts = [ 53 ];
};
};
imports = [
./certbot
./routing
./local-ca
];
}
@@ -0,0 +1,99 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.skyg.server.dns.local-ca;
in
{
options = {
skyg.server.dns.local-ca = {
enable = mkEnableOption "Local Certificate Authority for DNS domains";
caCert = mkOption {
description = "Path to the local CA certificate";
type = types.str;
default = "/etc/ssl/local-ca/cert.pem";
};
caKey = mkOption {
description = "Path to the local CA private key";
type = types.str;
default = "/etc/ssl/local-ca/key.pem";
};
domain = mkOption {
description = "Domain name for the local CA";
type = types.str;
default = "local-ca.skyg.internal";
};
organizationalUnit = mkOption {
description = "Organizational unit for the local CA certificate";
type = types.str;
default = "Skyg Internal CA";
};
organization = mkOption {
description = "Organization for the local CA certificate";
type = types.str;
default = "Skyg";
};
country = mkOption {
description = "Country code for the local CA certificate";
type = types.str;
default = "CA";
};
email = mkOption {
description = "Email address for the local CA";
type = types.str;
default = "admin@skyg.ca";
};
certificateLifetime = mkOption {
description = "Certificate lifetime in days";
type = types.int;
default = 365;
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.openssl ];
# Create directory for local CA
environment.etc."ssl/local-ca" = {
recursive = true;
owner = "root";
group = "root";
mode = "0755";
};
# Create local CA certificate (this would typically be generated by a script)
# For now, we'll just set up the structure and configuration
systemd.services.local-ca-setup = {
description = "Setup local Certificate Authority";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = ''
mkdir -p /etc/ssl/local-ca
# In a real implementation, you would generate the CA certificate here
# openssl req -new -x509 -nodes -days ${toString cfg.certificateLifetime} \
# -subj "/C=${cfg.country}/O=${cfg.organization}/OU=${cfg.organizationalUnit}/CN=${cfg.domain}/emailAddress=${cfg.email}" \
# -keyout ${cfg.caKey} -out ${cfg.caCert}
'';
User = "root";
};
};
# Configuration for services to trust local CA
environment.etc."ssl/certs/ca-certificates.crt".text = ''
# Local CA certificates would be added here
# This is a placeholder for where local CA certs would be included
'';
};
}
@@ -0,0 +1,88 @@
{ config, lib, ... }:
with lib;
let
cfg = config.skyg.server.dns.routing;
# Each { domain, ip } generates both exact and wildcard dnsmasq address entries
addressEntries = concatMap
({ domain, ip }: [
"/${domain}/${ip}"
"/.${domain}/${ip}"
])
cfg.addresses;
in
{
options = {
skyg.server.dns.routing = {
enable = mkEnableOption "local DNS resolver via dnsmasq";
addresses = mkOption {
description = "Static domain-to-IP mappings. Each entry generates both exact and wildcard dnsmasq address= entries.";
type = types.listOf (types.submodule {
options = {
domain = mkOption { type = types.str; };
ip = mkOption { type = types.str; };
};
});
default = [ ];
};
addressesSecretName = mkOption {
description = ''
Name of an agenix secret whose decrypted content is a dnsmasq config
fragment (address= lines). Included via dnsmasq conf-file. Set null to skip.
'';
type = types.nullOr types.str;
default = null;
example = "dns-addresses.conf";
};
upstreamServers = mkOption {
description = "Upstream DNS servers to forward unresolved queries to.";
type = types.listOf types.str;
default = [ "1.1.1.1" "1.0.0.1" ];
};
listenAddresses = mkOption {
description = "IPs to bind. Empty list means listen on all interfaces (dnsmasq default).";
type = types.listOf types.str;
default = [ ];
};
openFirewall = mkOption {
description = "Open port 53 UDP/TCP in the firewall.";
type = types.bool;
default = false;
};
};
};
config = mkIf cfg.enable {
age.secrets = mkIf (cfg.addressesSecretName != null) {
${cfg.addressesSecretName} = {
file = ../../../../secrets + "/${cfg.addressesSecretName}.age";
};
};
services.dnsmasq = {
enable = true;
settings = {
address = addressEntries;
server = cfg.upstreamServers;
}
// optionalAttrs (cfg.listenAddresses != [ ]) {
listen-address = cfg.listenAddresses;
}
// optionalAttrs (cfg.addressesSecretName != null) {
conf-file = config.age.secrets.${cfg.addressesSecretName}.path;
};
};
networking.firewall = mkIf cfg.openFirewall {
allowedUDPPorts = [ 53 ];
allowedTCPPorts = [ 53 ];
};
};
}