From 9a5427e3a0c0ccf2a82dc503149a26b23fbd6004 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 31 Mar 2024 21:29:27 +0300 Subject: 2024-03-31 --- modules/nixos/plausible.nix | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'modules/nixos/plausible.nix') diff --git a/modules/nixos/plausible.nix b/modules/nixos/plausible.nix index 8de54d2..d63e3ab 100644 --- a/modules/nixos/plausible.nix +++ b/modules/nixos/plausible.nix @@ -4,9 +4,11 @@ lib, ... }: -with lib; let +with lib; +let cfg = config.nixfiles.modules.plausible; -in { +in +{ options.nixfiles.modules.plausible = { enable = mkEnableOption "Plausible Analytics"; @@ -23,15 +25,18 @@ in { }; }; - config = let - db = "plausible"; - in + config = + let + db = "plausible"; + in mkIf cfg.enable { _module.args.libPlausible = { - htmlPlausibleScript = { - domain ? "$host", - src ? "https://${cfg.domain}/js/script.js", - }: ''''; + htmlPlausibleScript = + { + domain ? "$host", + src ? "https://${cfg.domain}/js/script.js", + }: + ''''; }; secrets = { @@ -43,7 +48,7 @@ in { nixfiles.modules = { nginx = { enable = true; - upstreams.plausible.servers."127.0.0.1:${toString cfg.port}" = {}; + upstreams.plausible.servers."127.0.0.1:${toString cfg.port}" = { }; virtualHosts.${cfg.domain}.locations."/" = { proxyPass = "http://plausible"; proxyWebsockets = true; @@ -62,7 +67,7 @@ in { }; services.postgresql = { - ensureDatabases = [db]; + ensureDatabases = [ db ]; ensureUsers = [ { name = db; -- cgit v1.2.3