server | add beszel agent

This commit is contained in:
Don Harper 2025-01-15 21:47:28 -06:00
parent d335f0f779
commit fc6fa24832
2 changed files with 100 additions and 1 deletions

View file

@ -23,7 +23,13 @@ in {
options = "--delete-older-than 7d";
};
};
imports = [ ../../home ./systemd.nix ./tailscale.nix ./upgrade-diff.nix ];
imports = [
../../home
./systemd.nix
./tailscale.nix
./upgrade-diff.nix
../../modules/beszel-agent.nix
];
# Enable networking
networking.networkmanager.enable = true;
@ -78,6 +84,7 @@ in {
services = {
pcscd = { enable = true; };
beszel-agent = { enable = true; };
avahi = {
enable = true;
nssmdns4 = true;

92
modules/beszel-agent.nix Normal file
View file

@ -0,0 +1,92 @@
# modules/beszel-agent.nix
{ inputs, outputs, config, lib, pkgs, ... }:
with lib;
let cfg = config.services.beszel-agent;
in {
options.services.beszel-agent = {
enable = mkEnableOption "Beszel agent service";
# package = mkOption {
# type = types.package;
# default = pkgs.beszel;
# description = "The beszel package to use.";
# };
port = mkOption {
type = types.port;
default = 45876;
description = "Port number for the beszel agent to listen on.";
};
key = mkOption {
type = types.str;
default = ''
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID3EsSeb3/DaYLXkyRJqTFAh8PDo8JRPYC6X2K1U6yjW"'';
description = "SSH key for the beszel agent.";
};
extraFilesystems = mkOption {
type = types.listOf types.str;
default = [ "/" ];
description = "List of additional filesystems to monitor.";
};
user = mkOption {
type = types.str;
default = "root";
description = "User account under which the service runs.";
};
groups = mkOption {
type = types.listOf types.str;
default = [ "root" ];
description = "Groups under which the service runs.";
};
restartSec = mkOption {
type = types.int;
default = 5;
description = "Time to wait before restarting the service.";
};
gpu = mkOption {
type = types.bool;
default = false;
description = "Sets env var to enable GPU monitoring.";
};
};
config = mkIf cfg.enable {
# users.users.${cfg.user} = {
# isSystemUser = true;
# group = builtins.head cfg.groups;
# extraGroups = builtins.tail cfg.groups;
# description = "Beszel Agent service user";
# };
# #users.groups.${cfg.group} = {};
# users.groups = builtins.listToAttrs (map (g: { name = g; value = {}; }) cfg.groups);
environment.systemPackages = with pkgs; [ beszel ];
systemd.services.beszel-agent = {
description = "Beszel Agent Service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Environment = [
"KEY=${cfg.key}"
"EXTRA_FILESYSTEMS=${concatStringsSep "," cfg.extraFilesystems}"
"PATH=/run/current-system/sw/bin:$PATH"
];
ExecStart = "/run/current-system/sw/bin/beszel-agent";
User = cfg.user;
Group = builtins.head cfg.groups;
Restart = "always";
RestartSec = cfg.restartSec;
};
};
};
}