merge
This commit is contained in:
63
modules/nixos/glances/default.nix
Normal file
63
modules/nixos/glances/default.nix
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
namespace,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.${namespace}.services.glances;
|
||||
in
|
||||
{
|
||||
imports = [ ./options.nix ];
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
# Open firewall for glances if enabled
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [ cfg.port ];
|
||||
allowedUDPPorts = [ cfg.port ];
|
||||
};
|
||||
|
||||
# Install glances package
|
||||
environment.systemPackages = with pkgs; [
|
||||
glances
|
||||
];
|
||||
|
||||
# Configure systemd service for glances
|
||||
systemd.services.glances-server = {
|
||||
description = "Glances system monitoring web server";
|
||||
enable = true;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
path = with pkgs; [
|
||||
bash
|
||||
glances
|
||||
];
|
||||
|
||||
script = ''
|
||||
glances -w --bind ${cfg.bindAddress} --port ${toString cfg.port}
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = "glances";
|
||||
Group = "glances";
|
||||
Restart = "always";
|
||||
RestartSec = "5";
|
||||
StandardOutput = "journal";
|
||||
StandardError = "journal";
|
||||
};
|
||||
};
|
||||
|
||||
# Create glances user and group
|
||||
users.users.glances = {
|
||||
isSystemUser = true;
|
||||
group = "glances";
|
||||
description = "Glances monitoring user";
|
||||
};
|
||||
|
||||
users.groups.glances = { };
|
||||
};
|
||||
}
|
||||
25
modules/nixos/glances/options.nix
Normal file
25
modules/nixos/glances/options.nix
Normal file
@@ -0,0 +1,25 @@
|
||||
{ lib, namespace, ... }:
|
||||
with lib;
|
||||
{
|
||||
options.${namespace}.services.glances = {
|
||||
enable = mkEnableOption "glances system monitoring service";
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 61208;
|
||||
description = "Port for glances web interface";
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Whether to open firewall for glances";
|
||||
};
|
||||
|
||||
bindAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "0.0.0.0";
|
||||
description = "Address to bind glances web server to";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user