You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.1 KiB
147 lines
4.1 KiB
{
|
|
inputs.nixpkgs.url = "nixpkgs";
|
|
|
|
outputs = {
|
|
self,
|
|
nixpkgs,
|
|
...
|
|
}: let
|
|
version = builtins.substring 0 7 self.lastModifiedDate;
|
|
|
|
systems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
|
|
forAllSystems = nixpkgs.lib.genAttrs systems;
|
|
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
|
|
|
|
packageFn = pkgs:
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
pname = "discord-cc-bridge";
|
|
inherit version;
|
|
|
|
src = builtins.path {
|
|
name = "source";
|
|
path = ./.;
|
|
};
|
|
|
|
cargoSha256 = "sha256-W0GbOUDQtSeMTq1wl15phRPc+cqONjCizumcoi3qoq4=";
|
|
};
|
|
in rec {
|
|
packages = forAllSystems (s: let
|
|
pkgs = nixpkgsFor.${s};
|
|
in rec {
|
|
discord-cc-bridge = packageFn pkgs;
|
|
default = discord-cc-bridge;
|
|
});
|
|
|
|
devShells = forAllSystems (s: let
|
|
pkgs = nixpkgsFor.${s};
|
|
inherit (pkgs) mkShell;
|
|
in {
|
|
default = mkShell {
|
|
packages = with pkgs; [rustc cargo rustfmt];
|
|
};
|
|
});
|
|
|
|
nixosModules = rec {
|
|
discord-cc-bridge = { config, lib, pkgs, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.services.discord-cc-bridge;
|
|
in {
|
|
options = {
|
|
services.discord-cc-bridge = {
|
|
enable =
|
|
mkEnableOption "Enable discord-cc-bridge relay server";
|
|
|
|
package = mkOption {
|
|
default = packages.${pkgs.system}.discord-cc-bridge;
|
|
type = types.package;
|
|
defaultText = literalExpression "packages.${pkgs.system}.discord-cc-bridge";
|
|
description = lib.mdDoc "discord-cc-bridge derivation to use";
|
|
};
|
|
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "discord-cc-bridge";
|
|
description = lib.mdDoc "User account under which discord-cc-bridge runs.";
|
|
};
|
|
|
|
group = mkOption {
|
|
type = types.str;
|
|
default = "discord-cc-bridge";
|
|
description = lib.mdDoc "Group under which discord-cc-bridge runs.";
|
|
};
|
|
|
|
addr = mkOption {
|
|
type = types.str;
|
|
default = "0.0.0.0:54321";
|
|
description = lib.mdDoc "The socket address to listen to Minecraft connections.";
|
|
};
|
|
|
|
discordToken = mkOption {
|
|
type = types.str;
|
|
description = lib.mdDoc "The discord bot token.";
|
|
};
|
|
|
|
authToken = mkOption {
|
|
type = types.str;
|
|
description = lib.mdDoc "The auth token used by CC.";
|
|
};
|
|
|
|
webhookUrl = mkOption {
|
|
type = types.str;
|
|
description = lib.mdDoc "The webhook URL.";
|
|
};
|
|
|
|
channelId = mkOption {
|
|
type = types.str;
|
|
description = lib.mdDoc "The channel id for the bridge.";
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
systemd.services.discord-cc-bridge = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network-online.target" ];
|
|
description = "discord-cc-bridge relay server";
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
User = cfg.user;
|
|
Group = cfg.group;
|
|
ExecStart =
|
|
"${cfg.package}/bin/discord-cc-bridge";
|
|
};
|
|
|
|
environment = {
|
|
DISCORD_TOKEN = cfg.discordToken;
|
|
BIND_ADDR = cfg.addr;
|
|
AUTH_TOKEN = cfg.authToken;
|
|
WEBHOOK_URL = cfg.webhookUrl;
|
|
CHANNEL_ID = cfg.channelId;
|
|
};
|
|
};
|
|
|
|
users.users = mkIf (cfg.user == "discord-cc-bridge") {
|
|
discord-cc-bridge = {
|
|
description = "discord-cc-bridge relay server";
|
|
useDefaultShell = true;
|
|
group = cfg.group;
|
|
isSystemUser = true;
|
|
};
|
|
};
|
|
|
|
users.groups = mkIf (cfg.group == "discord-cc-bridge") {
|
|
discord-cc-bridge = {};
|
|
};
|
|
};
|
|
};
|
|
default = discord-cc-bridge;
|
|
};
|
|
};
|
|
} |