diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-01-10 23:20:02 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-01-10 23:29:14 +0100 |
commit | fdcd62eec59485665b919c048874de05235b5971 (patch) | |
tree | 426979f3aef57fa692299a4933fac7f5bc4c5ee4 /src/nix/store-gc.cc | |
parent | e21aee58f6dd7785df50d5d2a473feb5f6b2ed4f (diff) |
Add 'nix store gc' command
Diffstat (limited to 'src/nix/store-gc.cc')
-rw-r--r-- | src/nix/store-gc.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nix/store-gc.cc b/src/nix/store-gc.cc new file mode 100644 index 000000000..6e9607d03 --- /dev/null +++ b/src/nix/store-gc.cc @@ -0,0 +1,43 @@ +#include "command.hh" +#include "common-args.hh" +#include "shared.hh" +#include "store-api.hh" + +using namespace nix; + +struct CmdStoreGC : StoreCommand, MixDryRun +{ + GCOptions options; + + CmdStoreGC() + { + addFlag({ + .longName = "max", + .description = "stop after freeing `n` bytes of disk space", + .labels = {"n"}, + .handler = {&options.maxFreed} + }); + } + + std::string description() override + { + return "perform garbage collection on a Nix store"; + } + + std::string doc() override + { + return + #include "store-gc.md" + ; + } + + void run(ref<Store> store) override + { + options.action = dryRun ? GCOptions::gcReturnDead : GCOptions::gcDeleteDead; + GCResults results; + PrintFreed freed(options.action == GCOptions::gcDeleteDead, results); + store->collectGarbage(options, results); + } +}; + +static auto rCmdStoreGC = registerCommand2<CmdStoreGC>({"store", "gc"}); |