How to auto mount / permanently mount external devices on NixOS
Well, I costumarily use bashmount
or udisksctl
to mount USB sticks. They will be mounted in /run/media/$(user name)/$(drive label or UUID)
.
But if you are talking about an internal harddisk or partition in a local harddrive, the simplest way is:
- Create a directory of your preference, as /mnt/windows-partition
- Mount the desired partition, say /dev/sdn5, in that directory:
$
mount /dev/sdn5 /mnt/windows-partition
- Run nixos-generate-config. It will update /etc/nixos/hardware-configuration.nix to match the new partition configuration (and configuration.nix stays untouched, unless you use the --force option).
- And, finally, a
nixos-rebuild switch
!
I personally use udisks for that. That means, if i want to mount an USB stick, i just have to plug it in and run:
$ udisksctl mount -b /dev/sdc
I aliased udisksctl mount -b
to udm
to make it even shorter. The device is then mounted in /run/media/$USER/$DEVICE_LABEL
and accessible for you.
I think, some tools (e.g. nautilus and ldm) can do that automatically for you.
EDIT: ah, i just found out that udisks can also automount devices.