-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
67 lines (56 loc) · 2.09 KB
/
module.nix
File metadata and controls
67 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ config, lib, pkgs, ... }:
let
cfg = config.services.nix-btm;
in
{
options.services.nix-btm = {
enable = lib.mkEnableOption "nix-btm build monitoring";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.nix-btm or (throw "nix-btm package not found; add the flake overlay or set services.nix-btm.package");
description = "The nix-btm Rust package (provides nix-btmd and nix-btm binaries).";
};
pluginPackage = lib.mkOption {
type = lib.types.package;
default = pkgs.nix-btm-plugin or (throw "nix-btm-plugin package not found; add the flake overlay or set services.nix-btm.pluginPackage");
description = "The nix-btm C++ plugin package (provides libnix-btm.so).";
};
socketDir = lib.mkOption {
type = lib.types.str;
default = "/run/nix-btm";
description = ''
Directory for the daemon's Unix sockets (events.sock and control.sock).
Override this for rootless nix or custom deployments. The daemon, TUI, and
ctl tool all respect the NIX_BTM_SOCKET_DIR environment variable,
which this option sets.
'';
};
};
config = lib.mkIf cfg.enable {
nix.settings = {
plugin-files = [ "${cfg.pluginPackage}/lib/libnix-btm.so" ];
use-cgroups = true;
};
# Tell the plugin where to send events when using a custom socket dir.
nix.extraOptions = lib.mkIf (cfg.socketDir != "/run/nix-btm") ''
btm-socket = ${cfg.socketDir}/events.sock
'';
systemd.tmpfiles.rules = [
"d ${cfg.socketDir} 0755 root root -"
];
systemd.services.nix-btmd = {
description = "Nix BTM Daemon";
after = [ "nix-daemon.service" ];
wantedBy = [ "multi-user.target" ];
environment.NIX_BTM_SOCKET_DIR = cfg.socketDir;
serviceConfig = {
ExecStart = "${cfg.package}/bin/nix-btmd";
Restart = "always";
RestartSec = 2;
};
};
# Set the env var system-wide so TUI and ctl find the sockets.
environment.sessionVariables.NIX_BTM_SOCKET_DIR = cfg.socketDir;
environment.systemPackages = [ cfg.package ];
};
}