Skip to content

Commit

Permalink
n8n: new service
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-logger committed Dec 6, 2024
1 parent efa9010 commit c8f01db
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/n8n/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs, ... }:

{
packages = [ pkgs.coreutils ];
services.n8n = {
enable = true;
address = "0.0.0.0";
port = "5432";
# settings = {

# }
# webhookUrl = "";
};
}
79 changes: 79 additions & 0 deletions src/modules/services/n8n.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{ config
, lib
, pkgs
, ...
}:

with lib;

let
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 <https://docs.n8n.io/hosting/environment-variables/configuration-methods/>
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";
};
};
};
}
7 changes: 7 additions & 0 deletions tests/n8n/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
services.n8n = {
enable = true;
address = "0.0.0.0";
port = 9090;
};
}

0 comments on commit c8f01db

Please sign in to comment.