Feature detection: builtins.features
#607
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
ux
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#607
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
We would like to enable feature detection for the "userspace".
Describe the solution you'd like
The structure we could envision is to produce a attrset which would contain things like those:
builtins.features."systems.lix".something
Describe alternatives you've considered
Suffer the same frustrations all the time about builtins proliferation and have userspace suffer.
See prior art like #144.
Additional context
Mentioned in person with @jade.
A
builtins.features
as an attrset would permitattrNames builtins.features
, which would be another source of entropy and another temptation to put more info in derivations, but this can be mitigated.Instead, it could be a function to bool, example:
Returning a bool may or may not be required. I'd lean towards specifying that the type may depend on the string, but I suppose we'll have lots of bools.
Related discussion: https://github.com/NixOS/nix/pull/5971#issuecomment-1021695124
Hmmm. On the other hand, an attr set is nice because it's discoverable, though this is a temptation as you've mentioned.
It could be a useful compromise if the features list is directly in the documentation string of the function, I suppose. But I also think each feature should have its own little paragraph describing what it is, when it showed up, and similar. I wonder how we could expose that ergonomically to the repl use case.
This issue was mentioned on Gerrit on the following CLs:
+1 for
builtins.hasFeature
, this is the approach that Vim uses and it works really well.Isn't
builtins ? x
already it, in the end?Often is, but not for everything. Some things are more subtle, like improvements to a builtin.
Also syntax extensions, in case users want to report nice errors in some central entrypoint file like
flake.nix
or/default.nix
or whatnot, and they don't use the extension in those entrypoints.I'd recommend against putting store level stuff in here, because that would end up requiring things like querying the remote builders and it breaks the
nix-instantiate
->nix-store -r
flow, where conceptuallynix-instantiate
doesn't have builders, esp. if IFD is disabled.Store level stuff is complicated for sure. I'm not sure what to do about that as it's definitely something that presents a problem for compatibility but it's impossible in the current protocol to probe and besides, eval and build are often separate. It's out of scope for this one, either way.
The purpose of hasFeature is indeed for if we fix builtins. For example, without using either nixVersion (on CppNix only! we neutered ours) or using getFlake as a proxy, it's impossible to tell from nix code if the version of fetchTree contains the bug where it will throw an uncatchable error if flakes are disabled rather than not be present, or if flakes are enabled and it works fine.
That is, it's for builtins having changes in having more accepted arguments.
Also btw y'all were thinking of doing a similar neutering of builtins.nixVersion as the one we did but I think it fell through the cracks since 2023. Might want to revive that along with the port of this once we land it.
--json=lix2025
for all json output from Lix #901