-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
158 lines (136 loc) · 4.61 KB
/
flake.nix
File metadata and controls
158 lines (136 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{
description = "高性能読み上げ Discord Bot (VOICEVOX Core + DPP)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
voicevoxCoreDir = "/opt/voicevox_core";
tts-bot = pkgs.stdenv.mkDerivation {
pname = "tts-bot";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
cmake
pkg-config
];
buildInputs = with pkgs; [
dpp
openssl
zlib
libopus
sqlite
spdlog
];
cmakeFlags = [
"-DENABLE_VOICEVOX=OFF"
"-DBUILD_TESTS=OFF"
];
meta = {
description = "高性能読み上げ Discord Bot";
license = pkgs.lib.licenses.mit;
mainProgram = "tts-bot";
};
};
tts-bot-voicevox = tts-bot.overrideAttrs (old: {
pname = "tts-bot-voicevox";
cmakeFlags = [
"-DENABLE_VOICEVOX=ON"
"-DVOICEVOX_CORE_DIR=${voicevoxCoreDir}/c_api"
"-DBUILD_TESTS=OFF"
];
postFixup = ''
patchelf --add-rpath ${voicevoxCoreDir}/c_api/lib $out/bin/tts-bot
patchelf --add-rpath ${voicevoxCoreDir}/onnxruntime/lib $out/bin/tts-bot
'';
});
in
{
packages = {
default = tts-bot;
voicevox = tts-bot-voicevox;
};
devShells.default = pkgs.mkShell {
inputsFrom = [ tts-bot ];
packages = with pkgs; [
gtest
gbenchmark
clang-tools
valgrind
gdb
];
shellHook = ''
export LD_LIBRARY_PATH="${voicevoxCoreDir}/onnxruntime/lib:${voicevoxCoreDir}/c_api/lib:''${LD_LIBRARY_PATH:-}"
export VOICEVOX_CORE_DIR="${voicevoxCoreDir}"
'';
};
}
) // {
nixosModules.default = { config, lib, pkgs, ... }:
let
cfg = config.services.tts-bot;
in
{
options.services.tts-bot = {
enable = lib.mkEnableOption "TTS Discord Bot";
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.system}.voicevox;
description = "tts-bot パッケージ";
};
voicevoxCoreDir = lib.mkOption {
type = lib.types.path;
default = "/opt/voicevox_core";
description = "VOICEVOX Core のインストールパス";
};
tokenFile = lib.mkOption {
type = lib.types.path;
description = "Discord Bot トークンファイル (sops-nix / agenix 等で管理)";
};
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/tts-bot";
description = "データディレクトリ (SQLite DB 等)";
};
extraEnv = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
description = "追加の環境変数";
};
};
config = lib.mkIf cfg.enable {
systemd.services.tts-bot = {
description = "TTS Discord Bot";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
VOICEVOX_CORE_DIR = toString cfg.voicevoxCoreDir;
LD_LIBRARY_PATH = lib.concatStringsSep ":" [
"${cfg.voicevoxCoreDir}/c_api/lib"
"${cfg.voicevoxCoreDir}/onnxruntime/lib"
];
} // cfg.extraEnv;
serviceConfig = {
ExecStart = "${cfg.package}/bin/tts-bot";
Restart = "always";
RestartSec = 5;
DynamicUser = true;
StateDirectory = "tts-bot";
WorkingDirectory = cfg.dataDir;
LoadCredential = "discord-token:${cfg.tokenFile}";
MemoryMax = "1G";
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = true;
ReadOnlyPaths = [ (toString cfg.voicevoxCoreDir) ];
ReadWritePaths = [ cfg.dataDir ];
};
};
};
};
};
}