Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid config file creation on every Nushell start #6434

Open
gbirke opened this issue Feb 11, 2025 · 1 comment
Open

Avoid config file creation on every Nushell start #6434

gbirke opened this issue Feb 11, 2025 · 1 comment
Assignees

Comments

@gbirke
Copy link
Contributor

gbirke commented Feb 11, 2025

Description

Currently, the Nushell integrations work by writing Nushell commands into the nushell env file:

  1. create an "${config.xdg.cacheHome}/somepackage directory
  2. Call the binary (in nushell) to generate the nushell configuration.

The next step of the integration then writes a source command into config.nu that loads the file.

for examples, see

The current way of generating these config files means that they will be re-generated on every start of Nushell, adding to the startup time and causing disk writes. As an improvement, I suggest running the file-creation command with nix (don't know enough about that to make a specific function suggestion).

@boomshroom
Copy link

boomshroom commented Feb 13, 2025

Nushell will automatically load any files in $XDG_DATA_DIRS/nushell/vendor/autoload, and NixOS automatically adds any place the user profile might be to XDG_DATA_DIRS. My personal config did this by disabling the default nushell integration for each of the modules I was using, and instead used pkgs.runCommand to generate the files at build time and put them into $out/share/nushell/vendor/autoload, and added the resulting derivations to home.packages.

This functionality was only added fairly recently in 0.96, so it's not too surprising that it wasn't used.

Starship:

home.packages = mkIf cfg.enableNushellIntegration [ (
  pkgs.runCommand "starship-nushell" { } ''
    mkdir -p $out/share/nushell/vendor/autoload
    ${lib.getExe cfg.package} init nu > $out/share/nushell/vendor/autoload/starship.nu
  ''
) ];

Zoxide:

home.packages = mkIf cfg.enableNushellIntegration [ (
  pkgs.runCommand "zoxide-nushell" { } ''
    mkdir -p $out/share/nushell/vendor/autoload
    ${lib.getExe cfg.package} init nushell > $out/share/nushell/vendor/autoload/zoxide.nu
  ''
) ];

Oh-my-posh:

home.packages = mkIf cfg.enableNushellIntegration [ (
  pkgs.runCommand "oh-my-posh-nushell" { } ''
    mkdir -p $out/share/nushell/vendor/autoload
    ${lib.getExe cfg.package} init nu ${configArgument} --print > $out/share/nushell/vendor/autoload/oh-my-posh.nu
  ''
) ];

Style may differ though. I generally use lib.getExe and lib.singleton, though the existing modules don't seem to do that.

Note that an alternative would be to get upstream to add to the package's postInstall to write the files in their own paths, at which point they would be unconditionally enabled even without home-manager doing anything. I'm pretty sure fish has something similar, and the same is probably true for zsh. At that point though, why not just do it for every shell that supports vendor scripts and that each package supports?

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

No branches or pull requests

5 participants