Hi all,
I’m trying to figure out how to best organize my modules in my config, I have a main module mySystem and a myHome(for home manager) that I import into my hosts and use to toggle certain features on or off so the interface looks like:
myHome = {
enable = true; # if false, all below options and sub module options should be disabled even if they're set to true
# All the options
user = "yeshey";
plasma.enable = true;
gnome.enable = false;
homeApps = {
enable = true; # if false, all home apps should be disabled
cli = {
enable = false; # if false, all cli apps should be disabled
general.enable = true;
git = {
enable = true; # if false, git should be disabled
personalGit = {
enable = true;
userName = "Yeshey";
userEmail = "yesheysangpo@hotmail.com";
};
};
};
libreoffice.enable = true;
};
};
The way to implement this gets a little messy, the myHome module imports all others:
imports = [
./gnome/default.nix
./plasma/default.nix
./homeApps/default.nix
[...]
];
So, in the plasma nix file I need to check if the enable option of myHome and if myHome.plasma.enable are both set:
config = lib.mkIf (config.myHome.enable && cfg.enable) {
This is all fine and great, but with nested options in gets increasingly hellish, my git module is like:
config = lib.mkIf (config.myHome.enable && config.myHome.homeApps.enable && config.myHome.homeApps.cli.enable && cfg.enable) {
This could maybe be solved with conditional imports, where it would only import the homeApps submodule if myHome was enabled, maybe like home-manager does/did, but I’ve read here that conditional imports are discouraged and lead to problems in nix.
I tried to look at the submodules type, but either it wouldn’t help me or I missed something. Or maybe I’m going about this the wrong way, and this is not the way nested enable options should be used?
Thanks in advance!