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.
47 lines
1.2 KiB
Nix
47 lines
1.2 KiB
Nix
{pkgs, config, ...}: {tarball, name, mainBinaryPath, serviceOptions ? {}, serviceConfig ? {}, hasErrorReporting ? false}:
|
|
with pkgs.stdenv.lib;
|
|
|
|
let
|
|
/*serviceName = "node-${name}";*/
|
|
serviceName = "node-foo";
|
|
cfg = config.services."${serviceName}";
|
|
source = builtins.fetchTarball tarball;
|
|
application = (import (pkgs.stdenv.mkDerivation {
|
|
src = source;
|
|
buildInputs = [ pkgs.node2nix ];
|
|
buildCommand = ''
|
|
node2nix -6 --pkg-name nodejs_6_x
|
|
'';
|
|
})).package;
|
|
errorReporter = (import ./node-error-reporter) { inherit pkgs; };
|
|
in {
|
|
imports = [
|
|
/*mkIf hasErrorReporting (errorReporter {
|
|
application = application;
|
|
applicationName = name;
|
|
})*/
|
|
];
|
|
|
|
options.services."${serviceName}" = {
|
|
enable = mkEnableOption "${name}";
|
|
} // serviceOptions;
|
|
|
|
config = mkIf cfg.enable {
|
|
# FIXME: What if a username conflict occurs?
|
|
users.extraUsers."${name}" = {
|
|
description = "${name} Service User";
|
|
};
|
|
|
|
services."${serviceName}" = {
|
|
description = "${name} Service";
|
|
wantedBy = ["multi-user.target"];
|
|
after = ["network.target"];
|
|
|
|
serviceConfig = {
|
|
ExecStart = "${application}/${mainBinaryPath}";
|
|
User = name;
|
|
};
|
|
} // serviceConfig;
|
|
};
|
|
}
|