-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'store add-gc-root' command to manually add indirect roots #11505
Open
layus
wants to merge
4
commits into
NixOS:master
Choose a base branch
from
layus:add-root
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
)"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intuitively I would have expected such as subcommand here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to add it in
nix gc add-root
, butnix gc
seems mostly unused and intended to start a gc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't have a top-level
nix gc
subcommand group, but anix store gc
command.To help keep some consistency between commands, the subcommands are ideally
nix <noun> <verb>
with the exception of a small number of frequently used commands.gc
is a verb, since the "garbage" part is subordinate to the "collect" part (as a noun adjunct to be technical).Since our commands end in verbs, this would create the expectation that
nix gc
is not a subcommand group, but a single action.I think
nix store add-root
would be ok, but perhapsnix store add-gc-root
would be better, as I think the hint about gc would be welcomed when reading scripts that call this command.Interactive use should not be common, because that would usually come after
nix build
, which already produces a root.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who makes final decisions about that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nix team members, I would say. Often happens in those regular meetings.