mirror of
https://github.com/NixOS/nix
synced 2024-09-19 10:50:24 -04:00
Add an 'add-root' comamnd to manually add indirect roots
This commit is contained in:
parent
48477d4a3e
commit
fee7efbc09
61
src/nix/add-root.cc
Normal file
61
src/nix/add-root.cc
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "command.hh"
|
||||
#include "args.hh"
|
||||
#include "shared.hh"
|
||||
#include "store-cast.hh"
|
||||
#include "indirect-root-store.hh"
|
||||
#include "common-args.hh"
|
||||
#include "strings.hh"
|
||||
#include "installable-derived-path.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
struct CmdAddRoot: StoreCommand
|
||||
{
|
||||
std::vector<std::string> links;
|
||||
bool checkResults = true;
|
||||
|
||||
CmdAddRoot()
|
||||
{
|
||||
expectArgs({
|
||||
.label = "indirect-roots",
|
||||
.handler = {&links},
|
||||
.completer = completePath,
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "Add indirect gc-roots through the symlink arguments";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "add-root.md"
|
||||
;
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto & indirectRootStore = require<IndirectRootStore>(*store);
|
||||
|
||||
for (auto &link: links) {
|
||||
auto indirectPath = absPath(link);
|
||||
if (indirectRootStore.isInStore(indirectPath)) {
|
||||
throw Error("Indirect root '%1%' must not be in the Nix store", link);
|
||||
}
|
||||
|
||||
if (checkResults) {
|
||||
auto path = indirectRootStore.followLinksToStorePath(indirectPath);
|
||||
indirectRootStore.addTempRoot(path);
|
||||
// TODO: ensure the path is safe from concurrent GC of fail.
|
||||
}
|
||||
|
||||
indirectRootStore.addIndirectRoot(indirectPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdAddRoot = registerCommand<CmdAddRoot>("add-root");
|
18
src/nix/add-root.md
Normal file
18
src/nix/add-root.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
```console
|
||||
$ readlink foo
|
||||
/nix/store/xxx
|
||||
$ nix add-root foo
|
||||
$ nix-store -q --roots /nix/store/xxx
|
||||
.../foo -> /nix/store/xxx
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command adds garbage collector root to the paths referenced by the symlinks passed as arguments.
|
||||
These are called indirect roots, as the root will disappear as soon as the intermediate symlink gets deleted.
|
||||
|
||||
)""
|
|
@ -68,6 +68,7 @@ subdir('build-utils-meson/diagnostics')
|
|||
subdir('build-utils-meson/generate-header')
|
||||
|
||||
nix_sources = [config_h] + files(
|
||||
'add-root.cc',
|
||||
'add-to-store.cc',
|
||||
'app.cc',
|
||||
'self-exe.cc',
|
||||
|
|
Loading…
Reference in a new issue