1{ config, pkgs, lib, ... }:
2let
3 cfg = config.services.meshcentral;
4 configFormat = pkgs.formats.json {};
5 configFile = configFormat.generate "meshcentral-config.json" cfg.settings;
6in with lib; {
7 options.services.meshcentral = with types; {
8 enable = mkEnableOption (lib.mdDoc "MeshCentral computer management server");
9 package = mkOption {
10 description = lib.mdDoc "MeshCentral package to use. Replacing this may be necessary to add dependencies for extra functionality.";
11 type = types.package;
12 default = pkgs.meshcentral;
13 defaultText = literalExpression "pkgs.meshcentral";
14 };
15 settings = mkOption {
16 description = lib.mdDoc ''
17 Settings for MeshCentral. Refer to upstream documentation for details:
18
19 - [JSON Schema definition](https://github.com/Ylianst/MeshCentral/blob/master/meshcentral-config-schema.json)
20 - [simple sample configuration](https://github.com/Ylianst/MeshCentral/blob/master/sample-config.json)
21 - [complex sample configuration](https://github.com/Ylianst/MeshCentral/blob/master/sample-config-advanced.json)
22 - [Old homepage with documentation link](https://www.meshcommander.com/meshcentral2)
23 '';
24 type = types.submodule {
25 freeformType = configFormat.type;
26 };
27 example = {
28 settings = {
29 WANonly = true;
30 Cert = "meshcentral.example.com";
31 TlsOffload = "10.0.0.2,fd42::2";
32 Port = 4430;
33 };
34 domains."".certUrl = "https://meshcentral.example.com/";
35 };
36 };
37 };
38 config = mkIf cfg.enable {
39 services.meshcentral.settings.settings.autoBackup.backupPath = lib.mkDefault "/var/lib/meshcentral/backups";
40 systemd.services.meshcentral = {
41 wantedBy = ["multi-user.target"];
42 serviceConfig = {
43 ExecStart = "${cfg.package}/bin/meshcentral --datapath /var/lib/meshcentral --configfile ${configFile}";
44 DynamicUser = true;
45 StateDirectory = "meshcentral";
46 CacheDirectory = "meshcentral";
47 };
48 };
49 };
50 meta.maintainers = [ maintainers.lheckemann ];
51}