How to auto mount disk at boot (NixOS)

I have two ssd in my pc and i used the second one to store my steam games. I tried to make it automount by mounting it then using the command “nixos-generate-config” but when i restarted it didnt fixed it. I looked at hardware config but the disk isnt mentoined there.

I tried to declare it like this in the nix config but this didnt worked.

fileSystems.“/run/media/heim/Games” = {
device = “/dev/sdb1”;
fsType = “ext4”;
options = [“uid=1000,gid=100,forceuid,forcegid,x-systemd.automount,x-systemd.mount-timeout=5s”];

How i could mount it at boot to “/run/media/heim/Games”?

maybe post your entire hardware-config for all other disks so that we can take a look at it?

this didnt worked

in which way did it not work? Not mounted at all? Did you try mounting the disk by uuid?

1.Will post my hardware config tomorrow.
2. It just not mounted at all. I can still find it in dolphin file manager, thats fine, but its not mounted

x-systemd.automount will only mount the disk when you access the mount point. If you remove that, it should mount on boot.

1 Like

Hardware config

Do not modify this file! It was generated by ‘nixos-generate-config’

{ config, lib, pkgs, modulesPath, … }:
imports =
[ (modulesPath + “/installer/scan/not-detected.nix”)
boot.initrd.availableKernelModules = [ “nvme” “xhci_pci” “ahci” “usbhid” “usb_storage” “sd_mod” ];
boot.initrd.kernelModules = ;
boot.kernelModules = [ “kvm-amd” ];
boot.extraModulePackages = ;
fileSystems.“/” =
{ device = “/dev/disk/by-uuid/ca4a3de8-0a6f-45da-90f7-e109c3a2341e”;
fsType = “ext4”;
fileSystems.“/boot” =
{ device = “/dev/disk/by-uuid/4F1B-0C46”;
fsType = “vfat”;
fileSystems.“/run/media/heim/Games” =
{ device = “/dev/disk/by-uuid/81ada518-5bf6-4f03-89aa-d262170fae25”;
fsType = “ext4”;
#its my pendrive
swapDevices =
[ { device = “/dev/disk/by-uuid/e7c10971-cebb-4a52-a42a-a722f05a4995”; }

networking.useDHCP = lib.mkDefault true;

nixpkgs.hostPlatform = lib.mkDefault “x86_64-linux”;
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

I am a bit at odds with your copy-paste of your config files. They don’t seem to preserve the correct formatting. And some boolean values have been replaced by different characters. Not really bad for reading, but I can’t you take them, edit and copy-paste back.

So you’ll have to do that yourself.

I’d just add the filesystem that you have to your hardware-config.nix and implement the two changes already proposed:

  1. Define the device to mount by uuid instead of /dev/sdb1 just like the other filesystems. You can check the uuid you need in /dev/disk/by-uuid/.

  2. Remove the systemd automount stuff.

The report back if it works.


It worked thanks. Added the code to nixos config then nixos-rebuild switch and it instantly mounted.
Thank you.