Nixpkgs: [Package Request] Gradle (auto) completion

Created on 30 Jun 2018  Â·  10Comments  Â·  Source: NixOS/nixpkgs

It would be nice if we are able to have gradle-completion, in the same way we have bash-completion, and the other _completion siblings_.

I know it's easy to just cURL and store gradle-completion.bash in $HOME/.nix-profile/etc/bash_completion.d/, but doing that we have to allow the user in question to write to that location (I don't really know the repercussions of that...if any) and really defeats the purpose, somehow, of Nix Packages.

Most helpful comment

I rechecked with the following vm config (which is basically the same as the settings I posted in my commit message):

{
  gradlefoo = { pkgs, ... }: {
    environment.systemPackages = [ pkgs.gradle pkgs.gradle-completion ];
    programs.zsh.enable = true;
  };
}

It seems to work perfectly fine with gradle *cmd*, however the validation breaks with ./gradlew (didn't test this, mostly use gradle as it's easier to type :sweat_smile:)

It shouldn't be too hard to fix this, I'll ping you when it's done.

All 10 comments

as the modules (at least for bash and zsh) are fairly advanced it shouldn't be too hard.
I'll try to have a look at it tonight %)

Hi, I installed gradle-completion-1.3.1 on Arch Linux 4.14.56-1-lts #1 SMP Tue Jul 17 20:11:42 CEST 2018 x86_64 GNU/Linux, but whenever I go into any Gradle-based project it doesn't work – as it works in macOS when I install it using Brew. It just doesn't discover, nor auto-completes any of the (currently available) tasks.

Maybe it's not getting sourced into the shell? I do have bash-completion-2.8 also installed, not sure if that's an impediment (or not):

[gorre@uplink ~]$ nix-env -q
bash-completion-2.8
dep-0.4.1
flatpak-builder-0.99.3
git-2.18.0
gradle-completion-1.3.1
hugo-0.42.1
jq-1.5
netstat-1003.1-2008
nix-2.0.4
nmap-7.70

I actually confirmed that the package is doing its job, however it can be possible that I screwed something up (e.g. something in my system config made it work). I don't think that I'll have sufficient time to look at this tonight, by I'll definetely keep this in mind and have a deeper look at this as soon as I have time to.

I rechecked with the following vm config (which is basically the same as the settings I posted in my commit message):

{
  gradlefoo = { pkgs, ... }: {
    environment.systemPackages = [ pkgs.gradle pkgs.gradle-completion ];
    programs.zsh.enable = true;
  };
}

It seems to work perfectly fine with gradle *cmd*, however the validation breaks with ./gradlew (didn't test this, mostly use gradle as it's easier to type :sweat_smile:)

It shouldn't be too hard to fix this, I'll ping you when it's done.

For me, even if I try to use gradle alone, when I hit Tab (auto-complete) on the shell (GNU bash, version 4.4.23(1)-release), it does auto-complete what I have in the directory, which is fine, but I guess at some point the gradle-completion script(s) should take over the "normal" shell auto-completion.

[gorre@uplink kotlin-grpc]$ ll
total 84K
drwxr-xr-x 9 gorre 4.0K Jul 24 08:47 .git/
drwxr-xr-x 3 gorre 4.0K Jul 22 11:34 client/
drwxr-xr-x 3 gorre 4.0K Jul 22 11:32 gradle/
drwxr-xr-x 3 gorre 4.0K Jul 22 11:34 protobuf/
drwxr-xr-x 3 gorre 4.0K Jul 22 11:34 server/
-rw-r--r-- 1 gorre   91 Jun  8 21:55 .dockerignore
-rw-r--r-- 1 gorre  334 Oct 25  2017 .editorconfig
-rw-r--r-- 1 gorre  125 Jul  5 20:26 .gitattributes
-rw-r--r-- 1 gorre   83 Jul 22 11:35 .gitignore
-rw-r--r-- 1 gorre  242 Jun 19 22:01 .gitlab-ci.yml
-rw-r--r-- 1 gorre   11 Jun 14 21:33 .tool-versions
-rw-r--r-- 1 gorre 1.9K Jul  5 22:13 Dockerfile
-rw-r--r-- 1 gorre 1.1K Jul 22 11:33 LICENSE
-rw-r--r-- 1 gorre 1.5K Jul  4 16:33 README.asciidoc
-rw-r--r-- 1 gorre 2.7K Jun 14 22:12 build.gradle
-rw-r--r-- 1 gorre  157 Jun 30 20:10 docker-compose.yml
-rw-r--r-- 1 gorre   31 Oct 25  2017 gradle.properties
-rwxr-xr-x 1 gorre 5.2K Jul 22 11:32 gradlew*
-rw-r--r-- 1 gorre 2.3K Jul 22 11:32 gradlew.bat
-rw-r--r-- 1 gorre  319 Jul  5 23:00 settings.gradle
[gorre@uplink kotlin-grpc]$ gradle 
build.gradle        Dockerfile          .git/               .gitlab-ci.yml      gradlew             protobuf/           settings.gradle     
client/             .dockerignore       .gitattributes      gradle/             gradlew.bat         README.asciidoc     .tool-versions      
docker-compose.yml  .editorconfig       .gitignore          gradle.properties   LICENSE             server/

