1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 19:21:04 +00:00
Commit graph

289 commits

Author SHA1 Message Date
Robert Hensing 92f4ef78de
lib/modules: improve error message when option is being accessed that isn't defined (#338362) 2024-09-02 10:08:49 +02:00
Sandro Jäckel ab8bf8c35b
lib/modules: improve error message when option is being accessed that isn't defined 2024-09-01 23:29:21 +02:00
Robert Hensing 0abfc619bc
lib.importApply: init (#230588)
* lib.modules.importApply: init

Brings variables from rich scopes to modules defined in separate files.

A helper for functions in files that return a module.

* lib.modules.importApply: Edit doc

Generally improve the quality. Notes:

- Not rendered to the manual yet, so probably the syntax could be
  improved, but I have no way to test this now.

- The docs use `arg` vs `staticArg` in the code. This is intentional,
  because the doc is pretty clear about the role of `arg` whereas
  the code exists in a context where ambiguities are more harmful.

* Format
2024-08-31 01:12:43 +02:00
Robert Hensing 4eb6883b86 lib/modules: Memoize remaining lookups into builtins
Similar to the previous commit about lookups into lib
Main benefits
- consistent
- faster
- shorter
2024-07-03 11:16:31 +02:00
Robert Hensing d0438fb00f lib/modules: Memoize remaining lookups into lib
Benefits:
 - some lookups happened in the hot path, and will now be slightly faster,
   with only a variable lookup and no attribute selection
 - it's now harder to accidentally use args.lib aka specialArgs.lib, which
   has happened
 - shorter
2024-07-03 11:16:31 +02:00
Robert Hensing 88a9a933c4 lib/modules: Memoize functionArgs lookup
This would also make specialArgs-lib.nix pass.
2024-07-03 11:16:31 +02:00
Robert Hensing 0a0e37c217 lib/modules: Memoize addErrorContext lookup 2024-07-03 11:16:31 +02:00
Robert Hensing 4a014ed92e lib/modules: Use fixed lib instead of args.lib
The practical use for this should be very limited because I don't
think anyone should change `lib`, let alone change `lib.functionArgs`,
but, but it would be even stranger to rely on `args.lib` (or really
`specialArgs.lib` for what's clearly a behavior of the current
`evalModules`, which uses its own ambient lib for basically everything.

The shadowing of `lib` by `args.lib` here seems to be a small mistake,
which is easy to make.
2024-07-03 11:16:31 +02:00
stuebinm 46456a929b lib: remove all uses of lib.mdDoc
this change is otherwise a no-op, as lib.mdDoc is already defined to be
the identity function.
2024-04-13 10:07:35 -07:00
Silvan Mosberger 4f1d724b82
Merge pull request #284551 from hercules-ci/types-attrTag
Add `types.attrTag`
2024-04-09 20:48:44 +02:00
Robert Hensing 2e1d470569 lib.modules.evalOptionValue: Undeprecate for lib.types
lib.types.attrTag needs it.
2024-04-04 11:54:46 +02:00
Valentin Gagarin b4cdc15163
Merge pull request #286544 from hercules-ci/doRename-doc
lib.modules.doRename: Add doc comments
2024-02-22 16:05:10 +01:00
Benoit de Chezelles eba79c6df4
lib.evalModules: Fix deprecation doc for args parameter 2024-02-18 21:33:31 +01:00
Robert Hensing fe36252019 lib.modules.doRename: Add doc comments
I don't think these are rendered yet, but this at least provides
the content.

Follow-up to https://github.com/NixOS/nixpkgs/pull/285612
2024-02-14 17:30:51 +01:00
Robert Hensing 29c7665003 lib.modules.doRename: Add condition parameter
This is to support single-to-multi service migrations, so that the
`to` (e.g. `foos.""`) isn't defined unconditionally. See test cases.
2024-02-02 07:31:16 +01:00
Robert Hensing afb1a2e376 lib/modules: Test optionless module errors from #131205 2023-12-09 14:15:49 +01:00
Robert Hensing 00e5487906
Merge pull request #249243 from lf-/jade/declarationsWithLocations
nixos/modules: Add declarationPositions
2023-09-17 19:43:07 +02:00
Jade Lovelace a1d3882307 nixos/modules: Add declarationPositions
What it does: line and column level *declaration* position information:

$ nix repl .
nix-repl> :p nixosConfigurations.micro.options.environment.systemPackages.declarationPositions
[ { column = 7; file = "/nix/store/24aj3k7fgqv3ly7qkbf98qvphasrw9nb-source/nixos/modules/config/system-path.nix"; line = 63; } ]

Use cases:
- ctags over NixOS options, as will be presented at NixCon 2023 ;)
- improving the documentation pages to go to the exact line of the
  declarations.

Related work:
- https://github.com/NixOS/nixpkgs/pull/65024

  This one does it for all *definitions* rather than declarations, and
  it was not followed through with due to performance worries.
- https://github.com/NixOS/nixpkgs/pull/208173

  The basis for this change. This change is just a rebase of that one.
  I split it out to add the capability before adding users of it, in
  order to simplify review. However, the ctags script in there is a
  sample user of this feature.

Benchmarks: conducted by evaluating my own reasonably complex NixOS
configuration with the command:
`hyperfine -S none -w 1 -- "nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath"`

```
Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath
  Time (mean ± σ):      8.971 s ±  0.254 s    [User: 5.872 s, System: 1.388 s]
  Range (min … max):    8.574 s …  9.327 s    10 runs

Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath
  Time (mean ± σ):      8.766 s ±  0.160 s    [User: 5.873 s, System: 1.346 s]
  Range (min … max):    8.496 s …  9.033 s    10 runs
```

Summary of results: it seems to be in the noise, this does not cause any
visible regression in times.
2023-09-08 11:48:40 +02:00
Robert Hensing 5ad01f1b6f lib/modules: Report a better error when option tree has bare type
Improves on 0d472a6201
- https://github.com/NixOS/nixpkgs/pull/242339

We actually do have the file name.

Thanks Shawn8901 for the [feedback]!

feedback: https://github.com/NixOS/nixpkgs/pull/242339#issuecomment-1683107055
2023-08-18 11:36:51 +02:00
Robert Hensing 0d472a6201 lib/modules: Report a good error when option tree has bare type
Note that this removes the possibility of declaring an option
named `_type`.
2023-08-14 10:44:56 +02:00
Robert Hensing 19f1d7da06
Merge pull request #245271 from sternenseemann/module-system-merge-no-type
lib/modules: handle typeless options in mergeModules
2023-07-27 10:55:08 +02:00
sternenseemann 9c35f44999 lib/modules: handle typeless options in mergeModules
mkOption does not require a `type` argument and does not set the
resulting attribute if it is not given. Consequently, we need to be
prepared to merge options that have no type information.
2023-07-26 23:58:04 +02:00
Robert Hensing 8014460c4d lib.mergeModules: Add context to error message 2023-07-11 13:03:52 +02:00
Robert Hensing 8f700580b9 lib/modules.nix: Format 2023-07-11 13:03:52 +02:00
Robert Hensing 4dd51a9ace lib/modules.nix: Inline single-use subtree bindings 2023-07-11 12:33:41 +02:00
Robert Hensing 6acc3114c3 lib/modules.nix: Make entire definition list strict in config check
This is a non-trivial refactor that slightly changes the semantics
of the internal definition lists.
Whereas previously only individual list items would trigger the exception,
now the error is promoted to the whole list.
This is mostly ok, because we compute the value, it is wrong to ignore a definition.
However, we don't always compute the value. For instance `readOnly`
only needs to count definitions. That won't be possible anymore when
the error is raised for one of the items. As a consequence, an error
will be raised for the errant definition instead of the number of
definitions.
2023-07-11 12:22:58 +02:00
Robert Hensing c28dd7d921 lib/modules.nix: Rename defnsByName -> pushedDownDefinitionsByName 2023-07-11 12:22:58 +02:00
Robert Hensing 448b153f81 lib/modules.nix: Rename defnsByName' -> rawDefinitionsByName 2023-07-11 12:22:58 +02:00
Robert Hensing fb988c6193 lib/modules.nix: Apply argument module of old f 2023-07-11 12:22:57 +02:00
Robert Hensing eb410eab82 lib/modules.nix: Apply argument modules of old old old byName 2023-07-11 12:22:57 +02:00
Robert Hensing 65de18210d lib/modules.nix: Apply argument f of old old byName 2023-07-11 12:22:57 +02:00
Robert Hensing c70a5e9223 lib/modules.nix: Apply argument attr of old byName 2023-07-11 12:22:08 +02:00
Robert Hensing d1e18a369a lib/modules.nix: Inline byName
byName is not an abstraction. This is the first commit in a series
that refactors it away.
2023-07-11 11:37:56 +02:00
Robert Hensing b1ad9cd27d
Merge pull request #238136 from hercules-ci/nixos-nixpkgs-dont-check-when-_module.args.pkgs-is-set
`nixos/nixpkgs`: Don't check when `_module.args.pkgs` is set
2023-06-23 19:17:36 +02:00
Robert Hensing 895ac17634
lib/modules.nix: Clean up mergeAttrDefinitionsWithPrio impl 2023-06-23 18:10:49 +02:00
figsoda 8a1a028694 lib/modules: remove unused let bindings 2023-06-23 09:41:04 +00:00
Robert Hensing 36ea2bbfe8 lib.modules: Add mergeAttrDefinitionsWithPrio
This will let us make assertions involving _module.args.pkgs, which
is not an option but a value attribute, and therefore doesn't have
its own highestPrio to inspect. The new function gives us that info.
2023-06-16 22:08:16 +02:00
pennae b9756b4de1 lib: unhide _module.args
this was a temporary fix that should hopefully no longer be necessary.
2023-06-16 19:26:23 +02:00
pennae d36f950d40 lib: turn *MD functions into aliases
with docbook gone and MD the default these aren't needed any more. we
can't remove them yet because there's thousands of uses, but maybe some
day we can.
2023-06-13 16:56:32 +02:00
Robert Hensing eab660d91e lib.modules: configurationClass -> class
This simplifies the documentation. `configuration` is implied by `_type`.
2023-05-06 18:32:59 +02:00
Robert Hensing 89491bef8d lib.modules: in evalModules return move _module.class -> configurationClass 2023-05-06 18:32:59 +02:00
Robert Hensing fd88c79418 lib.modules: Change class declaration in module to _class 2023-05-06 18:32:59 +02:00
Robert Hensing 8054785157 lib/modules: Move class out of specialArgs 2023-05-06 18:32:58 +02:00
Robert Hensing 73f584c3cc lib/modules.nix: Deduplicate documentation
`file://./..` looks redundant, but makes the url clickable in vscode.
2023-05-06 18:32:58 +02:00
Robert Hensing 84b1b01702 lib/modules: Only interpret class declaration in non-shorthand mode
This is to avoid stealing keys from submodules. `class` might be
common enough that reinterpreting existing `class` attributes in
configurations as a declaration leads to fairly widespread problems.
2023-05-06 18:29:04 +02:00
Robert Hensing 1f4a58ef03 lib/modules.nix: Refactor: extract applyModuleArgs 2023-05-06 18:29:04 +02:00
Robert Hensing 06ca78663c lib/modules.nix: Refactor: evaluate applyModuleArgsIfFunction in attrs case 2023-05-06 18:29:04 +02:00
Robert Hensing 439f6790bd lib/modules.nix: Restore old collectModules interface 2023-05-06 18:29:04 +02:00
Robert Hensing 9714487f74 lib/modules: Explain that a configuration can't be loaded as a module 2023-05-06 18:29:04 +02:00
Robert Hensing 2e689d58cb lib/modules: Improve error when a configuration is imported
This is appears to be a fairly common mistake for beginners who want
to build larger things from the system configurations, such as NixOps
networks, etc. Further explanation seems appropriate.
2023-05-06 18:29:03 +02:00