I import the following in my configuration.nix, but the gid/mode options have no effect, even after reboot, even though /etc/fstab reflects the changes!:
{ config, lib, pkgs, ... }:
{
boot.kernel.sysctl = {
"vm.nr_hugepages" = 512; # Adjust the number based on your needs
};
fileSystems."/dev/hugepages" = {
device = "hugetlbfs";
fsType = "hugetlbfs";
options = [ "mode=1770" "gid=100" ]; # 100 is typically the GID for the "users" group
};
}
$ ls -ld /dev/hugepages
drwxr-xr-x 2 root root 0 May 3 12:45 /dev/hugepages
There is a 4 year old thread where somebody is trying to do this for a different filesystem type, but it has no answers, which is surprising to me because this doesn’t seem like this should be that far off the beaten path.
Questions:
Why doesn’t NixOS respect its own changes to /etc/fstab?
That’s showing you the permissions of the mount point. Usually, mode and gid parameters on filesystems affect the contents of the filesystem, not the mount point itself. Do the contents of /dev/hugepages have the correct bits?
There’s no contents in there to start (it’s a memory only filesystem), so I have to switch to root to make something in there, and then the file that’s created is still user root group root. I could chown/chgrp obviously but I’m trying to set things up so root isn’t necessary.
Not sure; this particular mount is probably being managed by systemd, and I don’t know how it’s handling any conflicts between its built-in hugepages mount unit and /etc/fstab.
You might be able to customize it by creating a systemd.mounts entry with the exact same name ("dev-hugepages.mount").
This is incorrect. The permissions are a property of the file system, not the mountpoint it was mounted at. That file/directory that was there before the file system was mounted is now “beneath” the mountpoint and its permissions are irrelevant.
@jgarvin The issue is indeed because /dev/hugepagesis an upstream systemd mount unit, which overrules fstab. The reason it’s overruled is because NixOS puts those upstream units in /etc while systemd-fstab-generator puts its fstab-derived units in /run, and /etc overrules /run in systemd logic. Other distros put these upstream mount units in /usr/lib, which /run overrules, so they get the opposite behavior.
But yea, point is, you need to override it in the mount unit. Something like this should work:
systemd.mounts = [
{
what = "hugetables";
where = "/dev/hugepages";
options = "mode=1770,gid=100";
}
];