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 "MeshCentral computer management server";
9 package = mkOption {
10 description = "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 = ''
17 Settings for MeshCentral. Refer to upstream documentation for details:
18
19 <itemizedlist>
20 <listitem><para><link xlink:href="https://github.com/Ylianst/MeshCentral/blob/master/meshcentral-config-schema.json">JSON Schema definition</link></para></listitem>
21 <listitem><para><link xlink:href="https://github.com/Ylianst/MeshCentral/blob/master/sample-config.json">simple sample configuration</link></para></listitem>
22 <listitem><para><link xlink:href="https://github.com/Ylianst/MeshCentral/blob/master/sample-config-advanced.json">complex sample configuration</link></para></listitem>
23 <listitem><para><link xlink:href="https://www.meshcommander.com/meshcentral2">Old homepage) with documentation link</link></para></listitem>
24 </itemizedlist>
25 '';
26 type = types.submodule {
27 freeformType = configFormat.type;
28 };
29 example = {
30 settings = {
31 WANonly = true;
32 Cert = "meshcentral.example.com";
33 TlsOffload = "10.0.0.2,fd42::2";
34 Port = 4430;
35 };
36 domains."".certUrl = "https://meshcentral.example.com/";
37 };
38 };
39 };
40 config = mkIf cfg.enable {
41 services.meshcentral.settings.settings.autoBackup.backupPath = lib.mkDefault "/var/lib/meshcentral/backups";
42 systemd.services.meshcentral = {
43 wantedBy = ["multi-user.target"];
44 serviceConfig = {
45 ExecStart = "${cfg.package}/bin/meshcentral --datapath /var/lib/meshcentral --configfile ${configFile}";
46 DynamicUser = true;
47 StateDirectory = "meshcentral";
48 CacheDirectory = "meshcentral";
49 };
50 };
51 };
52 meta.maintainers = [ maintainers.lheckemann ];
53}