Unable to mount external storage due to 'cannot be topologically sorted'

I run NixOS on a small SSD, and have a partition on my external HDD that I used to use for storing media (/dev/sda5). I added this in my /etc/nixos/configuration.nix:

fileSystems."/dev/sda5" = {
    device = "/dev/sda5";
    mountPoint = "/mnt/Storage";

This was working for a few days uptil a few hours ago, when I was messing with flakes. I get these errors now:

Failed assertions:
       - The ‘fileSystems’ option can't be topologically sorted: mountpoint dependency path /mnt/Storage -> /mnt/Storage loops to /mnt/Storage
(use '--show-trace' to show detailed location information)

How can I prevent this?

Edit: solved my own problem.

(I was messing around with flakes and I had accidentally deleted my /etc/nixos/hardware-configuration.nix. In a panic, I ran nixos-generate-config again, which made a new hardware-configuration.nix containing the already mounted /mnt/Storage on my system. Thus when rebuilding my configuration some error may have occurred - I have no idea how this worked/came about.)

So, the solution is to edit /etc/nixos/hardware-configuration.nix and to remove the lines:

- fileSystems."/mnt/Storage" = {
- # some options here I don't remember (HARDWARE-CONFIGURATION.NIX!)
- };

Rebuilding the configuration now works.

I’m glad you figured it out.

You may want to consider keeping your configuration files in source control so that you can more easily restore accidentally deleted files :grimacing:

1 Like