Reconfigure default volume mount to /media/volume_name instead of /run/media/$USER/volume_name

Have made in excess of 20 attempts change this default mount point for all volumes in NIX 25.05 and no configuration.nix changes have been effective.

Is there a simple udev rule or udisks2 configuration to allow volumes clicked within the caja file manager to automatically mount under /media/volume_name rather than /run/media/$USER/volume_name?

I have used other versions of linux with a simple file creation such as:

udev rule sets env variable UDISKS_FILESYSTEM_SHARED. udisks2 automounts in /media/ not /media/[username]/
create file /etc/udev/rules.d/99-udisks2.rules containing:

ENV{ID_FS_USAGE}==“filesystem|other|crypto”, ENV{UDISKS_FILESYSTEM_SHARED}=“1” include crypto
ENV{ID_FS_USAGE}==“filesystem”, ENV{UDISKS_FILESYSTEM_SHARED}=“1” no crypto

reload: sudo udevadm control --reload

Is there a similar fix for NixOS that would override the /run/media/$USER/volume_name to mount as /media/volume_name?

It looks like services.udisks2.mountOnMedia does exactly this.

When enabled, instructs udisks2 to mount removable drives under /media/ directory, instead of the default, ACL-controlled /run/media/$USER/. Since /media/ is not mounted as tmpfs by default, it requires cleanup to get rid of stale mountpoints; enabling this option will take care of this at boot.

2 Likes

Thank you for the reply

you noted:

Declared in
nixos/modules/services/hardware/udisks2.nix

did you mean /etc/nixos/modules/services/hardware/udisks2.nix?

Here is my imported module:

#‘/etc/nixos/modules/services/hardware/udisks2.nix’

{ config, lib, pkgs, … }:

{

services.udisks2.mountOnMedia = true;
}

Inconsistent behavior noted:

After rebuild and cleanup with nix-collect-garbage -d, nix-collect-garbage, and nix-store --optimize, partitions mounted to /media/volume_name,
after reboot revert to /run/media/$USER/volume_name

Is this a bug that should be reported?

Do you also have services.udisks2.enabled = true; and have you ran nixos-rebuild switch after the change?

What you’re describing doesn’t sound normal. Is your configuration properly importing your udisks2 module file, and are you defining anything about udisks2 anywhere else in your configuration?

from configuration.nix:

###############################################

#GVFS + Udisks2 automount (/media/)

###############################################
services.gvfs.enable = true;
services.udisks2.enable = true;
#services.udisks2.mountOnMedia = true;

systemd.tmpfiles.rules = [
“d /media 0755 root root -”
];

This line seems commented out. Why? Uncomment it, rebuild and try again.

Rebuild and cleanup without error, before reboot, clicking partitions in Caja file manager mount to /media/volume_name, after reboot revert to /run/media/$USER/volume_name.

This is the line that appears in the module.

I did initially rebuild with this line not commented out and the result was the same, so I put it in the module so it would not appear twice, once in configuration.nix and again in the module. Rebuild has complained in the past regard to things listed twice.

Would you mind sharing your whole configuration? Be it on GitHub/GitLab/Codeberg or whatever. There’s no way to tell what’s going on from what you’ve said here.

1 Like

Sounds like you’ve got yourself in a situation where the boot loader entry isn’t updating, but the nixos-rebuild command can’t tell that that’s failing.

You’ve likely got a very broken configuration - assuming you’re running the correct commands - it’d definitely be a good idea to have someone look over it for you.

1 Like

Did you switch bootloaders recently? If so you may need to delete any traces of the old bootloader, then use the --install-bootloader flag the next time you rebuild your config. If you’re using EFI boot, you can use efibootmgr to manage the firmware boot entries as well - ensure the NixOS-managed entry comes first.

2 Likes
# Multibooting various operating systems from multi-partitioned single hard drive, using GRUB2 with Nixos menuentry to boot Nixos.
# The EFI bootloader that adds entries to the BIOS boot menu is located on a separate linux partition other than Nixos.
# The initial Nixos installation wrote a Nixos entry to the EFI partition with a separate kernels directory and it became necessary to manually configure a menuentry to the existing GRUB2 configuration before Nixos would boot using GRUB2. 
# The objective is to place all of the files necessary for Nixos to boot within the boot directory of the Nixos partition, and boot using the GRUB2 bootloader menuentry located on another linux partition.

# Thank you to all who replied to this inquiry and invite your input to resolve not only the default /media/volume_name issue, but also to configure booting Nixos as referenced.  Would also appreciate any other specific suggestions to improve the configuration.nix and performance of Nixos in general.

# Thank you.


menuentry "NixOS" --class nixos {
    search --set=drive1 --fs-uuid 4C30-1FE7  # drive1 is the FAT32 EFI boot partition
    linux ($drive1)//kernels/xga8n3f6za3fdawq2kr265g8q1na2lq2-linux-6.17.8-bzImage init=/nix/store/xf0iq01sl6pb1bqns1nyl2hijm35gkc1-nixos-system-nixos-25.05.813095.1c8ba8d3f763/init loglevel=4 lsm=landlock,yama,bpf
    initrd ($drive1)//kernels/1ic5snjj55wr9clc7xwdjac8xyzlb7h9-initrd-linux-6.17.8-initrd
    }

##### begin configuration.nix #####


{ config, pkgs, lib, modulesPath, ... }:

