From 4fee8726a9fe39a769c04fa6246aa97f9b23c375 Mon Sep 17 00:00:00 2001 From: sora-ext Date: Wed, 17 Jun 2026 17:13:59 +0200 Subject: [PATCH] Add modules/server/containers/apps/robotstxt.nix --- modules/server/containers/apps/robotstxt.nix | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 modules/server/containers/apps/robotstxt.nix diff --git a/modules/server/containers/apps/robotstxt.nix b/modules/server/containers/apps/robotstxt.nix new file mode 100644 index 0000000..1e52737 --- /dev/null +++ b/modules/server/containers/apps/robotstxt.nix @@ -0,0 +1,52 @@ +{ containerCfg, pkgs, builder, name, ... }: +let + port = 8080; + priority = toString (containerCfg.extra.priority or 2147482647); + defaultRobots = '' + User-agent: * + Disallow: / + ''; + robots = + if containerCfg.extra ? robots then + containerCfg.extra.robots + else + defaultRobots + (containerCfg.extra.extraRobots or ""); + robotsRoot = pkgs.writeTextDir "robots.txt" robots; + image = pkgs.dockerTools.streamLayeredImage { + name = "robots"; + tag = "1"; + contents = [ + robotsRoot + pkgs.busybox + ]; + config = { + Entrypoint = [ + "${pkgs.busybox}/bin/httpd" + "-f" + "-p" + "0.0.0.0:${toString port}" + "-h" + "${robotsRoot}" + ]; + ExposedPorts = { "${toString port}/tcp" = { }; }; + WorkingDir = "/"; + }; + }; +in { + runtime = { + containers = { + server = builder.mkContainer { + imageStream = image; + port = port; + extraLabels = { + "traefik.enable" = "true"; + "traefik.http.routers.${name}.entrypoints" = "web-secure"; + "traefik.http.routers.${name}.rule" = "Path(`/robots.txt`)"; + "traefik.http.routers.${name}.priority" = priority; + "traefik.http.routers.${name}.tls" = "true"; + "traefik.http.services.${name}.loadbalancer.server.port" = toString port; + }; + }; + }; + }; +}