mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
nix path-info: Add
Forgot to commit this earlier...
This commit is contained in:
parent
69e3ffb076
commit
1a71495273
1 changed files with 75 additions and 0 deletions
75
src/nix/path-info.cc
Normal file
75
src/nix/path-info.cc
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
#include "command.hh"
|
||||||
|
#include "progress-bar.hh"
|
||||||
|
#include "shared.hh"
|
||||||
|
#include "store-api.hh"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
struct CmdPathInfo : StorePathsCommand
|
||||||
|
{
|
||||||
|
bool showSize = false;
|
||||||
|
bool showClosureSize = false;
|
||||||
|
|
||||||
|
CmdPathInfo()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name() override
|
||||||
|
{
|
||||||
|
return "path-info";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string description() override
|
||||||
|
{
|
||||||
|
return "query information about store paths";
|
||||||
|
}
|
||||||
|
|
||||||
|
Examples examples() override
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
Example{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
Example{
|
||||||
|
"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/"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void run(ref<Store> store, Paths storePaths) override
|
||||||
|
{
|
||||||
|
size_t pathLen = 0;
|
||||||
|
for (auto & storePath : storePaths)
|
||||||
|
pathLen = std::max(pathLen, storePath.size());
|
||||||
|
|
||||||
|
for (auto & storePath : storePaths) {
|
||||||
|
if (!store->isValidPath(storePath))
|
||||||
|
throw Error(format("path ‘%s’ is not valid") % storePath);
|
||||||
|
|
||||||
|
std::cout << storePath << std::string(pathLen - storePath.size(), ' ');
|
||||||
|
|
||||||
|
if (showSize) {
|
||||||
|
std::cout << '\t' << std::setw(11) << store->queryPathInfo(storePath)->narSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showClosureSize) {
|
||||||
|
size_t totalSize = 0;
|
||||||
|
PathSet closure;
|
||||||
|
store->computeFSClosure(storePath, closure, false, false);
|
||||||
|
for (auto & p : closure)
|
||||||
|
totalSize += store->queryPathInfo(p)->narSize;
|
||||||
|
std::cout << '\t' << std::setw(11) << totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static RegisterCommand r1(make_ref<CmdPathInfo>());
|
Loading…
Reference in a new issue