WIP: Fix deps and nix-module
This commit is contained in:
parent
cec320746b
commit
3e108f4de3
31
flake.nix
31
flake.nix
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.4"
|
||||
"axios": "^1.7.4",
|
||||
"matrix-bot-sdk": "^0.7.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue