Unverified Commit d8a10b4d authored by Gergő Gutyina's avatar Gergő Gutyina Committed by GitHub
Browse files

nixos/n8n: add custom nodes option (#484577)

parents f211b54e 267c9bbb
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -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}"
@@ -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;
@@ -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";
+7 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ in
    {
      services.n8n = {
        enable = true;
        customNodes = [ pkgs.n8n-nodes-carbonejs ];
        environment = {
          WEBHOOK_URL = webhookUrl;
          N8N_TEMPLATES_ENABLED = false;
@@ -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 −0
Original line number Diff line number Diff line
{
  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 ];
  };
})