Writing NixOS module, type error somewhere

I’m trying to write my first NixOS module, and I’m getting an error I just can’t seem to figure out. Here is the text of the module: https://github.com/NixOS/nixpkgs/blob/03cde75ae110069555584e9bb9e3d9887f2d6530/nixos/modules/misc/wordlist.nix

When I try to set:

config.environment.wordlist = {
  enable = true;
  lists = [
    {
      envVar = "AUGMENTED_WORDLIST";
      source = [
        { file = "${pkgs.scowl}/share/dict/words.txt"; }
        { words = [ "foo" "bar" "baz" ]; }
      ];
    }
  ];
};

I’m getting an error that I just don’t understand:

error: value is a function while a set was expected

   at /nix/store/nd91gpdz8wf7y82a55v7l3sj0lqdrmaz-source/lib/types.nix:617:32:

      616|       description = "${t1.description} or ${t2.description}";
      617|       check = x: t1.check x || t2.check x;
         |                                ^
      618|       merge = loc: defs:

Full trace is available here: error: value is a function while a set was expected at /nix/store/nd91 - Pastebin.com

I just don’t understand exactly what is triggering this, and my attempts to debug this issue have been thwarted by trace being seemingly inconsistent, I assume due to laziness, (though it is highly mysterious to me exactly why/how this works, for instance if I add trace x on line 110, I get { envVar = <CODE>; source = <CODE> }, and if I trace x.envVar I get AUGMENTED_WORDLIST but if I trace x.source I get nothing at all.)

Does anyone have any tips or recommendations?

The full trace gives you a hint where it fails:

while evaluating 'check'
…
while evaluating the option `environment.wordlist.lists.[definition 1-entry 1].source':

So the problem occurs during the type check of the source option.

And indeed the type definition contains a small error. One of the parentheses is out of place and turns the oneOf list into a 3 element list which is not a valid type:

diff --git a/nixos/modules/misc/wordlist.nix b/nixos/modules/misc/wordlist.nix
index da684619fb6..a8103039e1d 100644
--- a/nixos/modules/misc/wordlist.nix
+++ b/nixos/modules/misc/wordlist.nix
@@ -35,7 +35,7 @@ specType = types.submodule {
     source = mkOption {
       type = types.oneOf [
         types.str
-        types.nonEmptyListOf (
+        (types.nonEmptyListOf
           taggedSourceType
         )
       ];
3 Likes

I know you have already found the solution, but I’m just going to link to a really great explanation on nix function syntax: How can I write a Python package derivation in a flake? - #11 by jacg

1 Like

I swear I know this, but of course “knowing something” and “recognizing something contrary to years of ingrained habits while in context when you’re convinced that the problem is elsewhere” are completely different. Thanks everyone for the second set of eyes.

1 Like