No error message?

I’m currently trying to debug a NixOS module. Here’s a similar version of the module:

{ config, pkgs, lib, ... }:
let
  yaml = pkgs.formats.yaml { };
in
{
  options.services.yes = {
    settings = lib.mkOption {
      type = lib.types.submodule {
        options = {
          general = lib.mkOption {
            type = lib.types.submodule {
              freeformType = yaml.type;

              options = {
                # paths = {
                #   config_dir = lib.mkOption {
                #     type = lib.types.path;
                #     default = "/etc/yes";
                #   };
                # };
              };
            };
          };
        };
      };
    };
  };

  config =
    let
      cfg = config.services.yes;
    in
    {
      services.yes.settings.general = rec {
        paths = {
          # config_dir = lib.mkDefault "/etc/yes";
          sub_dir = lib.mkDefault "${paths.config_dir.ctiegsnrctiel.ctiencduelm}/sub_dir";
        };
      };
    };
}

Funny enough, if I add this file to the imports list, I’d expect an error due to the ridiculous variable paths.config_dir.ctiegsnrctiel.ctiencduelm but sudo nixos-rebuild test --flake . suprisingly succeeded… and I’m confused. Why does it pass? I expected to get an error that tells me that paths.config_dir.ctiegsnrctiel.ctiencduelm isn’t set.

You used freeformType. That means that any option is permitted under this submodule, including ones that aren’t declared.

1 Like

Damn. I though that it also checks, at least at the end, if this variable even exists … thank you for the information.

Hmm, there may be more than one misconception floating around in here.

First is use of rec: don’t. You aren’t going through the module system if you use rec, which ends up being a footgun 90% of the time. Go through the config variable instead, like you’re doing when defining cfg.

Second is laziness. You might actually get an error if you tried to use this config somewhere, but since Nix is lazy, if you don’t use it, it won’t try to compute it.

You aren’t going through the module system if you use rec, which ends up being a footgun 90% of the time. Go through the config variable instead, like you’re doing when defining cfg.

That was my next attempt in debugging the module. Thank you for the hint!
I hope that I’ll find a solution… if not… I hope it’s fine if I create another post…