add options to the nixin-web.nix module

This commit is contained in:
Douze Bé 2024-12-20 11:55:06 +01:00
parent 56a57675a1
commit 535a536b57
2 changed files with 44 additions and 31 deletions

View file

@ -36,6 +36,11 @@
ipv6 = "2a01:4f9:1a:9a05::2/128"; ipv6 = "2a01:4f9:1a:9a05::2/128";
}; };
nixin.web = {
domain = "nixin.lab12.fr";
http-port = 8081;
};
# Enable ip forwarding to route packets for the local network connected to enp3s0 # Enable ip forwarding to route packets for the local network connected to enp3s0
boot.kernel.sysctl = { boot.kernel.sysctl = {
"net.ipv4.ip_forward" = 1; "net.ipv4.ip_forward" = 1;

View file

@ -1,10 +1,9 @@
{ # Nixin web site
pkgs, { config, pkgs, lib, ... }:
config,
lib,
...
}:
let let
inherit (lib) mkOption mkDefault;
nixin-web = pkgs.stdenv.mkDerivation { nixin-web = pkgs.stdenv.mkDerivation {
pname = "nixin-web"; pname = "nixin-web";
version = "0.1-alpha"; version = "0.1-alpha";
@ -22,32 +21,41 @@ let
}; };
in in
{ {
services.nginx.virtualHosts."nixin.lab12.fr" = { options = {
listen = [ nixin.web = {
{ http-port = mkOption { type = lib.types.int; };
addr = "127.0.0.1"; domain = mkOption { type = lib.types.str; };
port = 8081; };
ssl = false;
}
{
addr = "[::1]";
port = 8081;
ssl = false;
}
];
forceSSL = false;
enableACME = false;
locations."/".root = ''${nixin-web}'';
locations."/".index = "index.html";
}; };
services.traefik.dynamicConfigOptions.http.services."service-nixin-web" = { config = {
loadBalancer.servers = [ services.nginx.virtualHosts."${config.nixin.web.domain}" = {
{ url = "http://localhost:8081"; } listen = [
]; {
}; addr = "127.0.0.1";
services.traefik.dynamicConfigOptions.http.routers."router-nixin-web" = { port = config.nixin.web.http-port;
rule = "Host(`nixin.lab12.fr`)"; ssl = false;
service = "service-nixin-web"; }
{
addr = "[::1]";
port = config.nixin.web.http-port;
ssl = false;
}
];
forceSSL = false;
enableACME = false;
locations."/".root = ''${nixin-web}'';
locations."/".index = "index.html";
};
services.traefik.dynamicConfigOptions.http.services."service-nixin-web" = {
loadBalancer.servers = [
{ url = "http://localhost:${toString config.nixin.web.http-port}"; }
];
};
services.traefik.dynamicConfigOptions.http.routers."router-nixin-web" = {
rule = "Host(`${config.nixin.web.domain}`)";
service = "service-nixin-web";
};
}; };
} }