nix-community / nix-on-droid

Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli]
https://nix-on-droid.unboiled.info
MIT License
1.17k stars 65 forks source link

Package-specific tab-completion doesn't work #206

Open ShamrockLee opened 1 year ago

ShamrockLee commented 1 year ago

It seems that we only have tab completion for file path and commands.

Tab completions defined by individual packages, such as those for git, simply doesn't work.

If there's a way to enable such feature, it would be great to document it.

Reproduction steps:

  1. Make git available by either installing through the nix-on-droid.nix or invoking a nix-shell.
  2. Go to the terminal prompt.
  3. Type gitTab
  4. See only paths to files / directories instead of git subcommands.
Gerschtli commented 1 year ago

The problem is that the default nix-on-droid system does not load autocompletion files for any shell. It should be a rather simple fix in /etc/bashrc and /etc/zshrc adding default directories in ~/.nix-profile to the shell init scripts.

But the more I think about it, I see a general issue of clear separation of responsibilities. To compare nix-on-droid with similar system configurations like NixOS or nix-darwin in relation with home-manager, the system configurations never read or write things in the users home directory, this is solely left for home-manager. Another interesting thing in these system configurations is that they install their final build into /run/current-system (where the equivalent to the nix-on-droid-path package is available in /run/current-system/sw). This has some advantages like you have a clear separation between system installations and user specific installations. I agree that this is a rather irrelevant benefit for a single user setup but would help us maintaining a clear direction what should be scope of nix-on-droid and what is scope of home-manager.

So the change would be to load completion files for system installed packages and would then prevent redundant loading of these files once enabling home-manager which also loads them by default.

To make a long story short: Do we want to go with NixOS/nix-darwin approach of /run/current-system instead of ~/.nix-profile? @t184256 What do you think?

t184256 commented 1 year ago

If you're asking for my opinion, it's simple: system packages are there for hardware enablement (not applicable to n-o-d), non-user services and "recovery" packages that should be enough for hammering a package manager into a usable shape. Everything else goes to user packages, or, better, home-manager. So my answer would be to enable h-m if you want any kind of bells and whistles, and then programs.bash.enableCompletion.

I don't think this view is universally held across the Nix community, but you're right in that system packages are even less relevant for our essentially single-user install.

ShamrockLee commented 1 year ago

@t184256 Thank you for your detailed explanation.

Unfortunately, the Home Manager configuration programs.bash.enable = true;, which should enable the default programs.bash.enableCompletion = lib.mkOptionDefault true;, doesn't solve the issue.

t184256 commented 1 year ago

I've tested it before posting this comment and it worked for me (on all-unstable channels).

ShamrockLee commented 1 year ago

~It works now after updating nix-on-droid.~

~Thanks a lot!~

Update: It's the prompt that works, not the tab completion. I'll try to upgrade nixpkgs and Home Manager to unstable also.

ShamrockLee commented 1 year ago

I eventually work around this issue using

  programs.bash = {
    enable = true;
    bashrcExtra = ''
      while IFS= read -r _completionFile; do
        source "$_completionFile"
      done < <(${pkgs.findutils}/bin/find "$HOME/.nix-profile/share/bash-completion/completions" -mindepth 1 -maxdepth 1 -type f,l)
      unset _completionFile
    '';
  };

in home.nix.