nixos_config/hosts/blogbox/configuration.nix

116 lines
2.9 KiB
Nix
Raw Normal View History

2025-08-26 14:00:14 +02:00
{ config, pkgs, ... }:
2025-09-24 18:23:45 +02:00
let
hugoDir = "/home/alisceon/blog";
in
2025-08-26 14:00:14 +02:00
{
imports =
[ ./hardware-configuration.nix ];
networking.hostName = "blogbox";
boot.initrd.enable = true;
boot.loader = {
systemd-boot = {
enable = true;
}; # end loader.systemd-boot
}; # end boot
networking.firewall = {
enable = true;
allowedTCPPorts = [ 22 80 443 ];
allowedUDPPorts = [ 443 ];
};
2025-09-24 18:23:45 +02:00
environment = {
systemPackages = with pkgs; [
hugo
caddy
ddclient
]; # end systemPackages
}; # end environment
2025-08-26 14:00:14 +02:00
systemd = {
services = {
"pull-blog" = {
2025-09-24 18:23:45 +02:00
wantedBy = [ "multi-user.target" ];
2025-08-26 14:00:14 +02:00
script = ''
2025-09-24 18:23:45 +02:00
git pull origin main
hugo
2025-08-26 14:00:14 +02:00
'';
serviceConfig = {
type = "oneshot";
2025-09-24 18:23:45 +02:00
user = "alisceon";
workingDirectory = hugoDir;
}; # end serviceConfig
}; # end pull-blog
"ddclient" = {
description = "Dynamic DNS client";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.ddclient}/bin/ddclient -foreground -file /etc/blogbox/ddclient.conf";
Restart = "on-failure";
User = "root";
EnvironmentFile = "/etc/blogbox/.env";
}; # end serviceConfig
}; # end ddclient
}; # end services
2025-08-26 14:00:14 +02:00
timers = {
"pull-blog" = {
wantedBy = [ "timers.target" ];
timerConfig = {
2025-09-24 18:23:45 +02:00
OnBootSec = "5min";
OnUnitActiveSec = "5min";
2025-08-26 14:00:14 +02:00
Persistent = true;
2025-09-24 18:23:45 +02:00
}; # end timerConfig
}; # end pull-blog
"ddclient" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5min";
OnUnitActiveSec = "5min";
Persistent = true;
}; # end timerConfig
}; # end ddclient
}; # end timers
}; # end systemd
services= {
caddy = {
enable = true;
environmentFile = "/etc/blogbox/.env";
virtualHosts = {
"blog" = {
hostName = "${DOMAIN}";
forceSSL = true;
root = "${hugoDir}/public";
index = "index.html";
log = [ "stdout" "stderr" ];
fileServer = { };
tls = {
email = ""
}; # end tls
}; # end {$DOMAIN}
}; # end virtualHosts
}; # end caddy
}; # end services.caddy
2025-08-26 14:00:14 +02:00
environment = {
etc = {
2025-09-24 18:23:45 +02:00
"blogbox/ddclient.conf" = {
text = ''
use=web, web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login_env=DOMAIN
password_env=DDNS_PASSWORD
@
'';
mode = "600";
2025-08-26 14:00:14 +02:00
};
2025-09-24 18:23:45 +02:00
"blogbox/.env.example" = {
text = ''
HUGO_DIR=${hugoDir}
HUGO_ENV=production
DOMAIN=example.com
DDNS_PASSWORD=yourpassword
NAMECHEAP_API_KEY=yourapikey
'';
2025-08-26 14:00:14 +02:00
mode = "600";
2025-09-24 18:23:45 +02:00
};
2025-08-26 14:00:14 +02:00
}; # end etc
};
} # end file