Skip to content

Commit

Permalink
nix: +nixosModules.typst-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
leana8959 committed Sep 29, 2024
1 parent 984a4c8 commit a6707d1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nix/nixosModules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let
"zram"
"i_am_builder"
"fish-vendor-completions"

"typst-bot"
];

sharedModules.imports = map toModule sharedModuleNames;
Expand Down
79 changes: 79 additions & 0 deletions nix/nixosModules/typst-bot/default.nix
Original file line number Diff line number Diff line change
@@ -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
];
};

};

};

}

0 comments on commit a6707d1

Please sign in to comment.