nh
nh copied to clipboard
`nh shell` and `nh run`?
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.
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.
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.
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 https://github.com/clap-rs/clap/issues/1232 https://github.com/clap-rs/clap/issues/3166
Also note that after https://github.com/viperML/nh/pull/151, nh will not be a flake-first tool, but rather support -f, -A, etc.