News for hackers. Stuff that matters.
Re:Nix journey part 0: Learning and reference materials by peter_l_downs on Wednesday March 01, 2023 @05:10PM (#34989044)
The nix package search website is OK, but it doesn't let you filter by the names of installed binaries. A lot of the time, you have a question like "what nixpkgs attribute do i install in order to get the `python3` command". I recently wrote a command line tool that allows you to do this. It uses the same elasticsearch index as the search website, but allows more powerful filtering. If anyone is thinking of getting into nix, please consider trying it out!

https://github.com/peterldowns/nix-search-cli

Re:Nix journey part 0: Learning and reference materials by zach_mitchell on Wednesday March 01, 2023 @05:28PM (#34989221)
I've also noticed this. If you install `rustc` it says that you get `rust-gdb`, but that's really just a wrapper script around `gdb`, which it doesn't install.
Re:Nix journey part 0: Learning and reference materials by thomastjeffery on Wednesday March 01, 2023 @06:11PM (#34989657)
And vice versa. It's tricky to know what the binary will actually be named.

I have had to look directly in the /nix/store enough times that I lost count.

[dead]
Re:Nix journey part 0: Learning and reference materials by thomastjeffery on Monday March 06, 2023 @01:22PM (#35045217)
It would be trivial to print the contents of the nix store that package uses.

It would be pretty straightforward to show only what ends up in the path.

Re:Nix journey part 0: Learning and reference materials by OmarAssadi on Wednesday March 01, 2023 @07:01PM (#34990135)
Cool!

I love Nix, but really am not a fan of the Nix package listing website. So, it is nice to see.

And I guess worth mentioning, but if you or anyone else is ever feeling a little less lazy than me and want to add more available metadata, some of my main gripes with the official site:

- No easy way to see dependencies without viewing the package derivation source code.

- No easy way to see "reverse" dependencies, period, as far as I am aware, short of basically grepping the entire nixpkgs repo, and even then you won't get a totally accurate answer.

This seems like it'd be awful to implement given I don't think you can realistically know this information without evaluating the entirety of `all-packages.nix`. But it is something I miss about stuff like Arch Linux's package website. And I think in some ways, it is even more important with stuff like Nix if you intend to override a particular package globally, since you may end up needing to rebuild god knows how many things as a result.

- No easy way to filter by package types, outside of the very small set of existing package sets (e.g., `vimPackages`, `mpvScripts, etc).

As an example, I'd really like to be able to see all font packages in the nixpkgs repo, but there's just no nice way to do this easily, unlike some other package managers. It would be another kind of awful feature to implement, since there is not currently any grouping that I am aware of.

You /can/ kind of grep the `all-packages.nix` file and get a rough idea by searching for what packages call `./data/fonts`, but actually parsing that is pretty rough, since not everything is as simple as `font-name = callPackage ./data/fonts/font-name {};`

A good example of that parsing annoyance would be the noto-fonts [1].

- No easy way to see build options. For example, packages like `mpv` or `ffmpeg_5` have loads of different feature flags, some of which are unexpectedly disabled or enabled.

Again, I think this would be not fun to implement. But it is something that I think Gentoo gets really right with the listing of 'use flags' on their package listings [2] (in fact, Gentoo's site kind of gets everything right; it feels like the gold standard to me). NetBSD/pkgsrc is another one of the few that does well, albeit with a less-fancy design [3].

[1]: <https://github.com/NixOS/nixpkgs/blob/96c0fdeb6accc9f76f1887...>

[2]: <https://packages.gentoo.org/packages/media-video/ffmpeg>

[3]: <https://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/multimedia/...>

Re:Nix journey part 0: Learning and reference materials by peter_l_downs on Wednesday March 01, 2023 @07:23PM (#34990317)
You may want to submit this feedback as an issue to the nixos-search repository, where they have the indexing code and website interface. I have no idea who is in charge of Nix stuff and I find it all horrible to use, totally agreed with you that all basic package manager things you'd want to be able to do are impossible today with nix.

https://github.com/NixOS/nixos-search

Re:Nix journey part 0: Learning and reference materials by ghostwriter on Thursday March 02, 2023 @06:31AM (#34994538)
> No easy way to see dependencies without viewing the package derivation source code.

nix-store -qR `which python`

> No easy way to see "reverse" dependencies, period, as far as I am aware, short of basically grepping the entire nixpkgs repo, and even then you won't get a totally accurate answer.

nix-store -q --referrers `which python`

This and many other querying commands are explained in the Command Reference of Nix manual. Have you read it? [1]

[1] https://nixos.org/manual/nix/stable/command-ref/nix-store.ht...

Re:Nix journey part 0: Learning and reference materials by aidenn0 on Wednesday March 01, 2023 @07:11PM (#34990210)
I've used nix-index to answer this question:

         $ nix-locate --top-level /bin/python3
    remarkable2-toolchain.out                             0 s /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/bin/python3
    remarkable2-toolchain.out                             0 s /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/bin/python3-config
    remarkable2-toolchain.out                         5,544 x /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8
    remarkable2-toolchain.out                             0 s /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8-config
    remarkable2-toolchain.out                         2,114 x /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8-config-lib
    remarkable2-toolchain.out                             0 s /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3
    remarkable2-toolchain.out                           306 x /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3.8
    remarkable2-toolchain.out                        18,432 x /nix/store/lygxp772hm743v33wbri22f2k78k1vsb-remarkable2-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3.8.real
    remarkable-toolchain.out                              0 s /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/bin/python3
    remarkable-toolchain.out                              0 s /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/bin/python3-config
    remarkable-toolchain.out                          5,544 x /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8
    remarkable-toolchain.out                              0 s /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8-config
    remarkable-toolchain.out                          2,114 x /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi/usr/bin/python3.8-config-lib
    remarkable-toolchain.out                              0 s /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3
    remarkable-toolchain.out                            306 x /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3.8
    remarkable-toolchain.out                         18,432 x /nix/store/qk2p0ahd3nndi2zlwm9d0psahlrpikm0-remarkable-toolchain-3.1.2/sysroots/x86_64-codexsdk-linux/usr/bin/python3.8.real
    qtile.out                                        15,872 x /nix/store/mrpll8c98mvnnzab5znqawz56dvq841j-qtile-0.22.1/bin/python3
    qtile.out                                        15,872 x /nix/store/mrpll8c98mvnnzab5znqawz56dvq841j-qtile-0.22.1/bin/python3-config
    qtile.out                                        15,872 x /nix/store/mrpll8c98mvnnzab5znqawz56dvq841j-qtile-0.22.1/bin/python3.10
    qtile.out                                        15,872 x /nix/store/mrpll8c98mvnnzab5znqawz56dvq841j-qtile-0.22.1/bin/python3.10-config
    python3Minimal.out                                    0 s /nix/store/igdcckxrd115041zvvcqmw9qxwf6pfxv-python3-minimal-3.10.8/bin/python3
    python3Minimal.out                               15,616 x /nix/store/igdcckxrd115041zvvcqmw9qxwf6pfxv-python3-minimal-3.10.8/bin/python3.10
    python311.out                                         0 s /nix/store/ipaj21xdmnw2f2bs9mcd7czkzhdhbcfv-python3-3.11.1/bin/python3
    python311.out                                         0 s /nix/store/ipaj21xdmnw2f2bs9mcd7czkzhdhbcfv-python3-3.11.1/bin/python3-config
    python311.out                                    15,616 x /nix/store/ipaj21xdmnw2f2bs9mcd7czkzhdhbcfv-python3-3.11.1/bin/python3.11
    python311.out                                     3,404 x /nix/store/ipaj21xdmnw2f2bs9mcd7czkzhdhbcfv-python3-3.11.1/bin/python3.11-config
    python38.out                                          0 s /nix/store/n3ma7kwpssmwlgv118pc6k5ia0splp2m-python3-3.8.16/bin/python3
    python38.out                                          0 s /nix/store/n3ma7kwpssmwlgv118pc6k5ia0splp2m-python3-3.8.16/bin/python3-config
    python38.out                                     15,616 x /nix/store/n3ma7kwpssmwlgv118pc6k5ia0splp2m-python3-3.8.16/bin/python3.8
    python38.out                                      3,444 x /nix/store/n3ma7kwpssmwlgv118pc6k5ia0splp2m-python3-3.8.16/bin/python3.8-config
    python37.out                                          0 s /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3
    python37.out                                          0 s /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3-config
    python37.out                                     15,616 x /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3.7
    python37.out                                          0 s /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3.7-config
    python37.out                                     15,616 x /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3.7m
    python37.out                                      3,210 x /nix/store/a1gzdpyn8bbp192cavnxl6sa3snjx563-python3-3.7.16/bin/python3.7m-config
    python3Full.out                                       0 s /nix/store/rf7mdhqwpfzj239ylwim4rfqhw4fz52h-python3-3.10.8/bin/python3
    python3Full.out                                       0 s /nix/store/rf7mdhqwpfzj239ylwim4rfqhw4fz52h-python3-3.10.8/bin/python3-config
    python3Full.out                                  15,616 x /nix/store/rf7mdhqwpfzj239ylwim4rfqhw4fz52h-python3-3.10.8/bin/python3.10
    python3Full.out                                   3,447 x /nix/store/rf7mdhqwpfzj239ylwim4rfqhw4fz52h-python3-3.10.8/bin/python3.10-config
    python38Full.out                                      0 s /nix/store/b5yxnf8vq4rdkbz1z8wydhcxz3r1zsg7-python3-3.8.16/bin/python3
    python38Full.out                                      0 s /nix/store/b5yxnf8vq4rdkbz1z8wydhcxz3r1zsg7-python3-3.8.16/bin/python3-config
    python38Full.out                                 15,616 x /nix/store/b5yxnf8vq4rdkbz1z8wydhcxz3r1zsg7-python3-3.8.16/bin/python3.8
    python38Full.out                                  3,444 x /nix/store/b5yxnf8vq4rdkbz1z8wydhcxz3r1zsg7-python3-3.8.16/bin/python3.8-config
    sourcehut.python.out                                  0 s /nix/store/lbn7f0d2k36i4bgfdrjdwj7npy3r3h5d-python3-3.10.8/bin/python3
    sourcehut.python.out                                  0 s /nix/store/lbn7f0d2k36i4bgfdrjdwj7npy3r3h5d-python3-3.10.8/bin/python3-config
    sourcehut.python.out                             15,616 x /nix/store/lbn7f0d2k36i4bgfdrjdwj7npy3r3h5d-python3-3.10.8/bin/python3.10
    sourcehut.python.out                              3,447 x /nix/store/lbn7f0d2k36i4bgfdrjdwj7npy3r3h5d-python3-3.10.8/bin/python3.10-config
    python39Full.out                                      0 s /nix/store/ckxlmknrfn6c55jwnw86ha9440w4a9ff-python3-3.9.15/bin/python3
    python39Full.out                                      0 s /nix/store/ckxlmknrfn6c55jwnw86ha9440w4a9ff-python3-3.9.15/bin/python3-config
    python39Full.out                                 15,616 x /nix/store/ckxlmknrfn6c55jwnw86ha9440w4a9ff-python3-3.9.15/bin/python3.9
    python39Full.out                                  3,444 x /nix/store/ckxlmknrfn6c55jwnw86ha9440w4a9ff-python3-3.9.15/bin/python3.9-config
    python39.out                                          0 s /nix/store/hm6bqikghylrwgvqd42lgghjdq9p3hac-python3-3.9.15/bin/python3
    python39.out                                          0 s /nix/store/hm6bqikghylrwgvqd42lgghjdq9p3hac-python3-3.9.15/bin/python3-config
    python39.out                                     15,616 x /nix/store/hm6bqikghylrwgvqd42lgghjdq9p3hac-python3-3.9.15/bin/python3.9
    python39.out                                      3,444 x /nix/store/hm6bqikghylrwgvqd42lgghjdq9p3hac-python3-3.9.15/bin/python3.9-config
    python37Full.out                                      0 s /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3
    python37Full.out                                      0 s /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3-config
    python37Full.out                                 15,616 x /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3.7
    python37Full.out                                      0 s /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3.7-config
    python37Full.out                                 15,616 x /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3.7m
    python37Full.out                                  3,210 x /nix/store/ys4my3x7wwb6r6mwfkyk6q9pay2jm3dz-python3-3.7.16/bin/python3.7m-config
    ihaskell.out                                        294 x /nix/store/yj8p9gd2irrh0z16d3b0ljv4vps920h7-ihaskell-with-packages/bin/python3
    ihaskell.out                                        301 x /nix/store/yj8p9gd2irrh0z16d3b0ljv4vps920h7-ihaskell-with-packages/bin/python3-config
    ihaskell.out                                        297 x /nix/store/yj8p9gd2irrh0z16d3b0ljv4vps920h7-ihaskell-with-packages/bin/python3.10
    ihaskell.out                                        304 x /nix/store/yj8p9gd2irrh0z16d3b0ljv4vps920h7-ihaskell-with-packages/bin/python3.10-config
    google-cloud-sdk.out                             20,744 x /nix/store/7dw9fdkqs25fiwzq3r2z1y21gc97c8wd-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3
    google-cloud-sdk.out                              3,254 x /nix/store/7dw9fdkqs25fiwzq3r2z1y21gc97c8wd-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3-config
    google-cloud-sdk.out                             20,744 x /nix/store/7dw9fdkqs25fiwzq3r2z1y21gc97c8wd-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3.9
    google-cloud-sdk.out                              3,254 x /nix/store/7dw9fdkqs25fiwzq3r2z1y21gc97c8wd-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3.9-config
    google-cloud-sdk-gce.out                         20,744 x /nix/store/b96rpkxpw920sbbswz1xrrrpjdb1f30c-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3
    google-cloud-sdk-gce.out                          3,254 x /nix/store/b96rpkxpw920sbbswz1xrrrpjdb1f30c-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3-config
    google-cloud-sdk-gce.out                         20,744 x /nix/store/b96rpkxpw920sbbswz1xrrrpjdb1f30c-google-cloud-sdk-408.0.1/google-cloud-sdk/platform/bundledpythonunix/bin/python3.9
    google-cloud-sdk-gce.out                          3,254 x
Re:Nix journey part 0: Learning and reference materials by aidenn0 on Wednesday March 01, 2023 @07:18PM (#34990269)
Previous comment is getting long, but if you want to get rid of things like "googlecloud-sdk/platform/bundledpythonunix/bin" you can use:

    nix-locate --top-level --regex '^/bin/python3'
Which will only show packages with "/bin/python3" in the root.

Most of the time this is unnecessary, but since python gets vendored in a lot of packages, it comes up with this example.

Re:Nix journey part 0: Learning and reference materials by peter_l_downs on Wednesday March 01, 2023 @07:21PM (#34990299)
I can't tell if you're joking, but I'm not sure how these results told you anything. I find nix-index and nix-locate entirely unusable.
Re:Nix journey part 0: Learning and reference materials by aidenn0 on Wednesday March 01, 2023 @07:24PM (#34990323)
Not joking, I just scan through the first column. If you want to not have to do so, adding -1 cleans it up:

    $ nix-locate --top-level -1 --regex '^/bin/python3'
    qtile.out
    python3Minimal.out
    python311.out
    python38.out
    python37.out
    python3Full.out
    python38Full.out
    sourcehut.python.out
    python39Full.out
    python39.out
    python37Full.out
    ihaskell.out
Also things like "python3" and "gcc" and such are going to show way more hits than, for example, "firefox":

    $ nix-locate --top-level -1 --regex '^/bin/firefox'
    firefox-esr-102-unwrapped.out
    firefox_decrypt.out
    firefox-unwrapped.out
    firefox.out
Re:Nix journey part 0: Learning and reference materials by aidenn0 on Wednesday March 01, 2023 @08:01PM (#34990588)
Here, I made a short shell script to show all the results with package descriptions (requires enabling the "nix" command):

    #!/bin/sh
    results="$(nix-locate -1 --regex --top-level "^/bin/${1}\$")"
    for item in $results; do
        nix search "nixpkgs#${item%.*}"
    done
Example:

    $ ./nix-find-executable.sh python3
    * legacyPackages.x86_64-linux.qtile (0.22.1)
      A small, flexible, scriptable tiling window manager written in Python
    * legacyPackages.x86_64-linux.python3Minimal (3.10.8)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python311 (3.11.1)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python38 (3.8.16)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python37 (3.7.16)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python3Full (3.10.8)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python38Full (3.8.16)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.sourcehut.python (3.10.8)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python39Full (3.9.15)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python39 (3.9.15)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.python37Full (3.7.16)
      A high-level dynamically-typed programming language
    * legacyPackages.x86_64-linux.ihaskell
Re:Nix journey part 0: Learning and reference materials by Valodim on Wednesday March 01, 2023 @07:17PM (#34990258)
Relatedly, check out comma. It's basically a shortcut prefix command that will search packages for the binary you want to run (via nix-index), and gives you an interactive choice if there are multiple. Which package was drill in again? No matter, I'll just prefix a comma :)

https://github.com/nix-community/comma

Re:Nix journey part 0: Learning and reference materials by lom on Wednesday March 01, 2023 @08:31PM (#34990791)
nix-locate can also solve that problem
Re:Nix journey part 0: Learning and reference materials by nextos on Wednesday March 01, 2023 @08:50PM (#34990901)
A naive search is even easier. Right now, on NixOS:

   [nextos@local:~]$ python3
   The program 'python3' is not in your PATH. It is provided by several packages.
   You can make it available in an ephemeral shell by typing one of the following:
     nix-shell -p graalvmCEPackages.graalvm11-ce-full
     nix-shell -p graalvmCEPackages.graalvm17-ce-full
     nix-shell -p graalvmCEPackages.python-installable-svm-java11
     nix-shell -p graalvmCEPackages.python-installable-svm-java17
     nix-shell -p ihaskell
     nix-shell -p python311
     nix-shell -p python311Full
     nix-shell -p python312
     nix-shell -p python38
     nix-shell -p python38Full
     nix-shell -p python39
     nix-shell -p python39Full
     nix-shell -p python3Full
     nix-shell -p python3Minimal
     nix-shell -p qtile
     nix-shell -p sourcehut.python
Re:Nix journey part 0: Learning and reference materials by colordrops on Wednesday March 01, 2023 @09:12PM (#34991059)
I have zsh installed and it's not doing this. How does one get it to do this?
Re:Nix journey part 0: Learning and reference materials by jml7c5 on Wednesday March 01, 2023 @09:25PM (#34991146)
Are you using flakes? AFAIK `command-not-found` does not work with them. See https://github.com/NixOS/nixpkgs/issues/171054 and https://discourse.nixos.org/t/why-isnt-there-an-official-bui...

`nix-index` is a flake-compatible alternative: https://github.com/bennofs/nix-index

Re:Nix journey part 0: Learning and reference materials by colordrops on Wednesday March 01, 2023 @10:55PM (#34991804)
I am using flakes, and now I know why `command-not-found` doesn't work, thank you.
Re:Nix journey part 0: Learning and reference materials by pxc on Thursday March 02, 2023 @01:19PM (#34999538)
You can make it work again! It's a one-liner in configuration.nix. Solutions and alternatives were covered in detail in a recent Discourse thread: https://discourse.nixos.org/t/which-package-provides-ifconfi...