Compare commits

...

1 Commits

Author SHA1 Message Date
3e108f4de3
WIP: Fix deps and nix-module 2024-08-24 23:02:55 +02:00
6 changed files with 1841 additions and 12 deletions

View File

@ -14,7 +14,7 @@
package-json = lib.importJSON ./package.json;
in {
default = pkgs.buildNpmPackage {
default = pkgs.stdenv.mkDerivation {
pname = package-json.name;
version = package-json.version;
meta.homepage = package-json.repository.url;
@ -23,19 +23,34 @@
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.difference ./. (lib.fileset.unions [
./flake.nix
./module.nix
./flake.lock
./flake.nix
]);
};
npmDepsHash = "sha256-UNc902yMkoWfpun1RrLYlEtOXcFd7uxlwKFWoM0/nTE=";
postInstall = ''
ln -vs /run/secrets/pvv-doorbell-config.json $out/lib/node_modules/$pname/config.json
'';
nativeBuildInputs = with pkgs; [
importNpmLock.hooks.npmConfigHook
nodejs
# nodejs.passthru.python # for node-gyp
npmHooks.npmBuildHook
npmHooks.npmInstallHook
];
dontNpmBuild = true;
npmDeps = pkgs.importNpmLock {
npmRoot = ./.;
};
};
});
};
overlays = forAllSystems (system: {
default = prevPackages: finalPackages: {
pvv-doorbell-bot = self.packages.${system}.default;
};
});
nixosModules.default = import ./module.nix;
};
}

View File

@ -7,7 +7,9 @@ import {
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 token = config.token;
@ -130,4 +132,4 @@ async function handleCommand(roomId, event) {
};
client.sendMessage(roomId, event);
}
}

61
module.nix Normal file
View 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;
};
};
};
}

1751
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@
"author": "henrkgr",
"license": "ISC",
"dependencies": {
"axios": "^1.7.4"
"axios": "^1.7.4",
"matrix-bot-sdk": "^0.7.1"
}
}

1
result Symbolic link
View File

@ -0,0 +1 @@
/nix/store/4688vk323al998nig45cs94mxj5rjf9k-doorbell-matrix-bot-1.0.0