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";
};
nixin.web = {
domain = "nixin.lab12.fr";
http-port = 8081;
};
# Enable ip forwarding to route packets for the local network connected to enp3s0
boot.kernel.sysctl = {
"net.ipv4.ip_forward" = 1;

View file

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