Hi there, I am trying to restructure my config.
And I have got problem there.
Problem is that my defined value of
config.meta.system.binaryCaches seems to be duplicated, and so does values of other lists.
For example, in
/etc/nixos/system/options.nix, I define
meta.system.binaryCaches = [ "foo" ];
In config section of
meta.system.binaryCaches would be
[ "foo" "foo" ];
However, if I define
meta.system.binaryCaches directly inside config section of
configuration.nix, there would be no duplication.
I think this may have something to do with my style of writing
configuration.nix as a module, but I can’t figure out.
And this is
Thanks in advance!
After hours of trying, seems only values written at top-level would be duplicated. But still don’t know why.
I fixed by change
meta.nix. Still don’t know why.
It turned out to be that I used
meta as the name of the options, which is a bad idea because it is a used keyword in lib!
I changed to anything not being used, and it behaves normally.
But there is no warning to warn me. Unpleasant experience. 10 hrs spent on this stupid question.
Can you provide a smaller example or a full example with all files? Using the two files you provided it seems that there are several directories missing.
Even though you solved the issue it would be interesting to know what exactly went wrong. It was an unpleasant experience for you, but we can try to improve it so it does not happen again. It would go with the current campaign on improving Nix error messages: Proposal for improving Nix error messages
Here you go.
At the master tree that time, except I used used
config.meta instead of
meta.nix.example, everything should be enough to produce the “unpleasant experience”.
A little snippet instruction of reading the code above is:
src is where I implement the config. Almost same as what
config attr does.
module is where I define options.
meta.nix is the options for this configuration itself.
So to be exact, you used
meta which is supposed to correspond to metadata of this module, as described here, which is completely unexpected from the NixOS modules. Unfortunately I don’t know what to do, but I have linked this to the Proposal for improving Nix error messages thread mentioned earlier so I hope this gets fixed.
I think it’s actually not an error in Nix, it could be said “by-design”. But warnings like they are in Rust would definitely be better because not everyone who is writing the configuration would have such a considered thought about what words should avoid.
nix warns you to take caution, it would be a plus.
I’m not familiar with the internals, but after some thought, my guess is that the problem here is not at all that
meta is a reserved word of any sort. Instead, your modules being called
meta is just clashing with the builtin module
meta. So while it may sound bizaare when you think of it as some words somehow being reserved, as you’re saying here:
It’s probably a much simpler (albeit more far reaching) design flaw at play: module name clashing not being handled well.