2024-02-28 01:45:28 +01:00
|
|
|
# SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2024-02-28 00:13:53 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.services.villas.node;
|
|
|
|
|
|
|
|
villasNodeCfg = pkgs.writeText "villas-node.conf" (builtins.toJSON cfg.config);
|
|
|
|
in
|
|
|
|
with lib; {
|
|
|
|
options = {
|
|
|
|
services.villas.node = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "VILLASnode is a client/server application to connect simulation equipment and software.");
|
|
|
|
|
|
|
|
package = mkPackageOption pkgs "villas" {};
|
|
|
|
|
2024-03-08 19:55:05 +01:00
|
|
|
configPath = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
description = mdDoc ''
|
|
|
|
A path to a VILLASnode configuration file.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2024-02-28 00:13:53 +01:00
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf types.anything;
|
|
|
|
default = {
|
|
|
|
nodes = {};
|
|
|
|
paths = [];
|
|
|
|
idle_stop = false; # Do not stop daemon because of empty paths
|
|
|
|
};
|
|
|
|
|
2024-03-08 19:55:05 +01:00
|
|
|
description = mdDoc ''
|
2024-02-28 00:13:53 +01:00
|
|
|
Contents of the VILLASnode configuration file,
|
|
|
|
{file}`villas-node.json`.
|
|
|
|
|
|
|
|
See: https://villas.fein-aachen.org/docs/node/config/
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.config != null && cfg.config != {};
|
|
|
|
message = "You must provide services.villas.node.config.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# configuration file indirection is needed to support reloading
|
2024-03-08 19:55:05 +01:00
|
|
|
environment.etc."villas/node.json" = mkIf (builtins.isNull cfg.configPath) {
|
|
|
|
source = villasNodeCfg;
|
|
|
|
};
|
2024-02-28 00:13:53 +01:00
|
|
|
|
|
|
|
systemd.services.villas-node = {
|
|
|
|
description = "VILLASnode";
|
|
|
|
after = ["network.target"];
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2024-03-08 19:55:05 +01:00
|
|
|
ExecStart = let
|
|
|
|
cfgPath =
|
|
|
|
if isNull cfg.configPath
|
|
|
|
then "/etc/villas/node.json"
|
|
|
|
else cfg.configPath;
|
|
|
|
in "${lib.getExe cfg.package} node ${cfgPath}";
|
2024-02-28 00:13:53 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|