libmacchina icon indicating copy to clipboard operation
libmacchina copied to clipboard

Add nix package count

Open Gobidev opened this issue 2 years ago • 5 comments
trafficstars

closes #120

This PR adds nix package count. It works by counting the amount of directories in /nix/store/ and filtering out the ones that don't have a version number in their package name. This value differs from running nix-store -q --requisites /run/current-system/sw | wc -l and nix-store -q --requisites ~/.nix-profile | wc -l and adding the values (method used by other fetch utilities) because the directory also contains packages that are not counted by nix-store -q. However, spawning the commands is not an option as they both take around .3s to execute which is way longer than all other readouts combined take to run. This is the best alternative I could find.

To get an idea of how much they differ, here are some numbers:

System Method Amount
non-NixOS nix-store -q ... 14
libmacchina 56
NixOS nix-store -q ... 936
libmacchina 1235

I also simplified the count_snap function by replacing the if let ... return with map()

Gobidev avatar Mar 21 '23 17:03 Gobidev

As long as the numbers are accurate, this looks like a neat solution. I kinda sorta wish more package managers kept a little SQLite database like rpm does, it makes things simple.

grtcdr avatar Mar 22 '23 13:03 grtcdr

Yea it would be nice to have something like that, I looked through nix source code for a while and tried to figure out how their method works but it seemed to complicated to replicate.

Gobidev avatar Mar 22 '23 13:03 Gobidev

This doesn't look like it's discounting duplicates, which means that, for example, two bash entries in /nix/store are viewed as two distinct packages. I presume this is what makes the nix implementation complex. In any case, we should try to match their counting mechanism in order to report correct information.

grtcdr avatar Mar 22 '23 16:03 grtcdr

Sounds good, I will try to replicate the count method of nix-store when I have more time. Btw, can you make a release in the near future? It would be nice to have easy access to the features of the past few months.

Gobidev avatar Mar 22 '23 18:03 Gobidev

Sure thing, I'll get to that tomorrow.

grtcdr avatar Mar 23 '23 22:03 grtcdr

See #172

Gobidev avatar Jun 15 '24 13:06 Gobidev