Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard-coded package and option count on search.nixos.org #701

Open
riotbib opened this issue Nov 6, 2023 · 8 comments
Open

Hard-coded package and option count on search.nixos.org #701

riotbib opened this issue Nov 6, 2023 · 8 comments

Comments

@riotbib
Copy link
Member

riotbib commented Nov 6, 2023

The message at the header saying search.nixos.org enables searching of "more than 80 000 packages" is hard-coded. Should be way higher by now, as repology also states.

@Aleksanaa
Copy link
Member

Search more than 100,000 packages! 👍

@Sigmanificient
Copy link
Member

Sigmanificient commented Apr 4, 2024

Here is a small script that retrieve the number of packages from the latest nixpkgs release
It fetches the packages.json from the last item of nixpkgs s3 bucket

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq brotli yq

while [ "$latest" != "null" ]; do
  prev="${latest}"
  latest=$(curl "https://nix-releases.s3.amazonaws.com/?delimiter=/&prefix=nixpkgs/&marker=${latest}" \
    | xq -rMc ".ListBucketResult.CommonPrefixes[-1].Prefix")
  echo "-> $latest"
done

target="${prev%/}"
echo "Selecting latest: $target"
count=$(curl https://releases.nixos.org/${target}/packages.json.br \
  | brotli -d --stdout | jq ".packages | length")

echo "=> $count"

For nixpkgs/nixpkgs-24.05pre606477.e976fa8f49c3 there are 111246 packages available!

For options, it is almost the same script!

--- count-pkgs.sh	2024-04-04 08:04:14.290391078 +0200
+++ count-options.sh	2024-04-04 08:10:17.967651425 +0200
@@ -3,14 +3,14 @@
 
 while [ "$latest" != "null" ]; do
   prev="${latest}"
-  latest=$(curl "https://nix-releases.s3.amazonaws.com/?delimiter=/&prefix=nixpkgs/&marker=${latest}" \
+  latest=$(curl "https://nix-releases.s3.amazonaws.com/?delimiter=/&prefix=nixos/unstable/&marker=${latest}" \
     | xq -rMc ".ListBucketResult.CommonPrefixes[-1].Prefix")
   echo "-> $latest"
 done
 
 target="${prev%/}"
 echo "Selecting latest: $target"
-count=$(curl https://releases.nixos.org/${target}/packages.json.br \
-  | brotli -d --stdout | jq ".packages | length")
+count=$(curl https://releases.nixos.org/${target}/options.json.br \
+  | brotli -d --stdout | jq "length")
 
 echo "=> $count"

Thus, for nixos/unstable/nixos-24.05pre606533.08b9151ed403 there are 18396 options available!

@riotbib
Copy link
Member Author

riotbib commented Apr 16, 2024

Hej @Sigmanificient, nice work! Danke!

You may want to contact the Documentation Team, in case you want to contribute to the code base of search.nixos.org. I'll highlight @fricklerhandwerk and @infinisil of the Docu Team, in case they missed this issue for now.

@Sigmanificient
Copy link
Member

Hej @Sigmanificient, nice work! Danke!

You may want to contact the Documentation Team, in case you want to contribute to the code base of search.nixos.org. I'll highlight @fricklerhandwerk and @infinisil of the Docu Team, in case they missed this issue for now.

I would love to contribute to the website, but unfortunately I don't know anything about elm, and I am unsure on what to exactly do.

I shared the script in case they could help open the discussion, and I would be more than happy if they turned out useful

@infinisil
Copy link
Member

Nah the docs team doesn't have write access to search.nixos.org, that's for the marketing team :)

@riotbib
Copy link
Member Author

riotbib commented Apr 16, 2024

Ah, the infamous NixOS labyrinth, thanks for the insight @infinisil :)

@Sigmanificient
Copy link
Member

Sigmanificient commented Apr 23, 2024

Small update: I found that https://channels.nixos.org/nixos-unstable that already redirects to the latest nixpkgs version, which means I can cut off half of the previous script!

Here is a newer version, that makes way fewer requests, and outputs both packages count and options count in a JSON format

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq brotli

function parse_unstable_json() {
    local url="https://channels.nixos.org/nixos-unstable/$1.json.br"
    echo $(curl -L "$url" | brotli -d --stdout | jq "$2")
}

pkg_count=$(parse_unstable_json "packages" ".packages | length")
opt_count=$(parse_unstable_json "options" "length")

echo "{ 'packages': $pkg_count, 'options': $opt_count }" | tr "'" '"'
{ "packages": 111413, "options": 18524 }

@Sigmanificient
Copy link
Member

This issue should be renamed Hard-coded package and option count on search.nixos.org

@riotbib riotbib changed the title Hard-coded "more than 80 000 packages" Hard-coded package and option count on search.nixos.org Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants