Skip to content

Simplify user configuration #13671

Closed
Closed

Description

@NotTheDr01ds

Related problem

Related #13670

Goal: The environment variables visible to the user and internal configuration state should match.

It seems to me that an 893-line config (plus 101-line env) is overwhelming to many users, possibly even leaving a bad first impression to some. Regardless, it seems far more "cumbersome" than it should be.

Right now, a user has essentially two choices:

  1. Accept an 893-line config.nu and add to it (either in the file or through other files). In this case, the $env.config will be populated with the defaults that are in that file, with overrides by the user. The user can introspect the default values by observing, e.g., $env.config.table.mode.

    This is currently the only way to achieve the "Goal" above.

  2. Run with their own minimal config, but lose the ability to introspect the internal state, other than by reading through config nu --default and comparing what they've changed.

(config.nu example used here, but env.nu behaves the same)

Describe the solution you'd like

Internal defaults are obviously essential, but they don't all need to be exposed in the user's configuration files. For example, see almost every other shell config ;-)

My thoughts:

  • Get rid of the prompt to create config.nu and env.nu. Do it automatically if and only if the user is running for the first time (see Only ask user if they want to create a config.nu and env.nu one time #13669) and the $nu.default-config-dir doesn't exist.

    • Corollary: If the user deletes either file after first-run, don't regenerate them (a Fish-shell pet peeve I have ;-)
  • Always load default_env.nu and default_config.nu unless the user has started with nu --no-config-file/-n.

    • Yes, this includes when running with nu --config <file> or nu --env-config <file> so that the defaults are populated in memory.
  • Only write a minimal config.nu and env.nu that look something like:

    # Use config.nu to override default $env.config settings,
    # define (or import) custom commands, or run any other
    # startup tasks.
    # 
    # This file is loaded after env.nu and before login.nu
    # To examine the defaults, run:
    # config nu --default | nu-highlight
    # Use env.nu to add or override environment variables.
    # This file is loaded before config.nu and login.nu
    # To examine the defaults, run:
    # config env --default | nu-highlight

Advantages:

  • Users who want to put everything in config.nu can always just generate it with config nu --default | save config.nu (and with env.nu)
  • I think that loading default_env.nu would also get rid of the hacky "must treat PATH as string in config" issue, since the $env.ENV_CONVERSIONS would already be in place by the time any user-written code is parsed.
  • Should be pretty much no impact to startup time since the default_config.nu et. al. is the same size and parsing-time as the one that is written to disk by default now.
    • (From thread below) Even if a user duplicates the default config and env on-disk, the parsing and eval time is negligible - only a hair over 1ms on my system.

Describe alternatives you've considered

No response

Additional context and details

Note: About the only reason to not load the default_config.nu/default_env.nu when the user specifies --no-config-file is for performance reasons and testing. If this idea was implemented, it would be nice to have a separate --no-user-config that still loaded default_*.nu but not the on-disk, user files.

Activity

  1. added
    category:enhancement
    status:needs-triage
    on Aug 22, 2024
  2. changed the title [-]Load `default_config.nu` and `default_env.nu` in all cases[/-] [+]Load `default_config.nu` and `default_env.nu` in all cases (except when `--no-config-files` is used)[/+] on Aug 22, 2024
  3. fdncred commented on Aug 22, 2024

    @fdncred
    Contributor

    I guess your proposal means that if a user has a config.nu or env.nu it's additive and specifically meant to change a default. This is similar to people today using the defaults and at the end of config.nu they "source my_config_defaults.nu".

    It seems like this could also be a drag on startup times because you not only source the default config and env, but then you source whatever the user has for their config.nu and env.nu. So, if the user has "config nu --default | save config.nu", you're essentially doubling the parsing time, once for default_config.nu and once for config.nu. Am I understanding correctly?

  4. changed the title [-]Load `default_config.nu` and `default_env.nu` in all cases (except when `--no-config-files` is used)[/-] [+]Simple user configuration[/+] on Aug 22, 2024
  5. changed the title [-]Simple user configuration[/-] [+]Simplify user configuration[/+] on Aug 22, 2024
  6. added
    A:configuration
    on Aug 22, 2024
  7. NotTheDr01ds commented on Aug 22, 2024

    @NotTheDr01ds
    ContributorAuthor

    it's additive and specifically meant to change a default

    Yes, absolutely, and this seems to me to be the "traditional" way of doing things in a shell. Not that I don't think bad traditions should be rethought, but I believe this is a good tradition.

    So, if the user has "config nu --default | save config.nu", you're essentially doubling the parsing time, once for default_config.nu and once for config.nu. Am I understanding correctly?

    Yup - Caught me before I could get back here to edit that in. I had that idea after I typed it but before I got back to the keyboard. Yes, if a user wants the entire default_config.nu on the filesystem, it would double parsing time.

    A couple of thoughts on that though:

    • First, I would hope we could break users of that desire. Having all values be introspectable would, I hope, satisfy the use case for most users (again, I'd point to millions of users using other shells as a likely existence proof).

    But, there may be some other use cases:

    • If they simply want it for "reference" on the filesystem, then they could save it to default_config.nu with no parsing impact. I think most would opt for config nu --default (especially if documented in the "sparse" config), but it's an option.

    • Some shells (or at least distributions providing those shells) ship a config with defaults commented out that the user can uncomment to change. This could be done easily with

      config env --default | lines | each { $"# ($in)" } | to text | save config.nu

      (Hand-waving around the $env.config setting still being monolithic and not able to be uncommented line-by-line, but this would be fixable by changing the default to be "additive", although I'd be curious if there was a performance impact there).

  8. NotTheDr01ds commented on Aug 22, 2024

    @NotTheDr01ds
    ContributorAuthor

    Also, while we didn't test this scenario while we were looking at it in our stdlib Discord chat a while back, parsing and evaluating the default seems to be around 1ms:

    nu --no-std-lib -c "$nu.startup-time"
    # => 2ms 199µs 781ns
    nu --no-config-file --no-std-lib -c "$nu.startup-time"
    # => 1ms 72µs 895ns
    

    That's with an on-disk config.nu and env.nu generated in a fresh temp XDG_CONFIG_HOME.

  9. fdncred commented on Aug 22, 2024

    @fdncred
    Contributor

    I think nu -c only loads the env.nu file. I don't believe it loads the config.nu.

  10. NotTheDr01ds commented on Aug 22, 2024

    @NotTheDr01ds
    ContributorAuthor

    Probably right - I didn't check the gist on that. env.nu is more of an impact - Seems to add 5ms when I test it without -c and just checking the value in the session.

    Taking a guess that the performance hit for env.nu is because more lines-of-code get parsed, and several commands loaded into scope as well (e.g., def create_left_prompt).

  11. fdncred commented on Aug 22, 2024

    @fdncred
    Contributor

    I'm not sure you can depend on env.nu being slower thought. For instance, my config.nu is much bigger and i do a lot of useing and sourceing at the end of my config.nu so it's bringing in other files to parse.

    Also, i've started thinking about relative time and time per byte recently because saying something takes 1ms or 5ms is relative to their system. I've tried to implement this here in my startup-stats custom command. The last 2 columns are new.
    image
    In one respect this is still relative because it's only on my windows vm, but at least we're not talking about pure startup time without taking into account if i'm sourcing 1 line or 100k lines.

  12. NotTheDr01ds commented on Aug 22, 2024

    @NotTheDr01ds
    ContributorAuthor

    I'm not sure you can depend on env.nu being slower thought. For instance

    Sure, but we're measuring the impact of double-loading the defaults, right?

  13. removed
    status:needs-triage
    on Aug 28, 2024
  14. NotTheDr01ds commented on Aug 17, 2025

    @NotTheDr01ds
    ContributorAuthor

    This is now implemented by #13857, #14249, #14435 and others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:configurationcategory:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions