Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions nixos/modules/services/misc/n8n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ let
regularEnv = lib.filterAttrs (name: _value: !(lib.hasSuffix "_FILE" name)) cfg.environment;
fileBasedEnv = lib.filterAttrs (name: _value: lib.hasSuffix "_FILE" name) cfg.environment;

customNodesDir = pkgs.linkFarm "n8n-custom-nodes" (
map (pkg: {
name = pkg.pname;
path = "${pkg}/lib/node_modules/${pkg.pname}";
}) cfg.customNodes
);

# Transform file-based env vars to point to credentials directory
fileBasedEnvTransformed = lib.mapAttrs' (
varName: _secretPath: lib.nameValuePair varName "%d/${envVarToCredName varName}"
Expand All @@ -34,6 +41,17 @@ in

package = lib.mkPackageOption pkgs "n8n" { };

customNodes = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
example = lib.literalExpression "[ pkgs.n8n-nodes-carbonejs ]";
description = ''
List of custom n8n community node packages to load.
Each package is expected to be an npm package with an `n8n.nodes` entry in its `package.json`.
The packages are made available to n8n via the `N8N_CUSTOM_EXTENSIONS` environment variable.
'';
};

openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
Expand Down Expand Up @@ -121,6 +139,9 @@ in
// {
HOME = config.services.n8n.environment.N8N_USER_FOLDER;
}
// lib.optionalAttrs (cfg.customNodes != [ ]) {
N8N_CUSTOM_EXTENSIONS = toString customNodesDir;
}
// fileBasedEnvTransformed;
serviceConfig = {
Type = "simple";
Expand Down
7 changes: 7 additions & 0 deletions nixos/tests/n8n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ in
{
services.n8n = {
enable = true;
customNodes = [ pkgs.n8n-nodes-carbonejs ];
environment = {
WEBHOOK_URL = webhookUrl;
N8N_TEMPLATES_ENABLED = false;
Expand All @@ -41,5 +42,11 @@ in
# Test _FILE environment variables
machine.succeed("grep -qF 'LoadCredential=n8n_encryption_key_file:${secretFile}' /etc/systemd/system/n8n.service")
machine.succeed("grep -qF 'N8N_ENCRYPTION_KEY_FILE=%d/n8n_encryption_key_file' /etc/systemd/system/n8n.service")

# Test custom nodes
machine.succeed("grep -qF 'N8N_CUSTOM_EXTENSIONS=' /etc/systemd/system/n8n.service")
custom_extensions_dir = machine.succeed("grep -oP 'N8N_CUSTOM_EXTENSIONS=\\K[^\"]+' /etc/systemd/system/n8n.service").strip()
machine.succeed(f"test -L {custom_extensions_dir}/n8n-nodes-carbonejs")
machine.succeed(f"test -f {custom_extensions_dir}/n8n-nodes-carbonejs/package.json")
'';
}
32 changes: 32 additions & 0 deletions pkgs/by-name/n8/n8n-nodes-carbonejs/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
lib,
buildNpmPackage,
fetchFromGitHub,
nix-update-script,
n8n,
}:

buildNpmPackage (finalAttrs: {
pname = "n8n-nodes-carbonejs";
version = "1.2.0";

src = fetchFromGitHub {
owner = "jreyesr";
repo = "n8n-nodes-carbonejs";
tag = "v${finalAttrs.version}";
hash = "sha256-Dvl+Kc04i+hQ8rciT7n3oS4rtgke+HEqUszJnQa7UA0=";
};

npmDepsHash = "sha256-3VwejuSFGvJWNsitLKfVVpB8GnkTrrf/LLobNCpy8gU=";

passthru.updateScript = nix-update-script { };

meta = {
inherit (n8n.meta) platforms;
description = "n8n community node for rendering Word templates using Carbone.js";
homepage = "https://github.com/jreyesr/n8n-nodes-carbonejs";
changelog = "https://github.com/jreyesr/n8n-nodes-carbonejs/releases/tag/${finalAttrs.src.tag}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ sweenu ];
};
})
Loading