nixos/beszel.agent: Default service unit hardening interferes with Intel iGPU monitoring
Nixpkgs version
- Stable (25.11)
Describe the bug
The service unit directives NoNewPrivileges=true, PrivateUsers=true, and SystemCallFilter = [ "@system-service" ] prevent monitoring of Intel iGPUs using intel_gpu_top. PrivateDevices=true also interferes although I believe this was fixed in https://github.com/NixOS/nixpkgs/pull/508090. Additionally, the CAP_PERFMON capability is required to run intel_gpu_top as a non-root user. To allow monitoring the service configuration must be overridden with:
systemd.services.beszel-agent.serviceConfig = {
# Enable CAP_PERFMON in service unit
AmbientCapabilities = [ "CAP_PERFMON" ];
CapabilityBoundingSet = [ "CAP_PERFMON" ];
# Allow privilages to be inherited by child processes
NoNewPrivileges = lib.mkForce false;
# Prevent namespace scoping
PrivateUsers = lib.mkForce false;
# Allow Beszel agent to access devices generally
PrivateDevices = lib.mkForce false;
# Allow Beszel agent access to Intel GPU devices
DeviceAllow = [
"/dev/dri/card1 rw"
"/dev/dri/renderD128 rw"
];
# Prevent filtering of perf_event_open system calls
SystemCallFilter = lib.mkForce [
"@system-service"
"perf_event_open"
];
};
The docs also suggest lowering the perf_event_paranoid kernel parameter to <2, although I'm not sure if this is generally in the scope of a NixOS module. Similarly to https://github.com/NixOS/nixpkgs/issues/507976, the docs advise adding the GPU devices to the DeviceAllow list, as shown above.
Steps to reproduce
Configure services.beszel.agent with the services.beszel.agent.environment.GPU_COLLECTOR = "intel_gpu_top" option. Post https://github.com/NixOS/nixpkgs/pull/508090 I think this would be configured automatically when services.beszel.agent.environment.SKIP_gpu = false (default) and config.services.xserver.videoDrivers = [ "intel" ]
Expected behaviour
iGPU monitoring should be displayed in the Beszel hub.
Screenshots
No response
Relevant log output
Additional context
Failure to configure the options mentioned above results in errors of no valid GPU data or the GPU data map being empty.
System metadata
- system:
"x86_64-linux" - host os:
Linux 6.17.13-2-pve, NixOS, 26.05 (Yarara), 26.05.20260405.68d8aa3 - multi-user?:
yes - sandbox:
yes - version:
nix-env (Nix) 2.31.3+1 - nixpkgs:
/nix/store/gay80fqbpm2wakbsyd4in44gx0cwx3h5-source
Notify maintainers
@BonusPlay @arunoruto
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- [x] I assert that this is a bug and not a support request.
- [x] I assert that this is not a duplicate of an existing issue.
- [x] I assert that I have read the NixOS Code of Conduct and agree to abide by it.
Is this issue important to you?
Add a :+1: reaction to issues you find important.
Thanks for the helpful remarks!
Having senSetting DeviceAllow would be a bit tricky, since each systemsible default values for DeviceAllow would be a bit complicated, since each system behaves differently in that regard... PrivateDevices = lib.mkForce false; should be enough in most cases tho. Can you test if it works like that?
If not, we would have to look into creating separate gpu options to allow finer adjustments to the settings!
Can confirm! iGPU monitoring works for me with DeviceAllow removed.
Can confirm! iGPU monitoring works for me with
DeviceAllowremoved.
Thanks for checking! Would be good to know what minimal working example would be in this case so we can tweak things. But it seems like intel needs more requirements compared to nvidia and amd...
For me this was the minimal configuration, taking anything out broke it:
{
lib,
pkgs,
...
}:
services.beszel.agent = {
environment = {
GPU_COLLECTOR = "intel_gpu_top";
};
extraPath = [
# Not needed if using services.xserver.videoDrivers
pkgs.intel-gpu-tools
];
};
systemd.services.beszel-agent.serviceConfig = {
AmbientCapabilities = [ "CAP_PERFMON" ];
PrivateUsers = lib.mkForce false;
PrivateDevices = lib.mkForce false;
SystemCallFilter = lib.mkForce [
"@system-service"
"perf_event_open"
];
};
}
I should note I'm running this inside a privileged Proxmox LXC container, although I don't think that should change things.
As for Intel's requirements, in my (very limited) understanding, intel_gpu_top calls the perf_events kernel tool to get its data (which I guess other tools don't?). To do this as an unprivileged user on systems with kernel.perf_event_paranoid <= 2 (I think 2 is a common default) the systemd service needs the CAP_PERFMON ambient capability and the perf_event_open system call filter. NoNewPrivilages=false is needed to pass CAP_PERFMON to the child process (which I guess is running intel_gpu_top?).
Apologies if this is obvious and I'm over-explaining, a lot of this is new to me and I'm trying to wrap my head around it!
EDIT: Removed NoNewPrivilages = false as unnecessary.
I am totally not in it and I need to read up a few of the systemd options too!
Can you check if NoNewPrivileges can be set to true? It is kinds weird that this feature is needed to run it while the CAP_PERFMON is enabled!
I will try to incorporate intel specific changes in the open PR. Beszel updates take some time... Maybe I should apply for a commiters bit, but still not sure abt it 😂
I thought I'd tested removing each entry in the minimal configuration, but apparently I hadn't. Just tried it with NoNewPrivileges set to true and it totally still works.
Thanks for testing it out!
That makes me question if we need it for smartmon, but thats maybe for some other time!
I am drafting a potential PR to make configuring GPU configs a bit easier using the GPU_COLLECTOR variable.
But I must say, the module is becoming more and more complicated 😂
I updated #508090 with some changes that could benefit your problem! Could you take a look?
It looks good to me! As far as I can tell my minimal configuration from before would be reduced to:
{
...
}:
{
services.beszel.agent = {
environment = {
GPU_COLLECTOR = "intel_gpu_top";
};
};
}
which is ideal 😃
Thanks so much for your quick work on this! How long do changes usually take to get merged?
Small correction: GPU_COLLECTOR = [ "intel_gpu_top" ]; (It has to be a list, but the resulting error would be clear enough to know what happened).
Merges can take a while, especially since I am waiting on feedback for my implementation! Some big changes were made and I would like everyone to give their comments on it.
Buut, if you want, just create a custom beszel agent module and run it yourself!
To do so, you need to disable the provided one first. I am usually having one of those to test PRs and make my own changes on top of them to make them work!
Create a file, for example beszel/module.nix with:
{...}:
{
disabledModules = [ "services/monitoring/beszel-agent.nix" ];
# copy here the contents of https://github.com/arunoruto/nixpkgs/blob/b09294fb36f0623609f12c639c4a0c74c4e88370/nixos/modules/services/monitoring/beszel-agent.nix
# or whatever you like
}
Then I typically have a beszel/default.nix file which imports the local module.nix file and configures beszel iteself...
{...}:
{
imports = [ ./module.nix ];
services.beszel.agent = {
# ...
};
}
There are probably better ways to try out PRs, but this is the way I am doing it. I like it especially since I can thinker with the PR myself then!
Ah okay, I see why it would take some time for the merge to complete. Thanks for the disabledModules tip, I've never heard of that before (always something new with NixOS) I'll give it a go for sure 🤠