Skip to content

Commit

Permalink
feat(nix): conditional adguard rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Nov 15, 2024
1 parent 2bb4808 commit a6ed3c9
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 29 deletions.
1 change: 1 addition & 0 deletions nix/modules/nixos/containers/adguard/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ in {
app = "adguard";
host = "${cfg.host}";
url = "http://${cfg.localAddress}:3000";
route_enabled = cfg.enable;
})
];

Expand Down
9 changes: 8 additions & 1 deletion nix/modules/nixos/containers/authelia/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ in {
host = "${cfg.host}";
url = "http://${cfg.localAddress}:9091";
middleware = "secure-headers";
route_enabled = cfg.enable;
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
{
host = "${cfg.host}";
rewrite_enabled = cfg.enable;
})
];

config = mkIf cfg.enable {
Expand Down Expand Up @@ -110,6 +114,9 @@ in {
domain = "${cfg.domain}";
authelia_url = "https://${cfg.host}";
default_redirection_url = "https://homepage.${cfg.domain}";
expiration = "12h";
inactivity = "4h";
remember_me_duration = "1M";
}
];
};
Expand Down
6 changes: 5 additions & 1 deletion nix/modules/nixos/containers/flood/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ in {
app = "flood";
host = "${cfg.host}";
url = "http://${cfg.localAddress}:3000";
route_enabled = cfg.enable;
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
{
host = "${cfg.host}";
rewrite_enabled = cfg.enable;
})
];

config = mkIf cfg.enable {
Expand Down
6 changes: 5 additions & 1 deletion nix/modules/nixos/containers/homepage/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ in {
app = "homepage";
host = "${cfg.host}";
url = "http://${cfg.localAddress}:8082";
route_enabled = cfg.enable;
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
{
host = "${cfg.host}";
rewrite_enabled = cfg.enable;
})
];
config = mkIf cfg.enable {
containers.homepage = {
Expand Down
6 changes: 5 additions & 1 deletion nix/modules/nixos/containers/nextcloud/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ in {
app = "nextcloud";
host = "${cfg.host}";
url = "http://${cfg.localAddress}:80";
route_enabled = cfg.enable;
})
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "${cfg.host}";})
{
host = "${cfg.host}";
rewrite_enabled = cfg.enable;
})
];
config = mkIf cfg.enable {
networking.nat = {
Expand Down
16 changes: 11 additions & 5 deletions nix/modules/nixos/containers/shared/shared-adguard-dns-rewrite.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
{
host ? "test.sbulav.ru",
url ? "adguard.sbulav.ru",
rewrite_enabled ? false,
...
}: {
containers.adguard.config.services.adguardhome.settings.filtering.rewrites = [
{
domain = "${host}";
answer = "${url}";
containers.adguard.config.services.adguardhome.settings.filtering =
if rewrite_enabled
then {
rewrites = [
{
domain = "${host}";
answer = "${url}";
}
];
}
];
else {};
}
42 changes: 23 additions & 19 deletions nix/modules/nixos/containers/shared/shared-traefik-route.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@
host ? "test.sbulav.ru",
url ? "http://localhost:80",
middleware ? "auth-chain",
route_enabled ? false,
...
}: {
containers.traefik.config.services.traefik.dynamicConfigOptions.http = {
routers.${app} = {
entrypoints = ["websecure"];
rule = "Host(`${host}`)";
service = "${app}";
middlewares = ["${middleware}"];
tls = {
certResolver = "production";
containers.traefik.config.services.traefik.dynamicConfigOptions.http =
if route_enabled
then {
routers.${app} = {
entrypoints = ["websecure"];
rule = "Host(`${host}`)";
service = "${app}";
middlewares = ["${middleware}"];
tls = {
certResolver = "production";
};
};
};
services.${app} = {
loadBalancer = {
passHostHeader = true;
servers = [
{
url = "${url}";
}
];
services.${app} = {
loadBalancer = {
passHostHeader = true;
servers = [
{
url = "${url}";
}
];
};
};
};
};
}
else {};
}
5 changes: 4 additions & 1 deletion nix/modules/nixos/containers/traefik/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ in {
./middleware_allow-lan.nix
./middleware_secure-headers.nix
(import ../shared/shared-adguard-dns-rewrite.nix
{host = "traefik.${cfg.domain}";})
{
host = "traefik.${cfg.domain}";
rewrite_enabled = cfg.enable;
})
];

config = mkIf cfg.enable {
Expand Down

0 comments on commit a6ed3c9

Please sign in to comment.