nixos: move parrot, typst-bot to common

This commit is contained in:
Primrose 2024-12-21 12:21:23 +01:00
parent ec8d003744
commit 7644f50a1f
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
2 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,56 @@
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.parrot;
t = lib.types;
in
{
options = {
services.parrot = {
enable = lib.mkEnableOption "parrot";
environmentFile = lib.mkOption {
description = "Path to an environment file, you can set the token there";
type = t.path;
};
};
};
config = lib.mkIf cfg.enable {
users.users."parrot" = {
group = "parrot";
isSystemUser = true;
};
users.groups."parrot" = { };
systemd.services."parrot" = {
description = " A hassle-free, highly performant, self-hosted Discord music bot with YouTube and Spotify support. Powered by yt-dlp.";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "parrot";
Group = "parrot";
EnvironmentFile = cfg.environmentFile;
ExecStart = "${lib.getExe pkgs.parrot}";
};
};
};
}

View file

@ -0,0 +1,79 @@
{
pkgs,
config,
lib,
...
}:
let
cfg = config.services.typst-bot;
t = lib.types;
in
{
options = {
services.typst-bot = {
enable = lib.mkEnableOption "typst-bot";
dataDir = lib.mkOption {
description = "Cache directory";
type = t.path;
default = "/var/typst-bot";
};
environmentFile = lib.mkOption {
description = "Path to an environment file, you can set the token there";
type = t.path;
};
};
};
config = lib.mkIf cfg.enable {
users.users."typst-bot" = {
group = "typst-bot";
isSystemUser = true;
};
users.groups."typst-bot" = { };
systemd.tmpfiles.rules = [
"d ${cfg.dataDir}/cache 700 typst-bot typst-bot - -"
"d ${cfg.dataDir}/sqlite 700 typst-bot typst-bot - -"
];
systemd.services."typst-bot" = {
description = "A discord bot to render Typst code";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
touch ${cfg.dataDir}/sqlite/db.sqlite
'';
# Don't pollute the global path
path = [ pkgs.myPkgs.typst-bot ];
script = "typst-bot";
serviceConfig = {
User = "typst-bot";
Group = "typst-bot";
EnvironmentFile = [
"${pkgs.writeText "typst-bot-env" ''
DB_PATH=${cfg.dataDir}/sqlite/db.sqlite
CACHE_DIRECTORY=${cfg.dataDir}/cache
''}"
cfg.environmentFile
];
};
};
};
}