How to Find Package of Installed Command

I have the command bluetoothctl in my system but I do not know via which package it has been installed:

~ which bluetoothctl
/run/current-system/sw/bin/bluetoothctl

~ ls -l /run/current-system/sw/bin/bluetoothctl
/run/current-system/sw/bin/bluetoothctl -> /nix/store/h5z7lwsr57mrbkqxrw6m2gqpl7dc2a9f-bluez-5.70/bin/bluetoothctl

How can I find out why this package has been installed?

There is a way using community tools such as nix-index GitHub - nix-community/nix-index: Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius]. It provides a nix-locate command, which searches for a file in the /nix/store and matches it to a corresponding derivation in nixpkgs.

Thanks for your help. The command returns several packages of which none I have installed explicitly:

➜  ~ nix-locate 'bin/bluetoothctl'

(wine.out)                /nix/store/4dmv4yivh83w8x47jnwv8rcr08r33ssj-bluez-5.70/bin/bluetoothctl
(lutris-free.out)         /nix/store/qaixszc5w12m8mx189lxxza2g5wcsrb4-lutris-fhs/usr/bin/bluetoothctl
(lutris-free.out)         /nix/store/qaixszc5w12m8mx189lxxza2g5wcsrb4-lutris-fhs/usr/sbin/bluetoothctl
(lutris-free.out)         /nix/store/r7p7wyqvvqxkdz6p9c5la9fkzxk0ckaa-lutris-usr-target/bin/bluetoothctl
(lutris-free.out)         /nix/store/r7p7wyqvvqxkdz6p9c5la9fkzxk0ckaa-lutris-usr-target/sbin/bluetoothctl
bluez.out                 /nix/store/h5z7lwsr57mrbkqxrw6m2gqpl7dc2a9f-bluez-5.70/bin/bluetoothctl
bluez5-experimental.out   /nix/store/0a9ilf2yhiylxxz51xdd43j8h5vgccv1-bluez-5.70/bin/bluetoothctl

I guess they are dependencies of some service or other package.

It would be nice to find out which option in my NixOS configuration causes the installation of these dependencies.

Relevant thread: How do i find out why a package is installed?

1 Like