Skip to content

Instantly share code, notes, and snippets.

@infinisil
Created May 11, 2023 20:12
Show Gist options
  • Save infinisil/95c7013db62e9f23ab2bc92165a37221 to your computer and use it in GitHub Desktop.
Save infinisil/95c7013db62e9f23ab2bc92165a37221 to your computer and use it in GitHub Desktop.
Distribution of shards in Nixpkgs for RFC 140
{
system ? builtins.currentSystem,
nixpkgs ? fetchTarball {
url = "https://github.com/NixOS/nixpkgs/tarball/6948ef4deff7a72ebe5242244bd3730e8542b925";
sha256 = "1fw8vlbcxr3kw96rrjlw94zhbjs3a32dcnvav19cvniwlbhf2jsh";
},
}:
let
pkgs = import nixpkgs {
inherit system;
config.allowAliases = false;
overlays = [];
};
inherit (pkgs) lib;
set = pkgs;
names = lib.attrNames set;
attributeCount = lib.length names;
grouped = lib.groupBy (name:
lib.toLower (lib.substring 0 2 name)
) names;
distribution = lib.sort (a: b: a.count < b.count)
(lib.mapAttrsToList (name: values: {
inherit name;
count = lib.length values;
}) grouped);
shardCount = lib.length distribution;
top20 = lib.drop (shardCount - 20) distribution;
result =
builtins.trace "Attribute count: ${toString attributeCount}"
builtins.trace "Shard count: ${toString shardCount}"
builtins.trace "Top 20"
(lib.foldl' (acc: el:
builtins.trace "${el.name}: ${toString el.count}" acc
) null top20);
in {
inherit result;
}
@infinisil
Copy link
Author

$ nix-instantiate --eval eval.nix -A result
trace: Attribute count: 17305
trace: Shard count: 726
trace: Top 20
trace: gr: 121
trace: do: 133
trace: mi: 133
trace: gn: 137
trace: ne: 139
trace: po: 143
trace: st: 144
trace: mo: 149
trace: cl: 161
trace: re: 166
trace: gi: 172
trace: pa: 184
trace: te: 184
trace: go: 210
trace: pr: 217
trace: ca: 243
trace: ma: 244
trace: co: 252
trace: op: 260
trace: li: 1092
null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment