I am using services.node-red and need to make git package available within the service.
What is the proper way to add git into node-red system service?
Also: If you think every user of the service should have git in the service’s path, feel free to upstream this setting to the module by creating a PR!!
Thanks @mattchrist. Adding path does indeed add git to the PATH of systems service. I can see it in systemctl show node-red. Though the node-red still not able to find it, I wonder whether path is hardcoded somewhere in node-red now…
This is to use the projects feature of Node-RED, isn’t it? You will also need openssh to use this feature. The way the Node-RED module works means that the PATH is hardcoded, since the implementation of withNpmAndGcc already sets the PATH to have npm and gcc on it.
Here is the most basic way to enable the projects functionality for Node-RED:
{ config, pkgs, lib, ... }:
let
myNodeRed = pkgs.runCommand "node-red" {
nativeBuildInputs = [ pkgs.makeWrapper ];
}
''
mkdir -p $out/bin
makeWrapper ${pkgs.nodePackages.node-red}/bin/node-red $out/bin/node-red \
--set PATH '${lib.makeBinPath [ pkgs.git pkgs.openssh pkgs.nodePackages.npm pkgs.gcc ]}:$PATH' \
'';
in
{
services.node-red = {
enable = true;
package = myNodeRed;
configFile = "${pkgs.nodePackages.node-red}/lib/node_modules/node-red/settings.js";
define = { "editorTheme.projects.enabled" = "true"; };
};
# Because Node-RED devs don't believe that this is an issue that needs to be
# solved in the node application itself, but rather hardcoded into the env of
# their docker image.
# https://github.com/node-red/node-red-docker/issues/191
# https://github.com/node-red/node-red/issues/2420
programs.ssh.knownHosts."github.com".publicKey =
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
}
This will create a new package named myNodeRed which has git, npm, gcc and ssh on its PATH. We can tell the Node-RED service to use this package we just made via services.node-red.package. The services.node-red.define option is used to set editorTheme.projects.enabled to true in the settings.js used by Node-RED.
Then, because the developers of the projects function of Node-RED have not programmed in a way to accept and write authorized keys as part of ssh auth with git+ssh, we need to write Github.com into the known hosts globally for the NixOS system. Linked below are some issues to track that problem.
@matthewcroughan, how do you manage this part of the config? I feed the config itself and wonder whether there is a way to make it a part of *nix config files.
Since you can’t pass Node-RED multiple settings.js files which it would concatenate internally, the NixOS module is going to have to become more complex, and allow you to specify things like services.node-red.passwordFile which would be implemented by concatenating javascript files together as part of the Nix code. It currently does not do this, as when I implemented it, I just wanted a basic NixOS service to be available to people.
This is going to be difficult, because settings.js is not JSON, it’s turing complete javascript, and parsing it with Nix is not going to be trivial. I don’t have a quick and easy answer for you. What you can do is write your own settings.js file and then pass it to the Node-RED service by using services.node-red.configFile. That’s all I can recommend for now.