{
  ###############################################
  ## Bootloader
  ###############################################
  boot.loader = {
    grub.enable = true;
    grub.device = "nodev";
    grub.useOSProber = true;
    efi.canTouchEfiVariables = true;
  };

  boot.kernelPackages = pkgs.linuxPackages_latest;

  ###############################################
  ## Hardware (merged)
  ###############################################
  imports = [
    # Import the custom udisks2 module from the specified location
    /etc/nixos/modules/services/hardware/udisks2.nix
  ];

  boot.initrd.availableKernelModules = [
    "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" "sr_mod" "rtsx_pci_sdmmc"
  ];

  boot.kernelModules = [ "kvm-intel" "kvm-amd" ];

  ###############################################
  ## Firmware policy
  ###############################################
  hardware.enableAllFirmware = false;
  hardware.firmware = [];

  hardware.cpu.intel.updateMicrocode = true;
  hardware.cpu.amd.updateMicrocode = false;

  hardware.enableRedistributableFirmware = true;

  ###############################################
  ## Graphics
  ###############################################
  hardware.graphics.enable = true;

  services.xserver.videoDrivers = [
    "modesetting" "intel" "amdgpu" "radeon" "nouveau"
  ];

  ###############################################
  ## Networking
  ###############################################
  networking.hostName = "nixos";
  networking.networkmanager.enable = true;
  programs.nm-applet.enable = true;

  ###############################################
  ## Locale & Time
  ###############################################
  time.timeZone = "America/Recife";

  i18n.defaultLocale = "en_US.UTF-8";
  i18n.extraLocaleSettings = {
    LC_ADDRESS = "en_US.UTF-8";
    LC_IDENTIFICATION = "en_US.UTF-8";
    LC_MEASUREMENT = "en_US.UTF-8";
    LC_MONETARY = "en_US.UTF-8";
    LC_NAME = "en_US.UTF-8";
    LC_NUMERIC = "en_US.UTF-8";
    LC_PAPER = "en_US.UTF-8";
    LC_TELEPHONE = "en_US.UTF-8";
    LC_TIME = "en_US.UTF-8";
  };

  ###############################################
  ## Desktop
  ###############################################
  services.xserver.enable = true;
  services.xserver.displayManager.lightdm.enable = true;
  services.xserver.displayManager.lightdm.greeters.gtk.enable = true;
  services.xserver.desktopManager.mate.enable = true;

  services.xserver.xkb.layout = "us";

  ###############################################
  ## Printing
  ###############################################
  services.printing.enable = true;

  ###############################################
  ## Audio (PipeWire)
  ###############################################
  services.pulseaudio.enable = false;
  security.rtkit.enable = true;

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };

  ###############################################
  ## User Account
  ###############################################
  users.users.desconosido = {
    isNormalUser = true;
    description = "desconosido";
    extraGroups = [ "networkmanager" "wheel" "disk" ];
  };

  ###############################################
  ## Unfree packages
  ###############################################
  nixpkgs.config.allowUnfree = true;

  ###############################################
  ## System Packages
  ###############################################
  environment.systemPackages = with pkgs; [
    vdhcoapp
    gvfs
    udisks2   
  ];

  ###############################################
  ## Filesystems
  ###############################################
  fileSystems."/" = {
    device = "/dev/disk/by-uuid/7b1352x4-247g-3ad3-rg56-27c516534214";
    fsType = "ext4";            
  };

  ###############################################
  ## GVFS + Udisks2 automount (/media/<VOLUME>)
  ###############################################
  services.gvfs.enable = true;
  services.udisks2.enable = true;
  #services.udisks2.mountOnMedia = true;

  systemd.tmpfiles.rules = [
    "d /media 0755 root root -"
  ];

  ###############################################
  ## Polkit rule for passwordless disk mounts
  ###############################################
  security.polkit.enable = true;
  security.polkit.extraConfig = ''
    polkit.addRule(function(action, subject) {
      if (subject.isInGroup("wheel") &&
          action.id.indexOf("org.freedesktop.udisks2.") === 0) {
        return polkit.Result.YES;
      }
    });
  '';

  ###############################################
  ## System State
  ###############################################
  system.stateVersion = "25.11";
}
##### end configuration.nix #####

You don’t need this here. Have you created the file with that file structure, and also why? You’ve defined the proper udisks2 properties near the bottom of your configuration. I would delete these lines.

What bootloader are you using overall and how is it configured? I have no idea how this currently works for you and now NixOS generates the entry.

Is this hardcoded by you, or it’s just an example that you’ve pasted here?

There are many more weird definitions in your config, but let’s start by resolving your main question.

This is correct for grub EFI.
But then I don’t really know how this is intended to work for mirrored boot.

Thanks to all who responded to the inquiry.

Configuration.nix needed an additional boot configuration for the bootloader and kernel update to complete:

fileSystems.“/boot” = {
device = “/dev/disk/by-uuid/xxxx-xxxx”;
fsType = “vfat”;
};

Nixos boot file and kernel update issues are resolved. After updating Nixos it is a simple matter to copy the relevant GRUB2 menuentry information from Nixos to revise the active grub configuration file. The actual grub installation used for multibooting is on a separate partition of another linux distribution.

Additionally, apparently there was a problem with updating to 25.11 from 25.05 which involved updating profiles.

It appeared that the command “sudo nix-channel --update nixos; nixos-rebuild switch” needed to be exectuted from a superuser prompt or permission was denied to create the symlink.

The upgrade to 25.11 resolved the mount issue and now volumes mount at /media/wolume_name as intended.

Again, thanks to all who responded to the inquiry.