I’m constantly learning new gestures and workflows; all I can do is try to document them
NixOS modules are great; and it’s one of the superpowers of NixOS. They’re so great, there was a working group to look into how to apply the concept to Nixpkgs itself. For those uninitiated, there are plenty of guides online describing it’s value and...
9 Likes
Would be nice if there is a way to map these source hashes to flake names or if flakes named the source path after the flake.
How do I know which has represents which flake? It’s still kind of user unfriendly
Interesting idea; everthing is just the hash name… hmm.
FYI nixos-option
is getting a rewrite with flake support, might consider contributing there if you have ideas.
NixOS:master
← FireyFly:nixify-nixos-option
opened 10:02PM - 21 May 24 UTC
This ports the functionality of the C++ `nixos-option` to a nix script (with a t… iny shellscript for argument processing and invoking the nix script). The main impetus for this is that the current C++ version seems a bit verbose, unnecessarily tightly coupled to cppnix internals, fragile (with the occasional segfaults if you hold it slightly wrong).
While I'm rewriting it anyway, I opted to improve the output format slightly to make it easier on the eyes (there's no point in the type/description strings and declared/defined by lists as nix values; instead just make sure each output is indented with two spaces).
There's some changes in behaviour especially when it comes to errors whilst evaluating options. In recursive mode, errors that can be caught with `builtins.tryEval` render as just `«error»` whereas fatal errors bubble to the top and stop the recursion (the old C++ version prints the full stacktrace inline in place of the value for each option where evaluating the value errors).
The new version supports descending into `attrsOf`/`listOf` submodule options (as long as they're defined in the user's config)--the previous version doesn't seem to understand them (and segfaults in the recursive case, e.g. `nixos-option -r users.users.youruser`).
The new version (well, the shell wrapper part of it) supports `--show-trace` for full error traces.
Performance is basically unchanged vs the existing version (I think most of the time is spent evaluating nixos anyway).
Fixes #293543
Fixes #97855
---
Before this is merged, it'd be nice if it was a bit more widely tested (so far I've just tested it a bit on random options/paths locally).
The manual page should probably also be updated, and release notes added, but I figured it makes sense to get some feedback on the derivation changes first.
## Description of changes
* C++ implementation of `nixos-option` removed
* nixlang implementation added, with a small shellscript wrapper to invoke it
- (this uses `nix-instantiate --eval --json | jq -r` as a hack to output raw strings; suggestions for improvements welcome)
* new `default.nix`; I took the liberty to change the license since it's a fresh implementation anyway and doesn't link against nix (and if anything I took some notes from the `nixos-rebuild` derivation, which is also MIT licensed)
## Things done
- Built on platform(s)
- [x] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://nixos.org/manual/nixpkgs/unstable/#ssec-nixos-tests-linking) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [24.05 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2405.section.md) (or backporting [23.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2305.section.md) and [23.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2311.section.md) Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [ ] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
6 Likes
nbp
July 30, 2024, 10:00am
5
I doubt that definitionsWithLocations
is only 2 years old, given that this feature was present in the first iteration of nixos-option
(the bash + sed + nix script) and that it used to be included in the manual a very long time ago.
For the problem of quickly debugging with multiple mergeable definitions, you might be able to fallback on creating an additional option declaration, which would be merged with the previous option declaration, and let you declare the option as being read-only, i-e force having a single definition:
{lib, ...}: {
options = {
a.value = lib.mkOption {
readOnly = true;
};
};
}
Another problem related to option introspection is, where are options used. At the moment the only way to figure this out is this (most likely outdated) option-usage.nix script , which will evaluate a configuration once, then re-evaluate each of the options replacing them one by one with a throw
and catch the failures to compute a graph of usage, i-e O(n²). Until Nix / nixos-option
gets reflexivity or partial evaluation, there is no better way to solve this issue.
Another worth mentioning project:
5 Likes
I would try the readOnly
or conflict option but I found this lacking:
It only prints a single conflict definition
I wanted to know who set a value and if it’s mergeable this is even harder
Thanks for the advice nontheless.
Wow so instead of going backwards, option-usage
helps you figure it forward with fixed-point iteration replacing with throws? Cool.
Yea I’ve used this also; pretty good tool.
inclyc
July 31, 2024, 1:35am
9
Language servers teach your editor how to ‘goto definition’ via nix repl. AFAIK in nixd you can “goto declaration” to nixos/home-manager options.
“goto definition”, likely can be easily implemented in the same way but not done yet.
1 Like
The interesting is that there can be multiple definitions.
Never seen that in a language before especially with merged values.
You’d need a popup to show which to choose
inclyc
July 31, 2024, 5:00am
11
As per my understanding LSP protocol actually allows the server sending multiple locations, that would be simple and vscode indeed shows you a list of locations.
2 Likes