mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
nix: Add NixOS module for villas-node
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
parent
24e8fe62b9
commit
92243036f1
2 changed files with 69 additions and 0 deletions
12
flake.nix
12
flake.nix
|
@ -208,5 +208,17 @@
|
||||||
|
|
||||||
# Standard flake attribute specifying the formatter invoked on `nix fmt`
|
# Standard flake attribute specifying the formatter invoked on `nix fmt`
|
||||||
formatter = forSupportedSystems (system: (pkgsFor system).alejandra);
|
formatter = forSupportedSystems (system: (pkgsFor system).alejandra);
|
||||||
|
|
||||||
|
# Standard flake attribute for NixOS modules
|
||||||
|
nixosModules = rec {
|
||||||
|
default = villas;
|
||||||
|
|
||||||
|
villas = {
|
||||||
|
imports = [(nixDir + "/module.nix")];
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
self.overlays.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
57
packaging/nix/module.nix
Normal file
57
packaging/nix/module.nix
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
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" {};
|
||||||
|
|
||||||
|
config = mkOption {
|
||||||
|
type = types.attrsOf types.anything;
|
||||||
|
default = {
|
||||||
|
nodes = {};
|
||||||
|
paths = [];
|
||||||
|
idle_stop = false; # Do not stop daemon because of empty paths
|
||||||
|
};
|
||||||
|
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
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
|
||||||
|
environment.etc."villas/node.json".source = villasNodeCfg;
|
||||||
|
|
||||||
|
systemd.services.villas-node = {
|
||||||
|
description = "VILLASnode";
|
||||||
|
after = ["network.target"];
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStart = "${lib.getExe cfg.package} node /etc/villas/node.json";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue