mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
Add 'nix store gc' command
This commit is contained in:
parent
e21aee58f6
commit
fdcd62eec5
3 changed files with 67 additions and 3 deletions
43
src/nix/store-gc.cc
Normal file
43
src/nix/store-gc.cc
Normal file
|
@ -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"});
|
21
src/nix/store-gc.md
Normal file
21
src/nix/store-gc.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Delete unreachable paths in the Nix store:
|
||||
|
||||
```console
|
||||
# nix store gc
|
||||
```
|
||||
|
||||
* Delete up to 1 gigabyte of garbage:
|
||||
|
||||
```console
|
||||
# nix store gc --max 1G
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command deletes unreachable paths in the Nix store.
|
||||
|
||||
)""
|
Loading…
Add table
Add a link
Reference in a new issue