Load default_env.nu/default_config.nu before user env.nu/config.nu#14249
Load default_env.nu/default_config.nu before user env.nu/config.nu#14249fdncred merged 27 commits intonushell:mainfrom
default_env.nu/default_config.nu before user env.nu/config.nu#14249Conversation
|
@fdncred For your gist on this topic, I believe we'll find that For example, if |
|
Edit: This was implement: I'm thinking (but not totally sure yet) that we might could also move the "path conversion" code so that it runs after the |
|
Thanks for the PR! Just tried this out, but it look likes |
|
@IanManske Thanks for testing! Can you give me some more detail on your startup?
Thanks! |
|
Sure thing, I'm on 938cd2c and ran:
|
|
@IanManske Ah - Thanks! That's working as expected then. When you run with If you want to test in a clean environment: $env.XDG_CONFIG_HOME = (mktemp -d)
./target/debug/nuYou should see something like: ... followed by the banner. And After exiting that shell, you can clean up with: rm -r $env.XDG_CONFIG_HOME
hide-env XDG_CONFIG_HOME |
@NotTheDr01ds it would be good if someone would take my gist and turn it into some documentation with these changes you're talking about. |
|
@fdncred Sure thing - I'll get that in when I do that Config chapter update/rewrite for these changes. |
|
In today's meeting, we discussed several options that might allow users to disable the loading of defaults:
So I'm going to back out the flag. We also decided we will hold this until after 0.100.0 is released. This will give us more time for it to bake in nightly's/etc. |
|
Also, as requested during today's meeting, here's a link to the gist. |
|
@NotTheDr01ds Thank you kindly for adding a summary of what we discussed in the meeting today 😄 |
|
One thing that I honestly didn't notice until after the call yesterday is just how substantially @IanManske's #13802 changed the way config works. I usually just gloss over PR's with "refactor" in the title ;-). That's a great change, and does a lot of what this PR would have done if #13802 wasn't in place. But the combination of both of these gives us even more opportunities, I think. I'm thinking of now changing $env.config = {}Because of Ian's work, this will now populate all values from And ... Sweet! This shaves another (average) ~3ms (on my system) off a default/base launch time compared to 0.99.1. There might be a few values we want or need to populate back in, so that the "internal defaults" and |
8f0b3c3 to
9aa2d04
Compare
|
Some of the config settings will probably be hard to set through the Rust code like the hooks and theme, so I agree we probably still want something (or most things?) in the |
|
Related / maybe Unrelated Just posting what I posted on Discord
|
At least temporarily, I'm planning on moving the current (fully-loaded) version of Long-term, I'd like to implement something like @fdncred pointed out with the Ghostty stuff at some point. In our case, though, it would be something like: # Flattened tables
help config-option --list/-l --current
help config-option --list-l --default
help config-option --list-l --overrides
# Perhaps, to avoid too deeply nested a structure above:
help keybindings ...
help hooks ...
# Show help on option
help config-option <option>I wonder if we could add the documentation on each setting directly to the configuration as we do with commands? |
|
I kind of feel like there needs to be a readme.md in the default_files folder that describes the config files. we have 3 config files, config, env, login. some of those have default_ files, some have scaffold_ files, some have sample_ files but it's not the same for all 3 groups so it's a bit confusing. default_has config and env but no login scaffold_has config and env but no login sample_has config and login but no env even after reading the code i'm confused about all these files, what their purpose is, and when they're loaded. LOL. |
ac69246 to
2a5ce7d
Compare
|
@fdncred Fair enough - It's (a) confusing, and (b) probably in flux regardless. I'll add a README there, but long-term, I think both the I'm not even sure what the purpose of |
|
|
|
Right, but it wasn't actually used - I would have thought it would be written to the config directory, but it's not. I don't think most users were going to find it at |
|
I'm trying to test this out on Windows my setting the XDG_CONFIG_HOME var but I'm having problems. If I have this I get an error. $env.config.table = {
show_empty: false
trim: {
truncating_suffix: "…"
}
header_on_separator: true
footer_inheritance: true
}If I replace it with my entire Here's my config & env in case someone can spot something wrong. |
|
This looks like a big improvement+simplification. Thank you! |
default_env.nu/default_config.nu before user env.nu/config.nu
# Description As a bit of a follow-on to #13802 and #14249, this (pretty much a "one-line" change) really does *always* populate the `$env.config` record with the `nu-protocol::config` defaults during startup. This means that an `$env.config` record is value (with defaults) even during: * `nu -n` to suppress loading of config files * `nu -c <commandstring>` * `nu <script>` # User-Facing Changes There should be no case in which there isn't a valid `$env.config`. * Before: ```nushell nu -c "$env.config" # -> Error ``` * After: ```nushell nu -c "$env.config" # -> Default $env.config record ``` Startup time impact is negligible (17.072µs from `perf!` on my system) - Seems well worth it. # Tests + Formatting Added tests for several `-n -c` cases. - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting Config chapter update still in progress.
# Description Due to #14249 loading `default_env.nu` before the user's `env.nu`, variables that were defined there were overriding: * Inherited values * Some values that were set in the Rust code, such as the `NU_LIB_PATH` when set using `--include-path`. This change checks to see if a variable already exists, uses its value if so, and sets the default value otherwise. Note: `ENV_CONVERSIONS` is still "forced" to a default value regardless, as it needs to run reliably. There's probably not much reason to inherit it, but I'm open to the idea if there's a use-case. # User-Facing Changes * Before: Variables that were set in `default_env.nu` always overrode those that were inherited from the parent process or set internally * After: Inherited and internal environment variables will take priority. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting Will try to find a good place to mention this behavior in the Config chapter updates
# Description #14249 loaded `convert_env_values()` several times to force more updates to `ENV_CONVERSION`. This allows the user to treat variables as structured data inside `config.nu` (and others). Unfortunately, `convert_env_values()` did not originally anticipate being called more than once, so it would attempt to re-convert values that had already been converted. This usually leads to an error in the conversion closure. With this PR, values are only converted with `from_string` if they are still strings; otherwise they are skipped and their existing value is used. # User-Facing Changes No user-facing change when compared to 0.100, since closures written for 0.100's `ENV_CONVERSION` now work again without errors. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` - # After Submitting Will remove the "workaround" from the Config doc preview.
| @@ -0,0 +1,792 @@ | |||
| # Nushell Config File | |||
| # | |||
| # version = "0.99.2" | |||
There was a problem hiding this comment.
@PerchunPak Good catch. @NotTheDr01ds I'm also thinking all these config/env/scaffold/sample files should have a version at the top. Also, I'm getting an error in one. It should be = not :.

