Skip to content

Instantly share code, notes, and snippets.

@infinisil
Last active May 11, 2023 18:55
Show Gist options
  • Save infinisil/4f2bd165c2603fc28ab536f39ac2fd27 to your computer and use it in GitHub Desktop.
Save infinisil/4f2bd165c2603fc28ab536f39ac2fd27 to your computer and use it in GitHub Desktop.
The number of attributes in Nixpkgs that are affected by 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 = [(self: super: {
callPackage = file: args:
let
result = super.callPackage file args;
in
if self.lib.isAttrs result then
result // {
_isCallPackage = true;
}
else
# Currently only an irrelevant mathematica non-top-level call
# builtins.trace "Got a non-attr callPackage for ${toString file}"
result;
})];
};
inherit (pkgs) lib;
processed = map (value:
let
result = value._isCallPackage or false && lib.isDerivation value;
try = builtins.tryEval result;
in
if try.success then
try.value
else
null
) (lib.attrValues pkgs);
evaluate = lib.filter (value: value != null) processed;
evaluateLength = lib.length evaluate;
matching = lib.filter (value: value) evaluate;
matchingLength = lib.length matching;
percentMatching = 100.0 / evaluateLength * matchingLength;
result = builtins.trace ''
Out of ${toString evaluateLength} total non-alias attributes that can be evaluated, ${toString percentMatching}% (${toString matchingLength}) are derivations using `callPackage`
'' null;
in {
inherit result;
}
@infinisil
Copy link
Author

infinisil commented May 11, 2023

Evaluate with

nix-instantiate --eval count.nix -A result

Result:

Out of 17280 total non-alias attributes that can be evaluated, 81.226852% (14036) are derivations using callPackage

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