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

nh shell and nh run? #162

Open
iFreilicht opened this issue Oct 23, 2024 · 4 comments
Open

nh shell and nh run? #162

iFreilicht opened this issue Oct 23, 2024 · 4 comments

Comments

@iFreilicht
Copy link

It's been a major annoyance for a long time with nix-command that you always have to write out the name of the flake explicitly when using nix shell or nix run.

The popular nix-dram patches this functionality in, and it was requested for addition to lix, but as this is a breaking change, it was rejected.

Maybe this would be a good functionality to add to nh?

Being able to simply run nh shell cargo gcc would be a QoL improvement and not too difficult to implement. nh search already always uses nixpkgs, so there's less of an argument to be made against this being incompatible with other flakes.

@viperML
Copy link
Owner

viperML commented Oct 23, 2024

I don't want to implement that unless we can get completion support, and I don't have the bandwidth to look into implementing that.

@iFreilicht
Copy link
Author

I understand that. I may have a look at implementing this myself, but if anyone else reads this feel free to take it on.

Playing around a bit, it seems feasible to just shell out to nix eval. time nix eval nixpkgs#legacyPackages.aarch64-darwin --apply "builtins.attrNames" reports an average of 1.4s of runtime on my machine, so it would be an option to just read that, cache it in /tmp, and then search through that list.

You could search with eval directly: nix eval --json nixpkgs#legacyPackages.aarch64-darwin --apply 'pkgs: builtins.filter (x: (builtins.match "^ne.*" x) != null) (builtins.attrNames pkgs)'. This takes around half a second, no matter the query, so caching the full list will likely be quicker.

@viperML
Copy link
Owner

viperML commented Oct 24, 2024

From a quick search, this seems to be the way to implement it:

https://docs.rs/clap_complete/latest/clap_complete/engine/struct.ArgValueCompleter.html
clap-rs/clap#1232
clap-rs/clap#3166

@viperML
Copy link
Owner

viperML commented Oct 24, 2024

Also note that after #151, nh will not be a flake-first tool, but rather support -f, -A, etc.

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

2 participants