[Solved] Possible nix typing bug

Hey guys

I wrote the following module demonstrating what seems to be a typing bug in nix:

The property name has type int but I assign it a value of type str. Nix does not complain when I import this module in my configuration.nix though.

Am I missing something or should nix report this as a typing error?
I am facing this in my actual server config that I am using in production, but I tried to make an example that’s as small as possible to demonstrate the issue.

Thanks in advance for your inputs!

I get a type error, but remember that Nix is a lazy language, so that the type error doesn’t appear until you use the name. Here is what I did.

  • Create a file called type_error.nix next to my NixOS configuration with your GitHub Gist.
  • Put ./type_error.nix into the imports in configuration.nix
  • $ nix-repl '<nixpkgs/nixos>'
  • nix-repl> config.opts.test
    { _module = { ... }; name = «error: The option value `opts.test.name' in `/home/rmk35/nixos/type_error.nix' is not of type `signed integer'.»; }
1 Like

You are totally right, I was underestimating nix’ laziness and particularly the fact that type checking as well happens lazily at evaluation time.

Thanks, case closed!