Files
relay-exporter/flake.nix
T
plebandClaude Opus 5.5 741144d300 Bump to nixos-26.05, Node 26 LTS, and pnpm 11
- nixpkgs: nixos-25.11 -> nixos-26.05
- Node: nodejs_22 -> nodejs_26; @types/node ^25 -> ^26
- pnpm: pin pnpm_11 in build and devShell (pnpm_10 is marked insecure
  in 26.05); packageManager pnpm@10.28.0 -> pnpm@11.27.0
- Migrate to top-level fetchPnpmDeps/pnpmConfigHook and
  fetcherVersion 4 (v1 is removed in 26.11); regenerate deps hash
- Add pnpm-workspace.yaml declining dependency build scripts, which
  pnpm 11 requires to be decided explicitly
- Add CLAUDE.md with layout, commands, and update checklist

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:10:42 -08:00

177 lines
5.3 KiB
Nix

{
description = "Nostr relay Prometheus exporter";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
};
outputs = { self, nixpkgs }:
let
inherit (nixpkgs.lib) genAttrs;
systems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = genAttrs systems;
mkPackage = pkgs:
let
pname = "relay-exporter";
version = "0.1.0";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
!(pkgs.lib.hasInfix "/.git/" path)
&& !(pkgs.lib.hasInfix "/node_modules/" path)
&& !(pkgs.lib.hasInfix "/dist/" path);
};
in
pkgs.stdenv.mkDerivation {
inherit pname version;
inherit src;
nativeBuildInputs = [
pkgs.nodejs_26
pkgs.pnpm_11
pkgs.pnpmConfigHook
pkgs.makeWrapper
];
pnpmDeps = pkgs.fetchPnpmDeps {
inherit pname version src;
pnpm = pkgs.pnpm_11;
fetcherVersion = 4;
hash = "sha256-M2Wa9KPZRf+/vFUyPYkMed4tLmrtGFEYZcIJVR2Jj6A=";
};
buildPhase = ''
runHook preBuild
pnpm run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/app $out/bin
cp -r dist package.json node_modules $out/app/
makeWrapper ${pkgs.nodejs_26}/bin/node $out/bin/relay-exporter \
--set NODE_ENV production \
--add-flags "$out/app/dist/index.js"
runHook postInstall
'';
meta = {
description = "Prometheus exporter for Nostr relay health checks";
mainProgram = "relay-exporter";
license = pkgs.lib.licenses.mit;
platforms = pkgs.lib.platforms.linux;
};
};
in
rec {
packages = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
pkg = mkPackage pkgs;
in
{
relay-exporter = pkg;
default = pkg;
});
devShells = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = pkgs.mkShell {
packages = [
pkgs.nodejs_26
pkgs.pnpm_11
];
};
});
overlays.default = final: prev: {
relay-exporter = self.packages.${prev.stdenv.hostPlatform.system}.relay-exporter;
};
nixosModules.default =
{ config, lib, pkgs, ... }:
let
inherit (lib) mkEnableOption mkIf mkOption types;
cfg = config.services.relay-exporter;
system = pkgs.stdenv.hostPlatform.system;
defaultPackage = self.packages.${system}.relay-exporter;
in
{
options.services.relay-exporter = {
enable = mkEnableOption "relay-exporter service";
package = mkOption {
type = types.package;
default = defaultPackage;
defaultText = "self.packages.${system}.relay-exporter";
description = "Derivation that provides relay-exporter.";
};
port = mkOption {
type = types.port;
default = 9464;
description = "HTTP listen port for relay-exporter.";
};
listenAddr = mkOption {
type = types.str;
default = "0.0.0.0";
description = "Listen address for relay-exporter.";
};
stateDirectory = mkOption {
type = types.str;
default = "relay-exporter";
description = "Name of the state directory managed by systemd.";
};
environment = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Additional environment variables for relay-exporter.";
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = "Optional environment file consumed by systemd.";
};
};
config = mkIf cfg.enable {
systemd.services.relay-exporter = {
description = "Nostr relay Prometheus exporter";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
environment = {
NODE_ENV = "production";
PORT = builtins.toString cfg.port;
LISTEN_ADDR = cfg.listenAddr;
} // cfg.environment;
serviceConfig =
{
Type = "simple";
ExecStart = "${cfg.package}/bin/relay-exporter";
DynamicUser = true;
StateDirectory = cfg.stateDirectory;
WorkingDirectory = "/var/lib/${cfg.stateDirectory}";
Restart = "on-failure";
RestartSec = 3;
}
// lib.optionalAttrs (cfg.environmentFile != null) {
EnvironmentFile = cfg.environmentFile;
};
};
};
};
};
}