Best practices for sharing dotfiles between macOS and NixOS?

I recently started using nix-darwin, allowing me to use Nix for managing both macOS and NixOS.

My dotfiles are organized in modules, and I planned to enable/disable modules based on which OS I’m using. However, nix throws an error on macOS if it sees a NixOS-only config value (e.g. services.xserver), even when those options are disabled explicitly with mkIf false.

What’s the best way to use modules across NixOS and macOS? Do I need conditional imports?

home-manager has both a nixos module and a nix-darwin module you can use to use the same home.file config for both systems to automatically place dotfiles in the correct places.