-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da48e25
commit 644e3a4
Showing
4 changed files
with
87 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ pkgs, config, lib, ... }: | ||
with lib; | ||
let | ||
file-path = builtins.split "/" (toString ./.); | ||
serviceName = lib.last file-path; | ||
cfg = config.services."${serviceName}-server"; | ||
in { | ||
options.services = { | ||
"${serviceName}-server" = { | ||
enable = mkEnableOption "Enables ${serviceName} service"; | ||
mgmtConfig = mkOption { | ||
type = types.path; | ||
description = "Path to management config file"; | ||
}; | ||
signalPort = mkOption { | ||
default = 8080; | ||
type = types.int; | ||
description = "Port for signal service"; | ||
}; | ||
mgmtPort = mkOption { | ||
default = 8081; | ||
type = types.int; | ||
description = "Port for management service"; | ||
}; | ||
}; | ||
}; | ||
config = mkIf cfg.enable { | ||
systemd = { | ||
services = { | ||
"netbird-signal" = { | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "networking.target" ]; | ||
startLimitIntervalSec = 500; | ||
startLimitBurst = 5; | ||
preStart = ""; | ||
onSuccess = [ ]; | ||
onFailure = [ ]; | ||
serviceConfig = { | ||
User = serviceName; | ||
RestartSec = "5s"; | ||
WorkingDirectory = "/var/lib/${serviceName}"; | ||
StateDirectory = serviceName; | ||
RuntimeDirectory = serviceName; | ||
CacheDirectory = serviceName; | ||
Type = "simple"; | ||
}; | ||
script = "${pkgs.netbird}/bin/netbird-signal run --port ${ | ||
toString cfg.signalPort | ||
} --log-file console --log-level debug"; | ||
}; | ||
"netbird-mgmt" = { | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "networking.target" ]; | ||
startLimitIntervalSec = 500; | ||
startLimitBurst = 5; | ||
preStart = ""; | ||
onSuccess = [ ]; | ||
onFailure = [ ]; | ||
serviceConfig = { | ||
User = serviceName; | ||
RestartSec = "5s"; | ||
WorkingDirectory = "/var/lib/${serviceName}"; | ||
StateDirectory = serviceName; | ||
RuntimeDirectory = serviceName; | ||
CacheDirectory = serviceName; | ||
Type = "simple"; | ||
}; | ||
script = | ||
"${pkgs.netbird}/bin/netbird-mgmt management --config ${cfg.mgmtConfig} --port ${ | ||
toString cfg.mgmtPort | ||
} --log-file console --log-level debug --single-account-mode-domain=netbird.trontech.link"; | ||
}; | ||
}; | ||
}; | ||
users.users."${serviceName}" = { | ||
description = "${serviceName} user"; | ||
isSystemUser = true; | ||
group = serviceName; | ||
createHome = true; | ||
}; | ||
users.groups."${serviceName}" = { }; | ||
}; | ||
} |