[gorre@uplink kotlin-grpc]$ ./gradlew 
build.gradle        Dockerfile          .git/               .gitlab-ci.yml      gradlew             protobuf/           settings.gradle     
client/             .dockerignore       .gitattributes      gradle/             gradlew.bat         README.asciidoc     .tool-versions      
docker-compose.yml  .editorconfig       .gitignore          gradle.properties   LICENSE             server/

I'm fairly confused, are you sure that it's not caused by something else?
I tested it with a VM from nixpkgs master and inside gradle and ./gradlew work perfectly fine:

{
  gradle = { pkgs, ... }: {
    environment.systemPackages = with pkgs; [ gradle gradle-completion ];
  };
}

What I suspect now is that it could be caused by your user profile. I'm not sure if bash-completion actually pulls completion scripts from ~/.nix-profile. Would you mind checking this with a VM or by adding gradle-completion to environment.systemPackages in your configuration.nix?

Hi @Ma27, I'm using Arch Linux and the Bash shell.

I searched within my "home" directory for this file: configuration.nix and I couldn't find any. I did find a config.nix, but couldn't find environment.systemPackages on it.

[gorre@uplink .nix-profile]$ pwd
/home/gorre/.nix-profile

[gorre@uplink .nix-profile]$ find -L share/ -iname "*.nix"
share/nix/corepkgs/buildenv.nix
share/nix/corepkgs/imported-drv-to-derivation.nix
share/nix/corepkgs/fetchurl.nix
share/nix/corepkgs/derivation.nix
share/nix/corepkgs/unpack-channel.nix
share/nix/corepkgs/config.nix
[gorre@uplink .nix-profile]$ cat share/nix/corepkgs/config.nix
let
  fromEnv = var: def:
    let val = builtins.getEnv var; in
    if val != "" then val else def;
in rec {
  shell = "/nix/store/zqh3l3lyw32q1ayb15bnvg9f24j5v2p0-bash-4.4-p12/bin/bash";
  coreutils = "/nix/store/cb3slv3szhp46xkrczqw7mscy5mnk64l-coreutils-8.29/bin";
  bzip2 = "/nix/store/qqv6r9vkpb44rw5d8wyfpx64rgqzlvdm-bzip2-1.0.6.0.1-bin/bin/bzip2";
  gzip = "/nix/store/d7895h1an2pgcd6a3vx3yb5fbg786lci-gzip-1.9/bin/gzip";
  xz = "/nix/store/aakgkcvw6j54zg38zrn1w00sgxx0zj8b-xz-5.2.3-bin/bin/xz";
  tar = "/nix/store/2p00w952ljb1172nsf3jm7nsjgsw5qpw-gnutar-1.30/bin/tar";
  tarFlags = "--warning=no-timestamp";
  tr = "/nix/store/cb3slv3szhp46xkrczqw7mscy5mnk64l-coreutils-8.29/bin/tr";
  nixBinDir = fromEnv "NIX_BIN_DIR" "/nix/store/0d60i73mcv8z1m8d2m74yfn84980gfsa-nix-2.0.4/bin";
  nixPrefix = "/nix/store/0d60i73mcv8z1m8d2m74yfn84980gfsa-nix-2.0.4";
  nixLibexecDir = fromEnv "NIX_LIBEXEC_DIR" "/nix/store/0d60i73mcv8z1m8d2m74yfn84980gfsa-nix-2.0.4/libexec";
  nixLocalstateDir = "/nix/var";
  nixSysconfDir = "/etc";
  nixStoreDir = fromEnv "NIX_STORE_DIR" "/nix/store";

  # If Nix is installed in the Nix store, then automatically add it as
  # a dependency to the core packages. This ensures that they work
  # properly in a chroot.
  chrootDeps =
    if dirOf nixPrefix == builtins.storeDir then
      [ (builtins.storePath nixPrefix) ]
    else
      [ ];
}

My Bash shell is the one that comes by default with Arch Linux. I did the same on a virtual machine with Ubuntu 18.04.1 LTS.

Let me know if you want more info.

Ah good to know! I've been testing on NixOS, configuration.nix usually which defines the system's entire state. But I'm fairly certain that this is related to gradle-completion living in ~/.nix-profile, please give me som etime to investigate, but this sounds like a bug in the bash packages themselves...

It might be a bug because right now that I'm on it, I should also have auto-completion for Git commands (due to the fact that I have bash-completion), and it doesn't work either.

I even added /home/gorre/.nix-profile/share/ to $XDG_DATA_DIRS, but still, nothing going on there:

[gorre@uplink kotlin-grpc]$ echo $XDG_DATA_DIRS
/home/gorre/.nix-profile/share/:/home/gorre/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/

Thanks for the effort!

I see... Unfortunately I don't use the user profile for this so I might lack the required knowledge. I'd recommend to look for related tickets (or open a new one) as I'm fairly certain now that this is related to the integration of bash-completion into ~/.nix-profile.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chris-martin picture chris-martin  Â·  3Comments

yawnt picture yawnt  Â·  3Comments

grahamc picture grahamc  Â·  3Comments

sid-kap picture sid-kap  Â·  3Comments

tomberek picture tomberek  Â·  3Comments