From 452afd70c1701fbb229a3c4c25fa7f46a21c7c5d Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Mon, 6 May 2024 14:26:24 -0400 Subject: [PATCH] enable n8n on arrow --- flake.nix | 1 + hosts/arrow/modules.nix | 1 + modules/common/default.nix | 4 ++++ modules/nixos/services/n8n.nix | 19 +++++++------------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index aa1d0a3..67135ac 100644 --- a/flake.nix +++ b/flake.nix @@ -233,6 +233,7 @@ irc = "irc.${baseName}"; metrics = "metrics.${baseName}"; minecraft = "minecraft.${baseName}"; + n8n = "n8n.${baseName}"; prometheus = "prom.${baseName}"; paperless = "paper.${baseName}"; secrets = "vault.${baseName}"; diff --git a/hosts/arrow/modules.nix b/hosts/arrow/modules.nix index 55af5c0..05f90b2 100644 --- a/hosts/arrow/modules.nix +++ b/hosts/arrow/modules.nix @@ -22,6 +22,7 @@ cloudflare.enable = true; services.openssh.enable = true; services.caddy.enable = true; + services.n8n.enable = true; # nix-index seems to eat up too much memory for Vultr home-manager.users.${globals.user}.programs.nix-index.enable = inputs.nixpkgs.lib.mkForce false; diff --git a/modules/common/default.nix b/modules/common/default.nix index a885847..7084193 100644 --- a/modules/common/default.nix +++ b/modules/common/default.nix @@ -125,6 +125,10 @@ type = lib.types.str; description = "Hostname for IRC services."; }; + n8n = lib.mkOption { + type = lib.types.str; + description = "Hostname for n8n automation."; + }; transmission = lib.mkOption { type = lib.types.str; description = "Hostname for peer2peer downloads (Transmission)."; diff --git a/modules/nixos/services/n8n.nix b/modules/nixos/services/n8n.nix index 35cbcfb..5665e99 100644 --- a/modules/nixos/services/n8n.nix +++ b/modules/nixos/services/n8n.nix @@ -4,18 +4,9 @@ { config, lib, ... }: { - options = { - n8nServer = lib.mkOption { - type = lib.types.nullOr lib.types.str; - description = "Hostname for n8n automation"; - default = null; - }; - }; - - config = lib.mkIf (config.n8nServer != null) { + config = lib.mkIf config.services.n8n.enable { services.n8n = { - enable = true; settings = { n8n = { listenAddress = "127.0.0.1"; @@ -24,13 +15,17 @@ }; }; + # Configure Cloudflare DNS to point to this machine + services.cloudflare-dyndns.domains = [ config.hostnames.n8n ]; + + # Allow web traffic to Caddy caddy.routes = [ { - match = [ { host = [ config.n8nServer ]; } ]; + match = [ { host = [ config.hostnames.n8n ]; } ]; handle = [ { handler = "reverse_proxy"; - upstreams = [ { dial = "localhost:5678"; } ]; + upstreams = [ { dial = "localhost:${builtins.toString config.services.n8n.settings.n8n.port}"; } ]; } ]; }