Skip to content

Comments

Hide experimental settings#7609

Merged
Ericson2314 merged 4 commits intoNixOS:masterfrom
obsidiansystems:hide-experimental-settings
Mar 27, 2023
Merged

Hide experimental settings#7609
Ericson2314 merged 4 commits intoNixOS:masterfrom
obsidiansystems:hide-experimental-settings

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jan 17, 2023

Motivation

Settings for experimental features should not be accessible without that experimental feature enabled. For example, if nix-command is enabled, but flakes is disabled, the CLI should refuse to:

  • accept flags which would modify flake-specific settings
  • list flake-specific settings in help and show-config
  • etc.

This commit allows marking settings experimental, like we do for built-ins already, in a declarative way.
It also allows flags to likewise be marked experimental, which is needed to implement the above but also useful in its own right.

Even if we were to stabilize flakes and nix-command at once (and I hope not!), it is still nice to have this functionality for future experimental features. For example, we might end up needing settings and flags that exist for ca-derivations. We should likewise be able to hide those from the stable CLI.

Context

In #7608 @roberth started investigating what would be needed to make a very simple command nix store gc, Hiding these flake settings was one of the items in his check list.

The first commit message as a test that fails, and the latter two fix the test, until it passes. The latter two have somewhat in-depth commit messages explaining the implementation strategy.

Needed for #7608.

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or bug fix: updated release notes

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks decent; just a suggestion and two nitpicks.
I don't think I know enough about how the initialization order of the settings to judge that aspect, but otherwise lgtm.

both_ways store gc --help

! nix --experimental-features 'nix-command' show-config --flake-registry 'https://no'
nix --experimental-features 'nix-command flakes' show-config --flake-registry 'https://no'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test would be more future proof, but this will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Yeah I would have to mock up a whole command thingy and parse it, at which point I'd be worried the mocking and the real world got out of sync.

@Ericson2314 Ericson2314 force-pushed the hide-experimental-settings branch from 8429ccc to 0463611 Compare January 17, 2023 16:29
@thufschmitt thufschmitt added the feature Feature request or proposal label Feb 10, 2023
@fricklerhandwerk fricklerhandwerk added UX The way in which users interact with Nix. Higher level than UI. documentation and removed feature Feature request or proposal labels Mar 3, 2023
@Ericson2314 Ericson2314 force-pushed the hide-experimental-settings branch from 0463611 to 8a6591b Compare March 17, 2023 00:31
@github-actions github-actions bot added with-tests Issues related to testing. PRs with tests have some priority and removed documentation labels Mar 17, 2023
@thufschmitt thufschmitt added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Mar 17, 2023
@Ericson2314 Ericson2314 marked this pull request as draft March 17, 2023 13:09
@Ericson2314 Ericson2314 force-pushed the hide-experimental-settings branch 2 times, most recently from 577c1b2 to c0e7b70 Compare March 18, 2023 17:39
@Ericson2314 Ericson2314 force-pushed the hide-experimental-settings branch 2 times, most recently from e64f893 to 359e1a6 Compare March 20, 2023 13:51
@Ericson2314 Ericson2314 marked this pull request as ready for review March 20, 2023 13:53
This is needed in subsequent commits to allow the settings and CLI args
infrastructure itself to read this setting.
We hide them in various ways if the experimental feature isn't enabled.

To do this, we had to move the experimental features list out of
libnixstore, because the setting machinary itself depends on it. To do
that, we made a new `ExperimentalFeatureSettings`.
If we conditionally "declare" the argument, as we did before, based upon
weather the feature is enabled, commands like

    nix --experimental-features=foo ... --thing-gated-on-foo

won't work, because the experimental feature isn't enabled until *after*
we start parsing.

Instead, allow arguments to also be associated with experimental
features (just as we did for builtins and settings), and then the
command line parser will filter out the experimental ones.

Since the effects of arguments (handler functions) are performed right
away, we get the required behavior: earlier arguments can enable later
arguments enabled!

There is just one catch: we want to keep non-positional
flags...non-positional. So if

    nix --experimental-features=foo ... --thing-gated-on-foo

works, then

    nix --thing-gated-on-foo --experimental-features=foo ...

should also work.

This is not my favorite long-term solution, but for now this is
implemented by delaying the requirement of needed experimental features
until *after* all the arguments have been parsed.
@Ericson2314 Ericson2314 force-pushed the hide-experimental-settings branch from 359e1a6 to 4607ac7 Compare March 20, 2023 15:37
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Mar 22, 2023

Discussed in the Nix team meeting 2023-03-17:

  • Annoying because of the churn coming with it
  • But also very useful as long as we have experimental features.
  • Idea approved, assigned to @roberth

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-17-nix-team-meeting-minutes-41/26614/1

@Ericson2314 Ericson2314 merged commit 570829d into NixOS:master Mar 27, 2023
@Ericson2314 Ericson2314 deleted the hide-experimental-settings branch March 27, 2023 13:19
@thufschmitt thufschmitt added this to the CLI Stabilisation milestone Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. UX The way in which users interact with Nix. Higher level than UI. with-tests Issues related to testing. PRs with tests have some priority

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants