mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
Add 'nix store delete' command
This commit is contained in:
parent
77c9ceda4b
commit
6254b1f5d2
3 changed files with 70 additions and 1 deletions
45
src/nix/store-delete.cc
Normal file
45
src/nix/store-delete.cc
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include "command.hh"
|
||||||
|
#include "common-args.hh"
|
||||||
|
#include "shared.hh"
|
||||||
|
#include "store-api.hh"
|
||||||
|
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
struct CmdStoreDelete : StorePathsCommand
|
||||||
|
{
|
||||||
|
GCOptions options { .action = GCOptions::gcDeleteSpecific };
|
||||||
|
|
||||||
|
CmdStoreDelete()
|
||||||
|
{
|
||||||
|
addFlag({
|
||||||
|
.longName = "ignore-liveness",
|
||||||
|
.description = "do not check whether the paths are reachable from a root",
|
||||||
|
.handler = {&options.ignoreLiveness, true}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string description() override
|
||||||
|
{
|
||||||
|
return "delete paths from the Nix store";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string doc() override
|
||||||
|
{
|
||||||
|
return
|
||||||
|
#include "store-delete.md"
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void run(ref<Store> store, std::vector<StorePath> storePaths) override
|
||||||
|
{
|
||||||
|
|
||||||
|
for (auto & path : storePaths)
|
||||||
|
options.pathsToDelete.insert(path);
|
||||||
|
|
||||||
|
GCResults results;
|
||||||
|
PrintFreed freed(true, results);
|
||||||
|
store->collectGarbage(options, results);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static auto rCmdStoreDelete = registerCommand2<CmdStoreDelete>({"store", "delete"});
|
24
src/nix/store-delete.md
Normal file
24
src/nix/store-delete.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
R""(
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
|
||||||
|
* Delete a specific store path:
|
||||||
|
|
||||||
|
```console
|
||||||
|
# nix store delete /nix/store/yb5q57zxv6hgqql42d5r8b5k5mcq6kay-hello-2.10
|
||||||
|
```
|
||||||
|
|
||||||
|
# Description
|
||||||
|
|
||||||
|
This command deletes the store paths specified by *installables*. ,
|
||||||
|
but only if it is safe to do so; that is, when the path is not
|
||||||
|
reachable from a root of the garbage collector. This means that you
|
||||||
|
can only delete paths that would also be deleted by `nix store
|
||||||
|
gc`. Thus, `nix store delete` is a more targeted version of `nix store
|
||||||
|
gc`.
|
||||||
|
|
||||||
|
With the option `--ignore-liveness`, reachability from the roots is
|
||||||
|
ignored. However, the path still won't be deleted if there are other
|
||||||
|
paths in the store that refer to it (i.e., depend on it).
|
||||||
|
|
||||||
|
)""
|
|
@ -58,7 +58,7 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
|
||||||
|
|
||||||
# Delete one of the outputs and rebuild it. This will cause a hash
|
# Delete one of the outputs and rebuild it. This will cause a hash
|
||||||
# rewrite.
|
# rewrite.
|
||||||
nix-store --delete $TEST_ROOT/result-second --ignore-liveness
|
nix store delete $TEST_ROOT/result-second --ignore-liveness
|
||||||
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
|
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
|
||||||
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
|
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
|
||||||
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
|
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
|
||||||
|
|
Loading…
Reference in a new issue