aboutsummaryrefslogtreecommitdiff
path: root/src/nix/run.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 20:35:11 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 21:51:05 +0000
commitca0994819d68aee26a2906c37a47ae609ac46c4c (patch)
treec96805c008c22926b1eaadc340a99323d53be532 /src/nix/run.cc
parent10e81bf871551901ff0383bdede0f79325e93867 (diff)
parentc189031e8be0530d73a817571ad7f81ad5eedce6 (diff)
Merge remote-tracking branch 'upstream/master' into path-info
Diffstat (limited to 'src/nix/run.cc')
-rw-r--r--src/nix/run.cc66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 790784382..ec9388234 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -22,6 +22,9 @@ std::string chrootHelperName = "__run_in_chroot";
struct RunCommon : virtual Command
{
+
+ using Command::run;
+
void runProgram(ref<Store> store,
const std::string & program,
const Strings & args)
@@ -59,6 +62,9 @@ struct RunCommon : virtual Command
struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
{
+
+ using InstallablesCommand::run;
+
std::vector<std::string> command = { getEnv("SHELL").value_or("bash") };
CmdShell()
@@ -66,7 +72,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
addFlag({
.longName = "command",
.shortName = 'c',
- .description = "command and arguments to be executed; defaults to '$SHELL'",
+ .description = "Command and arguments to be executed, defaulting to `$SHELL`",
.labels = {"command", "args"},
.handler = {[&](std::vector<std::string> ss) {
if (ss.empty()) throw UsageError("--command requires at least one argument");
@@ -80,26 +86,11 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
return "run a shell in which the specified packages are available";
}
- Examples examples() override
+ std::string doc() override
{
- return {
- Example{
- "To start a shell providing GNU Hello from NixOS 20.03:",
- "nix shell nixpkgs/nixos-20.03#hello"
- },
- Example{
- "To start a shell providing youtube-dl from your 'nixpkgs' channel:",
- "nix shell nixpkgs#youtube-dl"
- },
- Example{
- "To run GNU Hello:",
- "nix shell nixpkgs#hello -c hello --greeting 'Hi everybody!'"
- },
- Example{
- "To run GNU Hello in a chroot store:",
- "nix shell --store ~/my-nix nixpkgs#hello -c hello"
- },
- };
+ return
+ #include "shell.md"
+ ;
}
void run(ref<Store> store) override
@@ -144,6 +135,8 @@ static auto rCmdShell = registerCommand<CmdShell>("shell");
struct CmdRun : InstallableCommand, RunCommon
{
+ using InstallableCommand::run;
+
std::vector<std::string> args;
CmdRun()
@@ -160,22 +153,11 @@ struct CmdRun : InstallableCommand, RunCommon
return "run a Nix application";
}
- Examples examples() override
+ std::string doc() override
{
- return {
- Example{
- "To run Blender:",
- "nix run blender-bin"
- },
- Example{
- "To run vim from nixpkgs:",
- "nix run nixpkgs#vim"
- },
- Example{
- "To run vim from nixpkgs with arguments:",
- "nix run nixpkgs#vim -- --help"
- },
- };
+ return
+ #include "run.md"
+ ;
}
Strings getDefaultFlakeAttrPaths() override
@@ -250,14 +232,16 @@ void chrootHelper(int argc, char * * argv)
for (auto entry : readDirectory("/")) {
auto src = "/" + entry.name;
- auto st = lstat(src);
- if (!S_ISDIR(st.st_mode)) continue;
Path dst = tmpDir + "/" + entry.name;
if (pathExists(dst)) continue;
- if (mkdir(dst.c_str(), 0700) == -1)
- throw SysError("creating directory '%s'", dst);
- if (mount(src.c_str(), dst.c_str(), "", MS_BIND | MS_REC, 0) == -1)
- throw SysError("mounting '%s' on '%s'", src, dst);
+ auto st = lstat(src);
+ if (S_ISDIR(st.st_mode)) {
+ if (mkdir(dst.c_str(), 0700) == -1)
+ throw SysError("creating directory '%s'", dst);
+ if (mount(src.c_str(), dst.c_str(), "", MS_BIND | MS_REC, 0) == -1)
+ throw SysError("mounting '%s' on '%s'", src, dst);
+ } else if (S_ISLNK(st.st_mode))
+ createSymlink(readLink(src), dst);
}
char * cwd = getcwd(0, 0);