summaryrefslogtreecommitdiff
path: root/module.nix
diff options
context:
space:
mode:
Diffstat (limited to 'module.nix')
-rw-r--r--module.nix68
1 files changed, 37 insertions, 31 deletions
diff --git a/module.nix b/module.nix
index 1c9353f..f06b884 100644
--- a/module.nix
+++ b/module.nix
@@ -1,40 +1,46 @@
-{ config, pkgs, lib, self, ... }:
-let cfg = config.services.nuogai; in with lib; {
+{ config, pkgs, lib, system, self, ... }:
+let cfg = config.services.nuogai;
+in with lib; {
options.services.nuogai = {
enable = mkEnableOption "Enables the nuogaı Discord Bot";
- guilePackage = mkOption { default = pkgs.guile; type = types.package; };
- nuiPort = mkOption { type = types.port; };
- spePort = mkOption { type = types.port; };
+ ports = listToAttrs
+ (map (flip attrsets.nameValuePair (mkOption { type = types.port; })) [
+ "nuigui"
+ "serial-predicate-engine"
+ "toadua"
+ ]);
tokenPath = mkOption { type = types.path; };
};
config = mkIf cfg.enable {
- fonts.fonts = [ self.packages.toaqScript.${system} ];
- systemd.services = lib.mapAttrs (k: v: {
- wants = [ "network-online.target" ];
- } // v) {
- nuogai = {
- description = "Toaq Discord bot";
- wantedBy = [ "multi-user.target" ];
- wants = [ "nuigui.service" "serial-predicate-engine.service" ];
- environment = {
- NUI_PORT = toString cfg.nuiPort;
- SPE_PORT = toString cfg.spePort;
+ fonts.fonts = [ self.packages.${system}.toaqScript ];
+ systemd.services = lib.mapAttrs (k: v:
+ {
+ wants = [ "network-online.target" ];
+ } // (v self.packages.${system}.${k})) {
+ nuogai = pkg: {
+ description = "Toaq Discord bot";
+ wantedBy = [ "multi-user.target" ];
+ wants = [ "nuigui.service" "serial-predicate-engine.service" ];
+ environment = {
+ NUI_PORT = toString cfg.ports.nuigui;
+ SPE_PORT = toString cfg.ports.serial-predicate-engine;
+ TOA_PORT = toString cfg.ports.toadua;
+ };
+ script = ''
+ export TOKEN=$(cat ${cfg.tokenPath})
+ ${pkg}/bin/nuogai
+ '';
+ };
+ nuigui = pkg: {
+ serviceConfig.WorkingDirectory = pkg;
+ serviceConfig.ExecStart = "${pkg}/bin/nuigui";
+ environment.PORT = toString cfg.ports.nuigui;
+ };
+ serial-predicate-engine = pkg: {
+ serviceConfig.WorkingDirectory = pkg;
+ serviceConfig.ExecStart = "${pkg}/bin/serial-predicate-engine";
+ environment.PORT = toString cfg.ports.serial-predicate-engine;
};
- script = ''
- export TOKEN=$(cat ${cfg.tokenPath})
- ${inputs.nuogai.packages.${system}.nuogai}/bin/nuogai
- '';
- };
- nuigui = {
- serviceConfig.WorkingDirectory = "${self.packages.nuigui.${system}}";
- serviceConfig.ExecStart = "${cfg.guilePackage} ./web.scm";
- environment.PORT = cfg.nuiPort;
- };
- serial-predicate-engine = {
- serviceConfig.WorkingDirectory = "${self.packages.serial-predicate-engine.${system}}";
- serviceConfig.ExecStart = "${cfg.guilePackage} ./web/webservice.scm";
- environment.PORT = cfg.spePort;
};
- };
};
}