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..9d1b3b42a --- /dev/null +++ b/examples/n8n/devenv.nix @@ -0,0 +1,14 @@ +{ pkgs, ... }: + +{ + packages = [ pkgs.coreutils ]; + services.n8n = { + enable = true; + address = "0.0.0.0"; + port = "5432"; + # settings = { + + # } + # webhookUrl = ""; + }; +} 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..433e8beda --- /dev/null +++ b/src/modules/services/n8n.nix @@ -0,0 +1,80 @@ +{ 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 { + 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..87b00c649 --- /dev/null +++ b/tests/n8n/devenv.nix @@ -0,0 +1,7 @@ +{ + services.n8n = { + enable = true; + address = "0.0.0.0"; + port = 9090; + }; +} 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