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

modules: fix evaluation when modules emit warnings #605

Merged
merged 2 commits into from
May 24, 2023

Conversation

sandydoo
Copy link
Member

@sandydoo sandydoo commented May 18, 2023

Description

The warnings option is used by functions like lib.mkRenamedOptionModule and lib.mkChangedOptionModule to warn the user to update their configuration. Without this option, evaluation fails on these functions with a missing attribute error.

Repro

You can reproduce the error by using a renamed option, like postgres.enable (instead of services.postgres.enable).

{ ... }:

{
  postgres.enable = true;
}

Before

Building shell ...
warning: applying 'toString' to path '/home/sandydoo/code/cachix/devenv/src/modules/services/postgres.nix' and then accessing it is deprecated, at «stdin»:0
error:
       at /home/sandydoo/code/nixpkgs/lib/modules.nix:326:9:

          325|         options = checked options;
          326|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          327|         _module = checked (config._module);

       … while evaluating the attribute 'config'

       error: The option `warnings' does not exist. Definition values:
       - In `/home/sandydoo/code/cachix/devenv/src/modules/services/postgres.nix': [ ]

After

Building shell ...
warning: applying 'toString' to path '/home/sandydoo/code/cachix/devenv/examples/postgres/devenv.nix' and then accessing it is deprecated, at «stdin»:0
trace: warning: The option `postgres.enable' defined in `/home/sandydoo/code/cachix/devenv/examples/postgres/devenv.nix' has been renamed to `services.postgres.enable'.

19:21:08 system     | postgres.1 started (pid=631304)

@sandydoo sandydoo added the bug Something isn't working label May 18, 2023
@cloudflare-pages
Copy link

cloudflare-pages bot commented May 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d2dfc73
Status: ✅  Deploy successful!
Preview URL: https://7a56d906.devenv.pages.dev
Branch Preview URL: https://fix-module-warnings.devenv.pages.dev

View logs

The `warnings` option is used by functions like
`lib.mkRenamedOptionModule` and `lib.mkChangedOptionModule` to warn the
user to update their configuration. Without this option, evaluation
fails on these functions with a missing attribute error.
@sandydoo
Copy link
Member Author

sandydoo commented May 19, 2023

warning: applying 'toString' to path '/home/sandydoo/code/cachix/devenv/examples/postgres/devenv.nix' and then accessing it is deprecated, at «stdin»:0
This extra warning looks like a bug in nixpkgs. It's converting the file path to a string to display it in the next warning, but clearly the toString machinery is throwing spurious warnings in this case.

@domenkozar domenkozar merged commit 8c90ce2 into main May 24, 2023
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants