git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/n8n: init module and test
commit903b2aa9a6286f2d8165ab7c54f8f60a38717c7d authorfreezeboy <freezeboy@users.noreply.github.com> dateSat 28 Nov 2020, 18:00 (6 years ago) parentb5ee81b
4 files changed+105
nixos/modules/module-list.nix+1 nixos/modules/services/misc/n8n.nix+78 nixos/tests/all-tests.nix+1 nixos/tests/n8n.nix+25
nixos/modules/module-list.nix+1
@@ -482,6 +482,7 @@
482482 ./services/misc/mediatomb.nix
483483 ./services/misc/metabase.nix
484484 ./services/misc/mwlib.nix
485+ ./services/misc/n8n.nix
485486 ./services/misc/nix-daemon.nix
486487 ./services/misc/nix-gc.nix
487488 ./services/misc/nix-optimise.nix
nixos/modules/services/misc/n8n.nixnew file+78
@@ -0,0 +1,78 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.n8n;
7+ format = pkgs.formats.json {};
8+ configFile = format.generate "n8n.json" cfg.settings;
9+in
10+{
11+ options.services.n8n = {
12+
13+ enable = mkEnableOption "n8n server";
14+
15+ openFirewall = mkOption {
16+ type = types.bool;
17+ default = false;
18+ description = "Open ports in the firewall for the n8n web interface.";
19+ };
20+
21+ settings = mkOption {
22+ type = format.type;
23+ default = {};
24+ description = ''
25+ Configuration for n8n, see <link xlink:href="https://docs.n8n.io/reference/configuration.html"/>
26+ for supported values.
27+ '';
28+ };
29+
30+ };
31+
32+ config = mkIf cfg.enable {
33+ services.n8n.settings = {
34+ # We use this to open the firewall, so we need to know about the default at eval time
35+ port = lib.mkDefault 5678;
36+ };
37+
38+ systemd.services.n8n = {
39+ description = "N8N service";
40+ after = [ "network.target" ];
41+ wantedBy = [ "multi-user.target" ];
42+ environment = {
43+ # This folder must be writeable as the application is storing
44+ # its data in it, so the StateDirectory is a good choice
45+ N8N_USER_FOLDER = "/var/lib/n8n";
46+ N8N_CONFIG_FILES = "${configFile}";
47+ };
48+ serviceConfig = {
49+ Type = "simple";
50+ ExecStart = "${pkgs.n8n}/bin/n8n";
51+ Restart = "on-failure";
52+ StateDirectory = "n8n";
53+
54+ # Basic Hardening
55+ NoNewPrivileges = "yes";
56+ PrivateTmp = "yes";
57+ PrivateDevices = "yes";
58+ DevicePolicy = "closed";
59+ DynamicUser = "true";
60+ ProtectSystem = "strict";
61+ ProtectHome = "read-only";
62+ ProtectControlGroups = "yes";
63+ ProtectKernelModules = "yes";
64+ ProtectKernelTunables = "yes";
65+ RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
66+ RestrictNamespaces = "yes";
67+ RestrictRealtime = "yes";
68+ RestrictSUIDSGID = "yes";
69+ MemoryDenyWriteExecute = "yes";
70+ LockPersonality = "yes";
71+ };
72+ };
73+
74+ networking.firewall = mkIf cfg.openFirewall {
75+ allowedTCPPorts = [ cfg.settings.port ];
76+ };
77+ };
78+}
nixos/tests/all-tests.nix+1
@@ -231,6 +231,7 @@ in
231231 mysql-autobackup = handleTest ./mysql/mysql-autobackup.nix {};
232232 mysql-backup = handleTest ./mysql/mysql-backup.nix {};
233233 mysql-replication = handleTest ./mysql/mysql-replication.nix {};
234+ n8n = handleTest ./n8n.nix {};
234235 nagios = handleTest ./nagios.nix {};
235236 nano = handleTest ./nano.nix {};
236237 nar-serve = handleTest ./nar-serve.nix {};
nixos/tests/n8n.nixnew file+25
@@ -0,0 +1,25 @@
1+import ./make-test-python.nix ({ lib, ... }:
2+
3+with lib;
4+
5+let
6+ port = 5678;
7+in
8+{
9+ name = "n8n";
10+ meta.maintainers = with maintainers; [ freezeboy ];
11+
12+ nodes.machine =
13+ { pkgs, ... }:
14+ {
15+ services.n8n = {
16+ enable = true;
17+ };
18+ };
19+
20+ testScript = ''
21+ machine.wait_for_unit("n8n.service")
22+ machine.wait_for_open_port("${toString port}")
23+ machine.succeed("curl --fail http://localhost:${toString port}/")
24+ '';
25+})