Skip to content

Commit

Permalink
feat(nix): make dns rewrites in module
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Nov 15, 2024
1 parent 48ac310 commit 2bb4808
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 45 deletions.
11 changes: 2 additions & 9 deletions nix/modules/nixos/containers/authelia/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ in {
url = "http://${cfg.localAddress}:9091";
middleware = "secure-headers";
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
];

config = mkIf cfg.enable {
Expand Down Expand Up @@ -148,14 +150,5 @@ in {
system.stateVersion = "24.11";
};
};

containers.adguard.config.services.adguardhome.settings.filtering.rewrites =
lib.mkIf config.${namespace}.containers.adguard.enable
[
{
domain = "${cfg.host}";
answer = "${config.${namespace}.containers.adguard.rewriteAddress}";
}
];
};
}
11 changes: 2 additions & 9 deletions nix/modules/nixos/containers/flood/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ in {
host = "${cfg.host}";
url = "http://${cfg.localAddress}:3000";
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
];

config = mkIf cfg.enable {
Expand Down Expand Up @@ -75,14 +77,5 @@ in {
system.stateVersion = "24.11";
};
};

containers.adguard.config.services.adguardhome.settings.filtering.rewrites =
lib.mkIf config.${namespace}.containers.flood.enable
[
{
domain = "${cfg.host}";
answer = "${config.${namespace}.containers.adguard.rewriteAddress}";
}
];
};
}
11 changes: 2 additions & 9 deletions nix/modules/nixos/containers/homepage/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ in {
host = "${cfg.host}";
url = "http://${cfg.localAddress}:8082";
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
];
config = mkIf cfg.enable {
containers.homepage = {
Expand Down Expand Up @@ -123,14 +125,5 @@ in {
system.stateVersion = "24.11";
};
};

containers.adguard.config.services.adguardhome.settings.filtering.rewrites =
lib.mkIf config.${namespace}.containers.adguard.enable
[
{
domain = "${cfg.host}";
answer = "${config.${namespace}.containers.adguard.rewriteAddress}";
}
];
};
}
11 changes: 2 additions & 9 deletions nix/modules/nixos/containers/nextcloud/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ in {
host = "${cfg.host}";
url = "http://${cfg.localAddress}:80";
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
];
config = mkIf cfg.enable {
networking.nat = {
Expand Down Expand Up @@ -157,14 +159,5 @@ in {
system.stateVersion = "24.11";
};
};

containers.adguard.config.services.adguardhome.settings.filtering.rewrites =
lib.mkIf config.${namespace}.containers.adguard.enable
[
{
domain = "${cfg.host}";
answer = "${config.${namespace}.containers.adguard.rewriteAddress}";
}
];
};
}
13 changes: 13 additions & 0 deletions nix/modules/nixos/containers/shared/shared-adguard-dns-rewrite.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DNS rewrite module, by default creating CNAME to adguard
{
host ? "test.sbulav.ru",
url ? "adguard.sbulav.ru",
...
}: {
containers.adguard.config.services.adguardhome.settings.filtering.rewrites = [
{
domain = "${host}";
answer = "${url}";
}
];
}
10 changes: 2 additions & 8 deletions nix/modules/nixos/containers/traefik/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ in {
./middleware_authelia.nix
./middleware_allow-lan.nix
./middleware_secure-headers.nix
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "traefik.${cfg.domain}";})
];

config = mkIf cfg.enable {
Expand Down Expand Up @@ -96,13 +98,5 @@ in {
system.stateVersion = "24.11";
};
};
containers.adguard.config.services.adguardhome.settings.filtering.rewrites =
lib.mkIf config.${namespace}.containers.adguard.enable
[
{
domain = "traefik.${cfg.domain}";
answer = "${config.${namespace}.containers.adguard.rewriteAddress}";
}
];
};
}
2 changes: 1 addition & 1 deletion nix/systems/x86_64-linux/serverz/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ in {
localAddress = "172.16.64.104";
};
flood = {
enable = false;
enable = true;
host = "flood.sbulav.ru";
hostAddress = "172.16.64.10";
localAddress = "172.16.64.105";
Expand Down

0 comments on commit 2bb4808

Please sign in to comment.