Configuration.nix options for filesystem ignored despite being in fstab

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
  };
}

With /etc/fstab:

/dev/disk/by-uuid/323ccc87-771f-4b0b-bf39-c6e696d8db7e / btrfs x-initrd.mount,subvol=root,compress=zstd 0 0
/dev/disk/by-uuid/4C9A-B83E /boot vfat fmask=0077,dmask=0077 0 2
hugetlbfs /dev/hugepages hugetlbfs mode=1770,gid=100 0 2
/dev/disk/by-uuid/323ccc87-771f-4b0b-bf39-c6e696d8db7e /home btrfs subvol=home,compress=zstd 0 0
/dev/disk/by-uuid/323ccc87-771f-4b0b-bf39-c6e696d8db7e /nix btrfs x-initrd.mount,subvol=nix,compress=zstd,noatime 0 0

Yet:

$ 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?
  • How are you supposed to do this instead?

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?

1 Like

Oh, what’s the right way to change the permissions of the mount point itself? I want to do this:

$ touch /dev/hugepages/foo
touch: cannot touch '/dev/hugepages/foo': Permission denied

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").

Or you might need to experiment with suppressing the built-in mount by adding it to systemd.suppressedSystemUnits.

1 Like

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/hugepages is 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";
  }
];
3 Likes

thanks, that did the trick!