2024-12-11 21:58:48 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2024-12-15 23:13:11 +00:00
|
|
|
let
|
|
|
|
port = 8082;
|
|
|
|
in
|
2024-12-11 21:58:48 +00:00
|
|
|
{
|
|
|
|
options.features.homelab.pihole.enable = mkEnableOption "Enable pihole";
|
|
|
|
|
|
|
|
config = mkIf config.features.homelab.pihole.enable {
|
|
|
|
virtualisation = {
|
|
|
|
docker = {
|
|
|
|
enable = true;
|
|
|
|
autoPrune.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
oci-containers = {
|
|
|
|
backend = "docker";
|
|
|
|
|
|
|
|
containers."pihole" = {
|
|
|
|
image = "pihole/pihole:latest";
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
"TZ" = "Europe/London";
|
|
|
|
};
|
|
|
|
|
|
|
|
volumes = [
|
2024-12-30 10:33:03 +00:00
|
|
|
"/home/opdavies/pihole/etc-dnsmasq.d:/etc/dnsmasq.d:rw"
|
|
|
|
"/home/opdavies/pihole/etc-pihole:/etc/pihole:rw"
|
2024-12-11 21:58:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
ports = [
|
|
|
|
"53:53/tcp"
|
|
|
|
"53:53/udp"
|
|
|
|
"67:67/udp"
|
2024-12-15 23:13:11 +00:00
|
|
|
"${toString port}:80/tcp"
|
2024-12-11 21:58:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
log-driver = "journald";
|
|
|
|
|
|
|
|
extraOptions = [
|
|
|
|
"--cap-add=NET_ADMIN"
|
|
|
|
"--network-alias=pihole"
|
|
|
|
"--network=pihole_default"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
services = {
|
|
|
|
"docker-pihole" = {
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = lib.mkOverride 90 "always";
|
|
|
|
RestartMaxDelaySec = lib.mkOverride 90 "1m";
|
|
|
|
RestartSec = lib.mkOverride 90 "100ms";
|
|
|
|
RestartSteps = lib.mkOverride 90 9;
|
|
|
|
};
|
|
|
|
|
|
|
|
after = [ "docker-network-pihole_default.service" ];
|
|
|
|
requires = [ "docker-network-pihole_default.service" ];
|
|
|
|
partOf = [ "docker-compose-pihole-root.target" ];
|
|
|
|
wantedBy = [ "docker-compose-pihole-root.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
"docker-network-pihole_default" = {
|
|
|
|
path = [ pkgs.docker ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStop = "docker network rm -f pihole_default";
|
|
|
|
};
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
docker network inspect pihole_default || docker network create pihole_default
|
|
|
|
'';
|
|
|
|
|
|
|
|
partOf = [ "docker-compose-pihole-root.target" ];
|
|
|
|
wantedBy = [ "docker-compose-pihole-root.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
targets."docker-compose-pihole-root" = {
|
|
|
|
unitConfig = {
|
|
|
|
Description = "Root target generated by compose2nix.";
|
|
|
|
};
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."pihole.localhost" = {
|
2024-12-15 23:13:11 +00:00
|
|
|
locations."/".proxyPass = "http://localhost:${toString port}/";
|
2024-12-11 21:58:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|