You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB
Nix

{pkgs, config, ...}@args:
{src, name, mainBinaryPath, setupCommands ? "", serviceOptions ? {}, serviceConfig ? {}, hasErrorReporting ? false, errorPath ? null}:
with pkgs.stdenv.lib;
let
buildNode2nixPackage = (import ./build/node2nix-package.nix) args;
errorReporter = (import ./node-error-reporter) args;
optionalValue = (import ./util/optional-value.nix);
in let
serviceName = "node-${name}";
cfg = config.services."${serviceName}";
application = buildNode2nixPackage {
name = "${serviceName}-source";
inherit src setupCommands;
};
errorReporterModule = optionalValue hasErrorReporting (errorReporter {
applicationName = name;
inherit application errorPath;
});
in
{
imports = [
errorReporterModule
];
options.services."${serviceName}" = {
enable = mkEnableOption "${name}";
} // serviceOptions;
config = {
# FIXME: What if a username conflict occurs?
users.extraUsers."${name}" = mkIf cfg.enable {
description = "${name} Service User";
};
systemd.services."${serviceName}" = mkIf cfg.enable ({
description = "${name} Service";
wantedBy = ["multi-user.target"];
after = ["network.target"];
serviceConfig = {
ExecStart = "${application}/${mainBinaryPath}";
User = name;
PermissionsStartOnly = true;
Restart = "on-failure";
};
} // serviceConfig);
};
}