How to properly use the home-manager / nixos modules #156
-
|
I probably don't really need it, as I don't need to merge lists, but I still want to understand it 🙂 What I already got (I hope): The The difference between Now the module exposes two options to change (or add new) What I didn't get was how, or more particular in what order, the packageDefinitions are being merged. From observation I think it's somehow related to the order the modules are "included" (the But I find it hard to debug the order of modules I'm importing to my actual config 😅 At least the order I expected didn't align with the outcome. Do you have any tips on how one could debug module execution order? I did this to test my hypothesis: Details
homeConfigurations = {
"test" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
{
home.stateVersion = "23.11";
home.username = "kai";
home.homeDirectory = "/home/kai";
nixCats.enable = true;
nixCats.packageNames = ["lala"];
nixCats.packageDefinitions.replace = {
lala = _: { settings.aliases = ["a"]; };
};
}
{
nixCats.packageDefinitions.replace = {
lala = _: { settings.aliases = ["b"]; };
};
}
{
nixCats.packageDefinitions.replace = {
lala = _: { settings.aliases = ["c"]; };
};
}
] ++ [nixCatsModules.homeManagerModule];Result has |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
You are spot on in your understanding. One detail, all replace types happen first, all merges are merged into that after. Edit: existing is before both of those, and the others update into it according to the strategy chosen Unfortunately the order of the merges and replacements is not easily controllable, the way it works is by defining a custom type for the module option, which the module evaluator uses to merge options when it encounters the same one in multiple places. The general rule is that the module that imports the other module will win (go last) So, if you make several other modules, but then in your main module you import all of those, the ones in the main module will go last. Unfortunately, I dont have that many tricks for you for determining module import order. (you could put in a builtins.trace?) Rather than deal with it, I would suggest making a new category for your stuff in the new file so that you don't have to worry about it being overridden in other files in most cases. |
Beta Was this translation helpful? Give feedback.
You are spot on in your understanding.
One detail, all replace types happen first, all merges are merged into that after.
Edit: existing is before both of those, and the others update into it according to the strategy chosen
Unfortunately the order of the merges and replacements is not easily controllable, the way it works is by defining a custom type for the module option, which the module evaluator uses to merge options when it encounters the same one in multiple places.
The general rule is that the module that imports the other module will win (go last)
So, if you make several other modules, but then in your main module you import all of those, the ones in the main module will go last.
U…