nixery/popcount
Vincent Ambo 73f0087be2 chore(nixery): Housekeeping for depot compatibility
Cleans up a whole bunch of things I wanted to get out of the door
right away:

* depot internal references to //third_party/nixery have been replaced
  with //tools/nixery
* cleaned up files from Github
* fixed SPDX & Copyright headers
* code formatting and inclusion in //tools/depotfmt checks

Change-Id: Iea79f0fdf3aa04f71741d4f4032f88605ae415bb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5486
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
2022-04-20 15:31:16 +00:00
..
default.nix chore(nixery): Housekeeping for depot compatibility 2022-04-20 15:31:16 +00:00
popcount.go chore(nixery): Housekeeping for depot compatibility 2022-04-20 15:31:16 +00:00
README.md feat(popcount): Clean up popularity counting script 2019-08-14 00:02:04 +01:00

popcount

This script is used to count the popularity for each package in nixpkgs, by determining how many other packages depend on it.

It skips over all packages that fail to build, are not cached or are unfree - but these omissions do not meaningfully affect the statistics.

It currently does not evaluate nested attribute sets (such as haskellPackages).

Usage

  1. Generate a list of all top-level attributes in nixpkgs:

    nix eval '(with builtins; toJSON (attrNames (import <nixpkgs> {})))' | jq -r | jq > all-top-level.json
    
  2. Run ./popcount > all-runtime-deps.txt

  3. Collect and count the results with the following magic incantation:

    cat all-runtime-deps.txt \
      | sed -r 's|/nix/store/[a-z0-9]+-||g' \
      | sort \
      | uniq -c \
      | sort -n -r \
      | awk '{ print "{\"" $2 "\":" $1 "}"}' \
      | jq -c -s '. | add | with_entries(select(.value > 1))' \
      > your-output-file
    

    In essence, this will trim Nix's store paths and hashes from the output, count the occurences of each package and return the output as JSON. All packages that have no references other than themselves are removed from the output.