Skip to content

Missing Diagnostic For Invalid Enum NixOS Option Value #805

@cw-1988

Description

@cw-1988

Similar issue: Missing Diagnostic For Invalid nullOr int NixOS Option Value

"great first issue" label is missing, i would've assigned it. "low priority" could probably also be a good label for this kind of nitpick, but everything that forces us to reevaluate through nix eval is just an unnecessary waste of time.

nixd can resolve enum-valued NixOS options and show the allowed values for hover/completion, but does not report a diagnostic when a literal string outside the enum is assigned.

For example, services.k3s.role is typed as:

one of "server", "agent"

Assigning another string does not produce an error diagnostic in the editor.

Expected Behavior

Given this NixOS module:

{ ... }:

{
  services.k3s.role = "banana";
}

nixd should report a diagnostic for "banana", because the option type is:

one of "server", "agent"

Valid values would be:

services.k3s.role = "server";
services.k3s.role = "agent";

Actual Behavior

No diagnostic is shown in the editor, even though nixd can resolve the option type information.

The invalid value is rejected when the NixOS module system evaluates the configuration:

A definition for option `services.k3s.role' is not of type `one of "server", "agent"'.
Definition values:
- In `<unknown-file>': "banana"

Reproduction

flake.nix:

{
  description = "nixd enum option value diagnostic reproduction";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
  };

  outputs =
    { nixpkgs, ... }:
    {
      nixosConfigurations.control = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
        ];
      };
    };
}

configuration.nix:

{ ... }:

{
  services.k3s.role = "banana";
}

VS Code / Cursor nixd config:

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": [
    "nixd",
    "--nixos-options-expr",
    "(builtins.getFlake \"path:/absolute/path/to/repro\").nixosConfigurations.control.options"
  ]
}

Evaluation Verification

The NixOS module system rejects the value:

nix eval --impure --expr '
  let
    nixpkgs = builtins.getFlake "github:nixos/nixpkgs/nixos-25.11";
    eval = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ ... }: {
          services.k3s.role = "banana";
        })
      ];
    };
  in
    eval.config.services.k3s.role
'

Expected error:

A definition for option `services.k3s.role' is not of type `one of "server", "agent"'.

Environment

  • nixd version: 2.6.4
  • Editor: VS Code / Cursor with jnoortheen.nix-ide
  • nixpkgs: nixos-25.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions