From 535a536b5770e74b6b4ccf1d65642770682fe73f Mon Sep 17 00:00:00 2001 From: Fabrice Bellamy <12b@distrilab.fr> Date: Fri, 20 Dec 2024 11:55:06 +0100 Subject: [PATCH] add options to the nixin-web.nix module --- config/arachnide/configuration.nix | 5 +++ modules/nixin-web.nix | 70 +++++++++++++++++------------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/config/arachnide/configuration.nix b/config/arachnide/configuration.nix index 03bb096..790617d 100644 --- a/config/arachnide/configuration.nix +++ b/config/arachnide/configuration.nix @@ -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; diff --git a/modules/nixin-web.nix b/modules/nixin-web.nix index e2913a1..07cbe13 100644 --- a/modules/nixin-web.nix +++ b/modules/nixin-web.nix @@ -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"; + }; }; }