There was a problem hiding this comment.
there are many syntax errors in the nightly build, not only this one
and many more
i will probably create a pr fixing all those
…nt prompt vars (#14579) # Description With `NU_LIB_DIRS`, `NU_PLUGIN_DIRS`, and `ENV_CONVERSIONS` now moved out of `default_env.nu`, we're down to just a few left. This moves all non-closure `PROMPT` variables out as well (and into Rust `main()`. It also: * Implements #14565 and sets the default `TRANSIENT_PROMPT_COMMAND_RIGHT` and `TRANSIENT_MULTILINE_INDICATOR` to an empty string so that they are removed for easier copying from the terminal. * Reverses portions of #14249 where I was overzealous in some of the variables that were imported * Fixes #12096 * Will be the final fix in place, I believe, to close #13670 # User-Facing Changes Transient prompt will now remove the right-prompt and multiline-indicator once a commandline has been entered. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` - # After Submitting Release notes addition
|
@PerchunPak Yes, the conversion from the old As for the version numbers, I assumed these were added automatically during the build process, but I didn't dive in to be sure. I'm fairly certain no one goes in and manually updates them each release ;-) @fdncred I'm not sure the |
|
Actually, looking through these, none of them should be "versioned" any longer. That's a relic of having breaking changes in default configs, which #14249 does away with. |
|
@NotTheDr01ds I think we should version all of them to demonstrate which version they're released with and compatible with. For instance, if you rename something like |
For some reason, it had multiple syntax errors and other issues, like undefined options. Would be great to add a test for sourcing all example configs, but I don't know rust See also #14249 (comment) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> CC @NotTheDr01ds
# Description Takes advantage of #14591 to remove the now-necessary calls to `convert_env_values()` that I added in #14249. The function is now just called once to convert `PATH`. Also removed the Windows-build-time checks for `ensure_path`, since previous case-insensitivity fixes make this unnecessary as well. # User-Facing Changes None - #14591 now handles conversion 'on-demand'. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A
In #14249, `config reset` wasn't updated to use the scaffold config files, so running `config reset` would accidentally reset the user's config to the internal defaults. This PR updates it to use the scaffold files.
Release-Notes Short Description
default_env.nubefore the userenv.nuis loaded, then loads the internaldefault_config.nubefore the user'sconfig.nuis loaded. This allows for a simpler user-configuration experience. Details are in this blog entry along with an updated Configuration ChapterDescription
Implements the main ideas in #13671 and a few more:
env.nuandconfig.nuand yet still have access to all of the defaults:default_env.nu(internally defined) will be loaded whenever (and before) the user'senv.nuis loaded.default_config.nu(internally defined) will be loaded whenever (and before) the user'sconfig.nuis loaded.-cand scripts) vs. REPL defaults. This would have solved many of the user complaints about thedisplay_errorsimplementation.config.nuandenv.nuare created on first launch (if the config directory isn't present).(New: 2024-11-07) Runs the env_conversions process after thedefault_env.nuis loaded so that users can treatPath/PATHas lists in their own config.default_config.nuwill be a minimal file to minimize load-times. This shaves another (on my system) ~3ms off the base launch time.$env.config. The documentation will be updated to cover these scenarios.default_config.nutosample_config.nufor short-term "documentation" purposes.dark-themeandlight-themeto Standard Library and demonstrate their use - Also improves startup times, but we're reaching the limit of optimization.sample_env.nuandsample_config.nu. These can be displayed in-shell using (for example)config nu --sample | nu-highlight | less -R. Note: Much of this will eventually be moved to or (some) duplicated in the Doc. But for now, this some nice in-shell doc that replaces the older "commented/documented default".ENV_CONVERSIONSprocess (1) after thedefault_env.nu(allowsPATHto be used as a list in user'senv.nu) and (2) beforedefault_config.nuis loaded (allows user'sENV_CONVERSIONSfrom theirenv.nuto be used in theirconfig.nu).(New: 2024-11-20) The defaultReset - Looks like there might be a bug inENV_CONVERSIONSis now an empty record. The internal Rust code handlesPATH(and variants) conversions regardless of theENV_CONVERSIONSvariable. This shaves a very small amount of time off the startup.nu-enginer::env::ensure_path()on Windows that would need to be fixed in order for this to work.User-Facing Changes
By default, you shouldn't see much, if any, change when running this with your existing configuration.
To see the greatest benefit from these changes, you'll probably want to start with a "fresh" config. This can be easily tested using something like:
You should see a message where the (mostly empty)
env.nuandconfig.nuare created on first start. Defaults should be the same (or similar to) those before the PR. Please let me know if you notice any differences.Users should now specify configuration in terms of overrides of each setting. For instance, rather than modifying
historysettings in the monolithicconfig.nu, the following is recommended in an updatedconfig.nu:or even just:
Note: It seems many users are already appending a
source my_config.nu(or similar pattern) to the end of the existingconfig.nuto make updates easier. In this case, they will likely want to remove all of the previous defaults and just move theirmy_config.nutoconfig.nu.Note: It should be unlikely that there are any breaking changes here, but there's a slim chance that some code, somewhere, expects an absence of certain config values. Otherwise, all config values are available before and after this change.
Tests + Formatting
toolkit fmttoolkit clippytoolkit testtoolkit test stdlibAfter Submitting
Configuration Chapter (and related) of the doc is currently WIP and will be finished in time for 0.101 release.