Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix eval handles errors differently based on if --json is used #11576

Open
quatquatt opened this issue Sep 23, 2024 · 0 comments
Open

nix eval handles errors differently based on if --json is used #11576

quatquatt opened this issue Sep 23, 2024 · 0 comments
Labels

Comments

@quatquatt
Copy link
Contributor

Describe the bug

When evaluating a higher-level option in a config with nix eval, it ignores an encountered value that would cause an error. Given this input while cd'ed into your configuration (replace MYHOSTNAME with your hostname)
nix eval ".#nixosConfigurations.MYHOSTNAME.config.programs._1password"
It provides this output:

{ enable = false; gid = «error: The option `programs._1password.gid' can no longer be used since it's been removed. A preallocated GID will be used instead.
»; package = «derivation /nix/store/43182jvmys5wxs30c196n9a163vg4238-1password-cli-2.28.0.drv»; }

However, if we add --json to our input, we get this output:

error:
       … while evaluating attribute 'gid'

       … while evaluating the attribute 'value'
         at /nix/store/rqicl40jqw5d93l43s1xq0bm6yy0gpx4-source/lib/modules.nix:809:9:
          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `programs._1password.gid':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: The option `programs._1password.gid' can no longer be used since it's been removed. A preallocated GID will be used instead.

It seems that when nix eval is used with --json, it doesn't traverse as low down when it comes to catching errors. Keep in mind that none of these values are set in my configuration: this is just based on the defaults for the module.

Expected behavior

I think the behavior without --json is more intuitive. An error that would be encountered upon setting a value doesn't make sense if you don't have that value set.

I do think that nix eval's behavior isn't perfect when it comes to errors. For example:
It still prints traces when it encounters a deprecated option, even if it's not being used in the configuration

  • If we evaluated programs._1password.gid directly, like via this input nix eval ".#nixosConfigurations.MYHOSTNAME.config.programs._1password.gid", we get an error, even though the value isn't set in our configuration. Note that adding --json has the same behavior here.

However, I think these issues are separate and can be tracked separately.

nix-env --version output
nix-env (Nix) 2.24.7

Priorities

Add 👍 to issues you find important.

@quatquatt quatquatt added the bug label Sep 23, 2024
@quatquatt quatquatt changed the title nix eval outputs errors differently based on if --json is used nix eval handles errors differently based on if --json is used Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant