WIP: Fix deps and nix-module
This commit is contained in:
parent
cec320746b
commit
526fec467c
18
flake.nix
18
flake.nix
|
@ -23,19 +23,23 @@
|
||||||
src = lib.fileset.toSource {
|
src = lib.fileset.toSource {
|
||||||
root = ./.;
|
root = ./.;
|
||||||
fileset = lib.fileset.difference ./. (lib.fileset.unions [
|
fileset = lib.fileset.difference ./. (lib.fileset.unions [
|
||||||
./flake.nix
|
./module.nix
|
||||||
./flake.lock
|
./flake.lock
|
||||||
|
./flake.nix
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
npmDepsHash = "sha256-UNc902yMkoWfpun1RrLYlEtOXcFd7uxlwKFWoM0/nTE=";
|
npmDepsHash = "sha256-518ln/eAlgnKcubOTquBP8gj9Q/lT5bhpJGWOeuUKmY=";
|
||||||
|
|
||||||
postInstall = ''
|
|
||||||
ln -vs /run/secrets/pvv-doorbell-config.json $out/lib/node_modules/$pname/config.json
|
|
||||||
'';
|
|
||||||
dontNpmBuild = true;
|
dontNpmBuild = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
|
overlays = forAllSystems (system: {
|
||||||
|
default = prevPackages: finalPackages: {
|
||||||
|
pvv-doorbell-bot = self.packages.${system}.default;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
nixosModules.default = import ./module.nix;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ import {
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import config from "./config.json" assert {type: "json"};
|
import { env } from 'node:process';
|
||||||
|
|
||||||
|
const config = await import (env.DOORBELL_CONFIG_FILE || "./config.json"); // assert {type: "json"};
|
||||||
|
|
||||||
const homeserverUrl = config.homeserver;
|
const homeserverUrl = config.homeserver;
|
||||||
const token = config.token;
|
const token = config.token;
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@
|
||||||
"author": "henrkgr",
|
"author": "henrkgr",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.4"
|
"axios": "^1.7.4",
|
||||||
|
"matrix-bot-sdk": "^0.7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue