mirror of
https://github.com/NixOS/nix.git
synced 2025-04-16 14:19:21 +00:00
Merge 55b691b2e4
into 0e1323c041
This commit is contained in:
commit
88e5122784
34
src/nix/flake-root.md
Normal file
34
src/nix/flake-root.md
Normal file
@ -0,0 +1,34 @@
|
||||
R""(
|
||||
|
||||
# Limitations
|
||||
- This subcommand doesn't support codebases that keep the flake.nix in a subdirectory.
|
||||
|
||||
# Examples
|
||||
|
||||
* Get the root folder of a codebase with the shell in folder /path/to/folder and flake.nix in /path/to:
|
||||
|
||||
```console
|
||||
/path/to/folder$ nix flake root
|
||||
/path/to
|
||||
|
||||
/path/to/folder$ nix flake root -r
|
||||
path:/tmp/eoq
|
||||
```
|
||||
|
||||
* Get the root folder of a codebase with the shell in folder /path/to/folder, a flake.nix in /path/to and a git repo initialized
|
||||
|
||||
```console
|
||||
/path/to/folder$ nix flake root
|
||||
/path/to
|
||||
|
||||
/path/to/folder$ nix flake root -r
|
||||
git+file:///path/to
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command uses the logic used to find flake.nix for commands
|
||||
such as `nix build` and shows the absolute path, or optionally,
|
||||
the flake reference.
|
||||
|
||||
)""
|
@ -1514,6 +1514,46 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdFlakeRoot : FlakeCommand
|
||||
{
|
||||
bool asRef = true;
|
||||
CmdFlakeRoot()
|
||||
{
|
||||
addFlag({
|
||||
.longName = "as-ref",
|
||||
.shortName = 'r',
|
||||
.description = "Show the root as a flakeref in URL-like representation.",
|
||||
.handler = {&asRef, false}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "get the root directory of a flake";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "flake-root.md"
|
||||
;
|
||||
}
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
{
|
||||
std::string rootRef = getFlakeRef().to_string();
|
||||
if (asRef) {
|
||||
int slashIndex = rootRef.find('/');
|
||||
while (rootRef[slashIndex + 1] == '/') {
|
||||
slashIndex++;
|
||||
}
|
||||
rootRef = rootRef.substr(slashIndex);
|
||||
}
|
||||
std::cout << rootRef << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CmdFlake : NixMultiCommand
|
||||
{
|
||||
CmdFlake()
|
||||
@ -1531,6 +1571,7 @@ struct CmdFlake : NixMultiCommand
|
||||
{"archive", []() { return make_ref<CmdFlakeArchive>(); }},
|
||||
{"show", []() { return make_ref<CmdFlakeShow>(); }},
|
||||
{"prefetch", []() { return make_ref<CmdFlakePrefetch>(); }},
|
||||
{"root", []() { return make_ref<CmdFlakeRoot>(); }},
|
||||
})
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user