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;
7 years ago
inherit application errorPath;
});
7 years ago
in
{
imports = [
errorReporterModule
];
7 years ago
options.services."${serviceName}" = {
enable = mkEnableOption "${name}";
} // serviceOptions;
7 years ago
config = {
# FIXME: What if a username conflict occurs?
users.extraUsers."${name}" = mkIf cfg.enable {
description = "${name} Service User";
};
7 years ago
systemd.services."${serviceName}" = mkIf cfg.enable ({
description = "${name} Service";
wantedBy = ["multi-user.target"];
after = ["network.target"];
7 years ago
serviceConfig = {
ExecStart = "${application}/${mainBinaryPath}";
User = name;
PermissionsStartOnly = true;
Restart = "on-failure";
7 years ago
};
} // serviceConfig);
};
}