Skip to content

Commit f5fbdba

Browse files
committed
n8n: new service
1 parent efa9010 commit f5fbdba

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
[comment]: # (Please add your documentation on top of this line)
4+
5+
@AUTOGEN_OPTIONS@

examples/n8n/devenv.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ pkgs, ... }:
2+
3+
{
4+
packages = [ pkgs.coreutils ];
5+
services.n8n = {
6+
enable = true;
7+
address = "0.0.0.0";
8+
port = 5432;
9+
# settings = {
10+
11+
# }
12+
# webhookUrl = "";
13+
};
14+
}

examples/n8n/devenv.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allowUnfree: true

src/modules/services/n8n.nix

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{ config
2+
, lib
3+
, pkgs
4+
, ...
5+
}:
6+
7+
with lib;
8+
9+
let
10+
inherit (lib) types;
11+
cfg = config.services.n8n;
12+
format = pkgs.formats.json { };
13+
configFile = format.generate "n8n.json" cfg.settings;
14+
in
15+
{
16+
options = {
17+
services.n8n = {
18+
enable = mkEnableOption "n8n";
19+
20+
address = lib.mkOption {
21+
type = types.str;
22+
description = "Listen address";
23+
default = "127.0.0.1";
24+
example = "127.0.0.1";
25+
};
26+
27+
port = lib.mkOption {
28+
type = types.port;
29+
default = 5432;
30+
description = ''
31+
The TCP port to accept connections.
32+
'';
33+
};
34+
35+
webhookUrl = lib.mkOption {
36+
type = lib.types.str;
37+
default = "";
38+
description = ''
39+
WEBHOOK_URL for n8n, in case we're running behind a reverse proxy.
40+
This cannot be set through configuration and must reside in an environment variable.
41+
'';
42+
};
43+
44+
settings = lib.mkOption {
45+
type = format.type;
46+
default = { };
47+
description = ''
48+
Configuration for n8n, see <https://docs.n8n.io/hosting/environment-variables/configuration-methods/>
49+
for supported values.
50+
'';
51+
};
52+
};
53+
};
54+
55+
config = lib.mkIf cfg.enable {
56+
assertions = [{
57+
assertion = cfg.enable;
58+
message = ''
59+
To use n8n, you have to enable it. (services.n8n.enable = true;)
60+
'';
61+
}];
62+
env = {
63+
N8N_PORT = cfg.port;
64+
N8N_LISTEN_ADDRESS = cfg.address;
65+
WEBHOOK_URL = "${cfg.webhookUrl}";
66+
N8N_CONFIG_FILES = "${configFile}";
67+
};
68+
69+
processes.n8n = {
70+
exec = "${pkgs.n8n}/bin/n8n";
71+
72+
process-compose = {
73+
readiness_probe = {
74+
exec.command = "${pkgs.curl}/bin/curl -f -k ${cfg.address}:${toString cfg.port}";
75+
initial_delay_seconds = 1;
76+
period_seconds = 10;
77+
timeout_seconds = 2;
78+
success_threshold = 1;
79+
failure_threshold = 5;
80+
};
81+
82+
availability.restart = "on_failure";
83+
};
84+
};
85+
};
86+
}

tests/n8n/devenv.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
services.n8n = {
3+
enable = true;
4+
address = "0.0.0.0";
5+
port = 5678;
6+
};
7+
}

tests/n8n/devenv.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allowUnfree: true

0 commit comments

Comments
 (0)