Nix store seems out of sync with my configuration

I think I’ve solved it, so I’m leaving this here for future me and anyone else facing similar issues.

  • Used the nix repl as suggested. Before making any more changes, restic service shows just the default/empty config and enabled is false, as expected (because there is no configuration).

  • Restored the old restic module, enabled in backups.nix then checked repl again. Full config shown, and the module is marked as enabled.

  • Switched to the new config. All the services and wrapped binaries are now accessible, but activation failed because mounting the /mnt/media (USB) mount exited. In actual fact, it is still mounted, and I can back up to it using systemctl start. The error mentioned option ‘uid’ unknown, so I deleted that and the group option.

  • Tried switching again, but now it said unit file not found for the mount. This is a problem that I have faced several times when trying to sort out automounting of shares in particular, and which I haven’t entirely fixed.

  • Commented out the relevant fileSystem call for /mnt/media, then followed the process here: How can I remove a mount unit? - Help - NixOS Discourse (rebuild switch [which failed to activate the config again or create a new generation, but I pressed on]), reboot, uncomment and fix code, switch again).

  • That worked!

So I still don’t know quite how it got into this state, but I seem to have resolved it. Thanks to all for prompting me to use nix repl. I haven’t investigated that before, so I have now learned how to use if for basic debugging, which I am sure will be very useful in the future.