From 852eab538615e550c96c46de955325d42a3412f9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 2 Feb 2025 23:43:31 +0100 Subject: [PATCH] feat: adding the configuration for discord bots --- hosts/fix/configuration.nix | 42 +++++++--------------------- hosts/global.nix | 1 - services/bot_discord/master.nix | 26 +++++++++++++++++ services/bot_discord/music.nix | 26 +++++++++++++++++ services/bot_discord/tempvoc.nix | 17 ++++++----- services/bot_discord/ticket.nix | 16 +++++++---- services/discord.nix | 48 ++++++++++++++++++++++++++++++++ 7 files changed, 130 insertions(+), 46 deletions(-) create mode 100644 services/bot_discord/master.nix create mode 100644 services/bot_discord/music.nix create mode 100644 services/discord.nix diff --git a/hosts/fix/configuration.nix b/hosts/fix/configuration.nix index 36dd8e5..29cdcc7 100644 --- a/hosts/fix/configuration.nix +++ b/hosts/fix/configuration.nix @@ -1,11 +1,20 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: { imports = [ ../global.nix ./hardware-configuration.nix + ../../services/discord.nix ]; + service = { + bot_discord = { + master = true; + music = true; + tempvoc = true; + ticket = true; + }; + }; # Bootloader. boot.loader = { systemd-boot.enable = true; @@ -19,37 +28,6 @@ wireless.enable = false; }; - systemd.services = { - music = { - description = "Enium discord bot for music"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - User = "nobody"; - WorkingDirectory = "/root/music"; - ExecStart = "${pkgs.nodejs}/bin/npm start"; - Environment = "PATH=${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.nodejs}/bin"; - Restart = "on-failure"; - RestartSec = 5; - }; - }; - yagpdb = { - description = "Enium discord master bot"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - User = "nobody"; - WorkingDirectory = "/root/yagpdb/cmd/yagpdb"; - ExecStart = "/root/yagpdb/cmd/yagpdb/yagpdb -all -pa"; - EnvironmentFile = "/root/yagpdb/cmd/yagpdb/sampleenvfile"; - Restart = "on-failure"; - RestartSec = 5; - }; - }; - }; - programs = { steam = { enable = true; diff --git a/hosts/global.nix b/hosts/global.nix index f2c6e1b..899bbe5 100644 --- a/hosts/global.nix +++ b/hosts/global.nix @@ -53,7 +53,6 @@ dconf fastfetch git - go home-manager lego libjpeg diff --git a/services/bot_discord/master.nix b/services/bot_discord/master.nix new file mode 100644 index 0000000..5f5c611 --- /dev/null +++ b/services/bot_discord/master.nix @@ -0,0 +1,26 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.service.bot_discord.master; +in +{ + config = lib.mkIf cfg { + environment.systemPackages = with pkgs; [ + go + ]; + systemd.services.yagpdb = { + description = "Enium discord master bot"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + User = "nobody"; + WorkingDirectory = "/opt/yagpdb/cmd/yagpdb"; + ExecStart = "/opt/yagpdb/cmd/yagpdb/yagpdb -all -pa"; + EnvironmentFile = "/opt/yagpdb/cmd/yagpdb/sampleenvfile"; + Restart = "on-failure"; + RestartSec = 5; + }; + }; + }; +} diff --git a/services/bot_discord/music.nix b/services/bot_discord/music.nix new file mode 100644 index 0000000..90cb294 --- /dev/null +++ b/services/bot_discord/music.nix @@ -0,0 +1,26 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.service.bot_discord.music; +in +{ + config = lib.mkIf cfg { + environment.systemPackages = with pkgs; [ + nodejs + ]; + systemd.services.music = { + description = "Enium discord bot for music"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + User = "nobody"; + WorkingDirectory = "/opt/music"; + ExecStart = "${pkgs.nodejs}/bin/npm start"; + Environment = "PATH=${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.nodejs}/bin"; + Restart = "on-failure"; + RestartSec = 5; + }; + }; + }; +} diff --git a/services/bot_discord/tempvoc.nix b/services/bot_discord/tempvoc.nix index f64cf85..7aad7fc 100644 --- a/services/bot_discord/tempvoc.nix +++ b/services/bot_discord/tempvoc.nix @@ -1,18 +1,21 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: +let + cfg = config.service.bot_discord.tempvoc; +in { - environment.systemPackages = with pkgs; [ - nodejs - ]; - systemd.services.ticket = { - tempvoc = { + config = lib.mkIf cfg { + environment.systemPackages = with pkgs; [ + nodejs + ]; + systemd.services.tempvoc = { description = "Enium discord bot for tempvoc"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "simple"; User = "nobody"; - WorkingDirectory = "/root/tempvoc"; + WorkingDirectory = "/opt/tempvoc"; ExecStart = "${pkgs.nodejs}/bin/npm start"; Environment = "PATH=${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.nodejs}/bin"; Restart = "on-failure"; diff --git a/services/bot_discord/ticket.nix b/services/bot_discord/ticket.nix index cd82296..d5ff374 100644 --- a/services/bot_discord/ticket.nix +++ b/services/bot_discord/ticket.nix @@ -1,17 +1,21 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: +let + cfg = config.service.bot_discord.ticket; +in { - environment.systemPackages = with pkgs; [ - nodejs - ]; - systemd.services.ticket = { + config = lib.mkIf cfg { + environment.systemPackages = with pkgs; [ + nodejs + ]; + systemd.services.ticket = { description = "Service for ticket"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "simple"; User = "nobody"; - WorkingDirectory = "/root/ticket"; + WorkingDirectory = "/opt/ticket"; ExecStart = "${pkgs.nodejs}/bin/npm start"; Environment = "PATH=${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.nodejs}/bin"; Restart = "on-failure"; diff --git a/services/discord.nix b/services/discord.nix new file mode 100644 index 0000000..94c0ac6 --- /dev/null +++ b/services/discord.nix @@ -0,0 +1,48 @@ +{ config, pkgs, lib, ... }: + +let + master_bot = import ./bot_discord/master.nix { + inherit config pkgs lib; + }; + music_bot = import ./bot_discord/music.nix { + inherit config pkgs lib; + }; + tempvoc_bot = import ./bot_discord/tempvoc.nix { + inherit config pkgs lib; + }; + ticket_bot = import ./bot_discord/ticket.nix { + inherit config pkgs lib; + }; + cfg = config.service.bot_discord; +in +{ + imports = [ + master_bot + music_bot + tempvoc_bot + ticket_bot + ]; + + options.service.bot_discord = { + master = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable master bot"; + }; + music = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable music bot"; + }; + tempvoc = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable tempvoc bot"; + }; + ticket = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable ticket bot"; + }; + }; +}