From 8c87d38971c7a04804becdf114e53a0ec2023f16 Mon Sep 17 00:00:00 2001 From: Logger Date: Thu, 5 Dec 2024 22:02:33 -0700 Subject: [PATCH 1/8] n8n: new service --- docs/individual-docs/services/n8n.md | 5 ++ examples/n8n/devenv.nix | 2 + examples/n8n/devenv.yaml | 1 + src/modules/services/n8n.nix | 86 ++++++++++++++++++++++++++++ tests/n8n/devenv.nix | 7 +++ tests/n8n/devenv.yaml | 1 + 6 files changed, 102 insertions(+) create mode 100644 docs/individual-docs/services/n8n.md create mode 100644 examples/n8n/devenv.nix create mode 100644 examples/n8n/devenv.yaml create mode 100644 src/modules/services/n8n.nix create mode 100644 tests/n8n/devenv.nix create mode 100644 tests/n8n/devenv.yaml diff --git a/docs/individual-docs/services/n8n.md b/docs/individual-docs/services/n8n.md new file mode 100644 index 000000000..d3615c80f --- /dev/null +++ b/docs/individual-docs/services/n8n.md @@ -0,0 +1,5 @@ + + +[comment]: # (Please add your documentation on top of this line) + +@AUTOGEN_OPTIONS@ diff --git a/examples/n8n/devenv.nix b/examples/n8n/devenv.nix new file mode 100644 index 000000000..fb4b367ec --- /dev/null +++ b/examples/n8n/devenv.nix @@ -0,0 +1,2 @@ +{ ... }: +{ } diff --git a/examples/n8n/devenv.yaml b/examples/n8n/devenv.yaml new file mode 100644 index 000000000..09bce897b --- /dev/null +++ b/examples/n8n/devenv.yaml @@ -0,0 +1 @@ +allowUnfree: true diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix new file mode 100644 index 000000000..6d8e860df --- /dev/null +++ b/src/modules/services/n8n.nix @@ -0,0 +1,86 @@ +{ config +, lib +, pkgs +, ... +}: + +with lib; + +let + inherit (lib) types; + cfg = config.services.n8n; + format = pkgs.formats.json { }; + configFile = format.generate "n8n.json" cfg.settings; +in +{ + options = { + services.n8n = { + enable = mkEnableOption "n8n"; + + address = lib.mkOption { + type = types.str; + description = "Listen address"; + default = "127.0.0.1"; + example = "127.0.0.1"; + }; + + port = lib.mkOption { + type = types.port; + default = 5432; + description = '' + The TCP port to accept connections. + ''; + }; + + webhookUrl = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + WEBHOOK_URL for n8n, in case we're running behind a reverse proxy. + This cannot be set through configuration and must reside in an environment variable. + ''; + }; + + settings = lib.mkOption { + type = format.type; + default = { }; + description = '' + Configuration for n8n, see + for supported values. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [{ + assertion = cfg.enable; + message = '' + To use n8n, you have to enable it. (services.n8n.enable = true;) + ''; + }]; + env = { + N8N_PORT = cfg.port; + N8N_LISTEN_ADDRESS = cfg.address; + WEBHOOK_URL = "${cfg.webhookUrl}"; + N8N_CONFIG_FILES = "${configFile}"; + }; + + processes.n8n = { + exec = "${pkgs.n8n}/bin/n8n"; + + process-compose = { + readiness_probe = { + exec.command = "${pkgs.curl}/bin/curl -f -k ${cfg.address}:${toString cfg.port}"; + initial_delay_seconds = 1; + period_seconds = 10; + timeout_seconds = 2; + success_threshold = 1; + failure_threshold = 5; + }; + + availability.restart = "on_failure"; + }; + }; + }; +} diff --git a/tests/n8n/devenv.nix b/tests/n8n/devenv.nix new file mode 100644 index 000000000..48529a647 --- /dev/null +++ b/tests/n8n/devenv.nix @@ -0,0 +1,7 @@ +{ + services.n8n = { + enable = true; + address = "0.0.0.0"; + port = 5678; + }; +} diff --git a/tests/n8n/devenv.yaml b/tests/n8n/devenv.yaml new file mode 100644 index 000000000..09bce897b --- /dev/null +++ b/tests/n8n/devenv.yaml @@ -0,0 +1 @@ +allowUnfree: true From 890ceccfc434dd85ed799137a7a646e74f868f7e Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:46:04 -0700 Subject: [PATCH 2/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 6d8e860df..433e8beda 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -53,12 +53,6 @@ in }; config = lib.mkIf cfg.enable { - assertions = [{ - assertion = cfg.enable; - message = '' - To use n8n, you have to enable it. (services.n8n.enable = true;) - ''; - }]; env = { N8N_PORT = cfg.port; N8N_LISTEN_ADDRESS = cfg.address; From d8f205d4ec0f792d452a3752082b89bc5bc5f972 Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:46:15 -0700 Subject: [PATCH 3/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 433e8beda..874b71328 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -4,8 +4,6 @@ , ... }: -with lib; - let inherit (lib) types; cfg = config.services.n8n; From 0854c3365b7e62ccfb1eef037d9b8a956ab86e7d Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:46:23 -0700 Subject: [PATCH 4/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 874b71328..476784497 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -13,7 +13,7 @@ in { options = { services.n8n = { - enable = mkEnableOption "n8n"; + enable = lib.mkEnableOption "n8n"; address = lib.mkOption { type = types.str; From ed333d73d41219d0c5e35095654412b7d22a1ac7 Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:46:33 -0700 Subject: [PATCH 5/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 476784497..cea620338 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -19,7 +19,6 @@ in type = types.str; description = "Listen address"; default = "127.0.0.1"; - example = "127.0.0.1"; }; port = lib.mkOption { From fd5a4f61e33915bc67437ff14a4f5392eafaa8a0 Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:46:43 -0700 Subject: [PATCH 6/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index cea620338..8ef2c3b62 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -23,7 +23,7 @@ in port = lib.mkOption { type = types.port; - default = 5432; + default = 5678; description = '' The TCP port to accept connections. ''; From c83752b2d861c7e856f159a429ab5927e3effb50 Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:47:13 -0700 Subject: [PATCH 7/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 8ef2c3b62..43f0666eb 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -30,7 +30,7 @@ in }; webhookUrl = lib.mkOption { - type = lib.types.str; + type = types.nullOr types.str; default = ""; description = '' WEBHOOK_URL for n8n, in case we're running behind a reverse proxy. From 1fe6eb5d7a070219db792abc8fc6c0b4245ad2c1 Mon Sep 17 00:00:00 2001 From: Logger <1440852+i-am-logger@users.noreply.github.com> Date: Thu, 9 Jan 2025 02:47:23 -0700 Subject: [PATCH 8/8] Update src/modules/services/n8n.nix Co-authored-by: sander --- src/modules/services/n8n.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/services/n8n.nix b/src/modules/services/n8n.nix index 43f0666eb..3940c409d 100644 --- a/src/modules/services/n8n.nix +++ b/src/modules/services/n8n.nix @@ -31,7 +31,7 @@ in webhookUrl = lib.mkOption { type = types.nullOr types.str; - default = ""; + default = null; description = '' WEBHOOK_URL for n8n, in case we're running behind a reverse proxy. This cannot be set through configuration and must reside in an environment variable.