Reusing custom NixOS module options in Home Manager

Hello folks,

Recently I finished my NixOS config and I’m very happy because it works ;-). Thank you for the amazing open-source.

I organized my configuration (files imported as NixOS modules) into two directories called modules and profiles where profiles just specify = ... and modules specify those = mkOption ... and then conditionally use it config = { ... } section. Works great for me and it is easy to extend it in the future.

Yesterday I started playing with Home Manager and I quickly realized that I can’t add Home Manager configuration into the existing module files. I wish I could have it inside config = { ... } section but that’s OK. I can have for example myapp.nix for NixOS module system-wide configuration and for user (Home Manager) configuration.

But I really miss that I can’t use those = mkOption ... in Home Manager. Is it possible to re-use those custom options inside Home Manager files? Or is it possible to define new options like = mkOption ...?

Thank you :wink:

You can actually use HM inside NixOS. So you define system-level stuff with the normal NixOS modules, but user-level stuff with HM modules. And with a bit of care you can write those HM modules such that you can also re-use them standalone on other systems.

By doing so, you don’t have duplication, and you only define options either on the NixOS side, or on the HM side.