Skip to content

Commit cf69fc2

Browse files
authored
nixos/glances: init (#303320)
2 parents 3a2110a + d174bf4 commit cf69fc2

File tree

8 files changed

+182
-0
lines changed

8 files changed

+182
-0
lines changed

maintainers/maintainer-list.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,6 +4134,12 @@
41344134
githubId = 43564;
41354135
name = "Claes Holmerson";
41364136
};
4137+
claha = {
4138+
email = "[email protected]";
4139+
github = "claha";
4140+
githubId = 9336788;
4141+
name = "Claes Hallström";
4142+
};
41374143
clebs = {
41384144
email = "[email protected]";
41394145
github = "clebs";

nixos/doc/manual/release-notes/rl-2411.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197

198198
- [Zapret](https://github.com/bol-van/zapret), a DPI bypass tool. Available as [services.zapret](option.html#opt-services.zapret.enable).
199199

200+
- [Glances](https://github.com/nicolargo/glances), an open-source system cross-platform monitoring tool. Available as [services.glances](option.html#opt-services.glances).
201+
200202
## Backward Incompatibilities {#sec-release-24.11-incompatibilities}
201203

202204
- Nixpkgs now requires Nix 2.3.17 or newer to allow for zstd compressed binary artifacts.

nixos/modules/module-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@
888888
./services/monitoring/do-agent.nix
889889
./services/monitoring/fusion-inventory.nix
890890
./services/monitoring/gatus.nix
891+
./services/monitoring/glances.nix
891892
./services/monitoring/goss.nix
892893
./services/monitoring/grafana-agent.nix
893894
./services/monitoring/grafana-image-renderer.nix
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Glances {#module-serives-glances}
2+
3+
Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS
4+
and Windows operating systems.
5+
6+
Visit [the Glances project page](https://github.com/nicolargo/glances) to learn
7+
more about it.
8+
9+
# Quickstart {#module-serives-glances-quickstart}
10+
11+
Use the following configuration to start a public instance of Glances locally:
12+
13+
```nix
14+
{
15+
services.glances = {
16+
enable = true;
17+
openFirewall = true;
18+
};
19+
};
20+
```
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
pkgs,
3+
config,
4+
lib,
5+
utils,
6+
...
7+
}:
8+
let
9+
cfg = config.services.glances;
10+
11+
inherit (lib)
12+
getExe
13+
maintainers
14+
mkEnableOption
15+
mkOption
16+
mkIf
17+
mkPackageOption
18+
;
19+
20+
inherit (lib.types)
21+
bool
22+
listOf
23+
port
24+
str
25+
;
26+
27+
inherit (utils)
28+
escapeSystemdExecArgs
29+
;
30+
31+
in
32+
{
33+
options.services.glances = {
34+
enable = mkEnableOption "Glances";
35+
36+
package = mkPackageOption pkgs "glances" { };
37+
38+
port = mkOption {
39+
description = "Port the server will isten on.";
40+
type = port;
41+
default = 61208;
42+
};
43+
44+
openFirewall = mkOption {
45+
description = "Open port in the firewall for glances.";
46+
type = bool;
47+
default = false;
48+
};
49+
50+
extraArgs = mkOption {
51+
type = listOf str;
52+
default = [ "--webserver" ];
53+
example = [
54+
"--webserver"
55+
"--disable-webui"
56+
];
57+
description = ''
58+
Extra command-line arguments to pass to glances.
59+
60+
See https://glances.readthedocs.io/en/latest/cmds.html for all available options.
61+
'';
62+
};
63+
};
64+
65+
config = mkIf cfg.enable {
66+
67+
environment.systemPackages = [ cfg.package ];
68+
69+
systemd.services."glances" = {
70+
description = "Glances";
71+
after = [ "network.target" ];
72+
wantedBy = [ "multi-user.target" ];
73+
74+
serviceConfig = {
75+
Type = "simple";
76+
DynamicUser = true;
77+
ExecStart = "${getExe cfg.package} --port ${toString cfg.port} ${escapeSystemdExecArgs cfg.extraArgs}";
78+
Restart = "on-failure";
79+
80+
NoNewPrivileges = true;
81+
ProtectSystem = "full";
82+
ProtectHome = true;
83+
PrivateTmp = true;
84+
PrivateDevices = true;
85+
ProtectKernelTunables = true;
86+
ProtectKernelModules = true;
87+
ProtectKernelLogs = true;
88+
ProtectControlGroups = true;
89+
MemoryDenyWriteExecute = true;
90+
RestrictAddressFamilies = [
91+
"AF_INET"
92+
"AF_INET6"
93+
"AF_NETLINK"
94+
"AF_UNIX"
95+
];
96+
LockPersonality = true;
97+
RestrictRealtime = true;
98+
ProtectClock = true;
99+
ReadWritePaths = [ "/var/log" ];
100+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
101+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
102+
SystemCallFilter = [ "@system-service" ];
103+
};
104+
};
105+
106+
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
107+
};
108+
109+
meta.maintainers = with maintainers; [ claha ];
110+
}

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ in {
383383
gitolite = handleTest ./gitolite.nix {};
384384
gitolite-fcgiwrap = handleTest ./gitolite-fcgiwrap.nix {};
385385
glance = runTest ./glance.nix;
386+
glances = runTest ./glances.nix;
386387
glusterfs = handleTest ./glusterfs.nix {};
387388
gnome = handleTest ./gnome.nix {};
388389
gnome-extensions = handleTest ./gnome-extensions.nix {};

nixos/tests/glances.nix

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{ lib, ... }:
2+
3+
{
4+
name = "glances";
5+
6+
nodes = {
7+
machine_default =
8+
{ pkgs, ... }:
9+
{
10+
services.glances = {
11+
enable = true;
12+
};
13+
};
14+
15+
machine_custom_port =
16+
{ pkgs, ... }:
17+
{
18+
services.glances = {
19+
enable = true;
20+
port = 5678;
21+
};
22+
};
23+
};
24+
25+
testScript = ''
26+
machine_default.start()
27+
machine_default.wait_for_unit("glances.service")
28+
machine_default.wait_for_open_port(61208)
29+
30+
machine_custom_port.start()
31+
machine_custom_port.wait_for_unit("glances.service")
32+
machine_custom_port.wait_for_open_port(5678)
33+
'';
34+
35+
meta.maintainers = [ lib.maintainers.claha ];
36+
}

pkgs/applications/system/glances/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
packaging,
99
psutil,
1010
setuptools,
11+
pydantic,
12+
nixosTests,
1113
# Optional dependencies:
1214
fastapi,
1315
jinja2,
@@ -69,6 +71,10 @@ buildPythonApplication rec {
6971
prometheus-client
7072
] ++ lib.optional stdenv.hostPlatform.isLinux hddtemp;
7173

74+
passthru.tests = {
75+
service = nixosTests.glances;
76+
};
77+
7278
meta = {
7379
homepage = "https://nicolargo.github.io/glances/";
7480
description = "Cross-platform curses-based monitoring tool";

0 commit comments

Comments
 (0)