mirror of
https://github.com/nmasur/dotfiles
synced 2025-04-25 05:02:25 +00:00
semi-failed packaging of actual budget prometheus exporter
This commit is contained in:
parent
562295edb1
commit
11e0992d99
91
pkgs/prometheus-actual-exporter/package.nix
Normal file
91
pkgs/prometheus-actual-exporter/package.nix
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
nodejs_18,
|
||||
buildNpmPackage,
|
||||
nodePackages,
|
||||
python3,
|
||||
gcc,
|
||||
gnumake,
|
||||
}:
|
||||
let
|
||||
|
||||
in
|
||||
|
||||
buildNpmPackage (finalAttrs: rec {
|
||||
pname = "prometheus-actual-exporter";
|
||||
|
||||
version = "1.1.5";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "sakowicz";
|
||||
repo = "actual-budget-prometheus-exporter";
|
||||
tag = version;
|
||||
hash = "sha256-DAmWr1HngxAjhOJW9OnMfDqpxBcZT+Tpew/w/YYJIYU=";
|
||||
};
|
||||
|
||||
patches = [ ./tsconfig.patch ];
|
||||
|
||||
npmDepsHash = "sha256-N8xqRYFelolNGTEhG22M7KJ7B5U/uW7o+/XfLF8rHMg=";
|
||||
|
||||
nativeBuildInputs = [
|
||||
nodejs_18
|
||||
nodePackages.typescript
|
||||
python3
|
||||
nodePackages.node-gyp
|
||||
gcc
|
||||
gnumake
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
echo "Removing better-sqlite3 install script before npm install"
|
||||
sed -i '/"install"/d' node_modules/better-sqlite3/package.json || true
|
||||
sed -i '/"install"/d' package.json || true
|
||||
'';
|
||||
|
||||
preBuild = ''
|
||||
echo "Disabling prebuilt install script from better-sqlite3"
|
||||
find node_modules/better-sqlite3 -name package.json -exec sed -i '/"install"/d' {} +
|
||||
rm -f node_modules/better-sqlite3/build/Release/better_sqlite3.node || true
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
# export npm_config_build_from_source=true
|
||||
# export npm_config_unsafe_perm=true
|
||||
# export BINARY_SITE=none
|
||||
# export PATH=${nodePackages.node-gyp}/bin:$PATH
|
||||
# export npm_config_node_gyp=${nodePackages.node-gyp}/bin/node-gyp
|
||||
|
||||
# npm rebuild better-sqlite3 --build-from-source --verbose
|
||||
|
||||
npm run build
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/{bin,lib}
|
||||
cp -r . $out/lib/prometheus-actual-exporter
|
||||
makeWrapper ${lib.getExe nodejs_18} $out/bin/prometheus-actual-exporter \
|
||||
--add-flags "$out/lib/prometheus-actual-exporter/dist/app.js"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
echo "Removing prebuilt .node and rebuilding better-sqlite3"
|
||||
|
||||
export npm_config_build_from_source=true
|
||||
export npm_config_unsafe_perm=true
|
||||
export BINARY_SITE=none
|
||||
export PATH=${nodePackages.node-gyp}/bin:$PATH
|
||||
export npm_config_node_gyp=${nodePackages.node-gyp}/bin/node-gyp
|
||||
|
||||
sed -i '/"install"/d' node_modules/better-sqlite3/package.json
|
||||
rm -f node_modules/better-sqlite3/build/Release/better_sqlite3.node || true
|
||||
|
||||
npm rebuild better-sqlite3 --build-from-source --verbose
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Prometheus exporter for Actual Budget";
|
||||
homepage = "https://github.com/sakowicz/actual-budget-prometheus-exporter";
|
||||
mainProgram = "prometheus-actual-exporter";
|
||||
};
|
||||
})
|
12
pkgs/prometheus-actual-exporter/tsconfig.patch
Normal file
12
pkgs/prometheus-actual-exporter/tsconfig.patch
Normal file
@ -0,0 +1,12 @@
|
||||
diff --git a/tsconfig.json b/tsconfig.json
|
||||
index 5106135..3a340f6 100644
|
||||
--- a/tsconfig.json
|
||||
+++ b/tsconfig.json
|
||||
@@ -8,5 +8,6 @@
|
||||
"skipLibCheck": true,
|
||||
"lib": ["es2020"],
|
||||
"outDir": "./dist"
|
||||
- }
|
||||
+ },
|
||||
+ "include": ["src/**/*", "app.ts"]
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
@ -18,6 +19,11 @@ in
|
||||
description = "Port to use for the localhost";
|
||||
default = 5006;
|
||||
};
|
||||
prometheusPort = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
description = "Port to use for prometheus actual exporter";
|
||||
default = 5007;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
@ -25,10 +31,30 @@ in
|
||||
services.actual = {
|
||||
enable = true;
|
||||
settings = {
|
||||
port = 5006;
|
||||
port = cfg.port;
|
||||
};
|
||||
};
|
||||
|
||||
# systemd.services.prometheus-actual-exporter = {
|
||||
# enable = true;
|
||||
# description = "Prometheus exporter for Actual budget";
|
||||
# serviceConfig = {
|
||||
# DynamicUser = true;
|
||||
# Environment = [
|
||||
# "ACTUAL_SERVER_URL=https://${hostnames.budget}:443"
|
||||
# "PORT=${builtins.toString cfg.prometheusPort}"
|
||||
# ];
|
||||
# EnvironmentFile = [
|
||||
# config.secrets.actualbudget-password.dest
|
||||
# config.secrets.actualbudget-budget-id.dest
|
||||
# ];
|
||||
# ExecStart = lib.getExe pkgs.nmasur.prometheus-actual-exporter;
|
||||
# };
|
||||
# wantedBy = [
|
||||
# "multi-user.target"
|
||||
# ];
|
||||
# };
|
||||
|
||||
# Used for prometheus exporter
|
||||
virtualisation.podman.enable = true;
|
||||
|
||||
@ -66,7 +92,7 @@ in
|
||||
};
|
||||
|
||||
nmasur.presets.services.prometheus-exporters.scrapeTargets = [
|
||||
"127.0.0.1:5007"
|
||||
"127.0.0.1:${builtins.toString cfg.prometheusPort}"
|
||||
];
|
||||
|
||||
secrets.actualbudget-password = {
|
||||
@ -99,7 +125,7 @@ in
|
||||
services.cloudflare-dyndns.domains = [ hostnames.budget ];
|
||||
|
||||
# Backups
|
||||
services.restic.backups.default.paths = [ "/var/lib/actualbudget" ];
|
||||
services.restic.backups.default.paths = [ "/var/lib/actual" ];
|
||||
|
||||
};
|
||||
|
||||
|
@ -103,8 +103,9 @@ in
|
||||
value = name;
|
||||
}) hostname_map;
|
||||
};
|
||||
|
||||
metrics = { }; # Enables Prometheus metrics
|
||||
};
|
||||
apps.http.servers.metrics = { }; # Enables Prometheus metrics
|
||||
apps.tls.automation.policies = cfg.tlsPolicies;
|
||||
|
||||
# Setup logging to journal and files
|
||||
|
Loading…
x
Reference in New Issue
Block a user