WIP: Fix deps and nix-module
This commit is contained in:
61
module.nix
Normal file
61
module.nix
Normal file
@@ -0,0 +1,61 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.pvv-doorbell-bot;
|
||||
inherit (lib) mkDefault mkEnableOption mkPackageOption mkIf mkOption types mdDoc;
|
||||
in
|
||||
{
|
||||
options.services.pvv-doorbell-bot = {
|
||||
enable = mkEnableOption (lib.mdDoc "Enable the doorbell service that alerts on matrix/discord pings");
|
||||
|
||||
package = mkPackageOption pkgs "pvv-doorbell-bot" { };
|
||||
nodePackage = mkPackageOption pkgs "nodejs_20" { };
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "pvv-doorbell-bot";
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "pvv-doorbell-bot";
|
||||
};
|
||||
|
||||
settings = {
|
||||
configFile = mkOption {
|
||||
type = types.path;
|
||||
description = mdDoc "Path to secret config.json file that sets the options defined in `config.json.template`";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
users.users = mkIf (cfg.user == "pvv-doorbell-bot") {
|
||||
pvv-doorbell-bot = {
|
||||
description = "PVV Doorbell Matrix Bot User";
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
};
|
||||
};
|
||||
|
||||
users.groups = mkIf (cfg.group == "pvv-doorbell-bot") {
|
||||
pvv-doorbell-bot = { };
|
||||
};
|
||||
|
||||
systemd.services."pvv-doorbell-bot" = {
|
||||
serviceConfig = let
|
||||
appDir = "${cfg.package}/lib/node_modules/doorbell-matrix-bot";
|
||||
in {
|
||||
ExecStart = "${lib.getExe cfg.nodePackage} ${appDir}/index.mjs";
|
||||
WorkingDirectory = appDir;
|
||||
RuntimeDirectory = "pvv-doorbell-bot";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
};
|
||||
|
||||
environment = {
|
||||
DOORBELL_CONFIG_FILE = cfg.settings.configFile;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user