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

Add nix package count #150

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

Gobidev
Copy link
Contributor

@Gobidev Gobidev commented Mar 21, 2023

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()

@grtcdr
Copy link
Member

grtcdr commented Mar 22, 2023

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.

@Gobidev
Copy link
Contributor Author

Gobidev commented Mar 22, 2023

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.

@grtcdr
Copy link
Member

grtcdr commented Mar 22, 2023

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.

@Gobidev Gobidev marked this pull request as draft March 22, 2023 17:11
@Gobidev
Copy link
Contributor Author

Gobidev commented Mar 22, 2023

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.

@grtcdr
Copy link
Member

grtcdr commented Mar 23, 2023

Sure thing, I'll get to that tomorrow.

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

Successfully merging this pull request may close these issues.

[FEATURE] Support nix as a package manager
2 participants