mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
Add human readable closure sizes to nix path-info
Unfortunately, -h is already taken as a short option by --help, so we have to use a different letter or the capitalized version. Resolves #2363
This commit is contained in:
parent
5e83b0227f
commit
3407a5d936
1 changed files with 27 additions and 2 deletions
|
@ -13,12 +13,14 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||||
{
|
{
|
||||||
bool showSize = false;
|
bool showSize = false;
|
||||||
bool showClosureSize = false;
|
bool showClosureSize = false;
|
||||||
|
bool humanReadable = false;
|
||||||
bool showSigs = false;
|
bool showSigs = false;
|
||||||
|
|
||||||
CmdPathInfo()
|
CmdPathInfo()
|
||||||
{
|
{
|
||||||
mkFlag('s', "size", "print size of the NAR dump of each path", &showSize);
|
mkFlag('s', "size", "print size of the NAR dump of each path", &showSize);
|
||||||
mkFlag('S', "closure-size", "print sum size of the NAR dumps of the closure of each path", &showClosureSize);
|
mkFlag('S', "closure-size", "print sum size of the NAR dumps of the closure of each path", &showClosureSize);
|
||||||
|
mkFlag('H', "human-readable", "with -s and -S, print sizes like 1K 234M 5.67G etc.", &humanReadable);
|
||||||
mkFlag(0, "sigs", "show signatures", &showSigs);
|
mkFlag(0, "sigs", "show signatures", &showSigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +41,10 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||||
"To show the closure sizes of every path in the current NixOS system closure, sorted by size:",
|
"To show the closure sizes of every path in the current NixOS system closure, sorted by size:",
|
||||||
"nix path-info -rS /run/current-system | sort -nk2"
|
"nix path-info -rS /run/current-system | sort -nk2"
|
||||||
},
|
},
|
||||||
|
Example{
|
||||||
|
"To show a package's closure size and all its dependencies with human readable sizes:",
|
||||||
|
"nix path-info -rsSH nixpkgs.rust"
|
||||||
|
},
|
||||||
Example{
|
Example{
|
||||||
"To check the existence of a path in a binary cache:",
|
"To check the existence of a path in a binary cache:",
|
||||||
"nix path-info -r /nix/store/7qvk5c91...-geeqie-1.1 --store https://cache.nixos.org/"
|
"nix path-info -r /nix/store/7qvk5c91...-geeqie-1.1 --store https://cache.nixos.org/"
|
||||||
|
@ -58,6 +64,25 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printSize(int value)
|
||||||
|
{
|
||||||
|
if (!humanReadable) {
|
||||||
|
std::cout << '\t' << std::setw(11) << value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr std::array<char, 6> idents = {
|
||||||
|
' ', 'K', 'M', 'G', 'T', 'P'
|
||||||
|
};
|
||||||
|
size_t power = 0;
|
||||||
|
double res = value;
|
||||||
|
while (res > 1024) {
|
||||||
|
++power;
|
||||||
|
res /= 1024;
|
||||||
|
}
|
||||||
|
std::cout << '\t' << std::setw(11) << std::setprecision(3) << res << idents[power];
|
||||||
|
}
|
||||||
|
|
||||||
void run(ref<Store> store, Paths storePaths) override
|
void run(ref<Store> store, Paths storePaths) override
|
||||||
{
|
{
|
||||||
size_t pathLen = 0;
|
size_t pathLen = 0;
|
||||||
|
@ -81,10 +106,10 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
||||||
std::cout << storePath << std::string(std::max(0, (int) pathLen - (int) storePath.size()), ' ');
|
std::cout << storePath << std::string(std::max(0, (int) pathLen - (int) storePath.size()), ' ');
|
||||||
|
|
||||||
if (showSize)
|
if (showSize)
|
||||||
std::cout << '\t' << std::setw(11) << info->narSize;
|
printSize(info->narSize);
|
||||||
|
|
||||||
if (showClosureSize)
|
if (showClosureSize)
|
||||||
std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath).first;
|
printSize(store->getClosureSize(storePath).first);
|
||||||
|
|
||||||
if (showSigs) {
|
if (showSigs) {
|
||||||
std::cout << '\t';
|
std::cout << '\t';
|
||||||
|
|
Loading…
Reference in a new issue