Add 'nix run' and 'nix shell' manpages
This commit is contained in:
parent
ae7351dbee
commit
09660b8557
|
@ -86,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
|
||||
|
@ -168,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
|
||||
|
|
87
src/nix/run.md
Normal file
87
src/nix/run.md
Normal file
|
@ -0,0 +1,87 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Run the default app from the `blender-bin` flake:
|
||||
|
||||
```console
|
||||
# nix run blender-bin
|
||||
```
|
||||
|
||||
* Run a non-default app from the `blender-bin` flake:
|
||||
|
||||
```console
|
||||
# nix run blender-bin#blender_2_83
|
||||
```
|
||||
|
||||
Tip: you can find apps provided by this flake by running `nix flake
|
||||
show blender-bin`.
|
||||
|
||||
* Run `vim` from the `nixpkgs` flake:
|
||||
|
||||
```console
|
||||
# nix run nixpkgs#vim
|
||||
```
|
||||
|
||||
Note that `vim` (as of the time of writing of this page) is not an
|
||||
app but a package. Thus, Nix runs the eponymous file from the `vim`
|
||||
package.
|
||||
|
||||
* Run `vim` with arguments:
|
||||
|
||||
```console
|
||||
# nix run nixpkgs#vim -- --help
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
`nix run` builds and runs *installable*, which must evaluate to an
|
||||
*app* or a regular Nix derivation.
|
||||
|
||||
If *installable* evaluates to an *app* (see below), it executes the
|
||||
program specified by the app definition.
|
||||
|
||||
If *installable* evaluates to a derivation, it will try to execute the
|
||||
program `<out>/bin/<name>`, where *out* is the primary output store
|
||||
path of the derivation and *name* is the name part of the value of the
|
||||
`name` attribute of the derivation (e.g. if `name` is set to
|
||||
`hello-1.10`, it will run `$out/bin/hello`).
|
||||
|
||||
# Flake output attributes
|
||||
|
||||
If no flake output attribute is given, `nix run` tries the following
|
||||
flake output attributes:
|
||||
|
||||
* `defaultApp.<system>`
|
||||
|
||||
* `defaultPackage.<system>`
|
||||
|
||||
If an attribute *name* is given, `nix run` tries the following flake
|
||||
output attributes:
|
||||
|
||||
* `apps.<system>.<name>`
|
||||
|
||||
* `packages.<system>.<name>`
|
||||
|
||||
* `legacyPackages.<system>.<name>`
|
||||
|
||||
# Apps
|
||||
|
||||
An app is specified by a flake output attribute named
|
||||
`apps.<system>.<name>` or `defaultApp.<system>`. It looks like this:
|
||||
|
||||
```nix
|
||||
apps.x86_64-linux.blender_2_79 = {
|
||||
type = "app";
|
||||
program = "${self.packages.x86_64-linux.blender_2_79}/bin/blender";
|
||||
};
|
||||
```
|
||||
|
||||
The only supported attributes are:
|
||||
|
||||
* `type` (required): Must be set to `app`.
|
||||
|
||||
* `program` (required): The full path of the executable to run. It
|
||||
must reside in the Nix store.
|
||||
|
||||
)""
|
48
src/nix/shell.md
Normal file
48
src/nix/shell.md
Normal file
|
@ -0,0 +1,48 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Start a shell providing `youtube-dl` from the `nixpkgs` flake:
|
||||
|
||||
```console
|
||||
# nix shell nixpkgs#youtube-dl
|
||||
# youtube-dl --version
|
||||
2020.11.01.1
|
||||
```
|
||||
|
||||
* Start a shell providing GNU Hello from NixOS 20.03:
|
||||
|
||||
```console
|
||||
# nix shell nixpkgs/nixos-20.03#hello
|
||||
```
|
||||
|
||||
* Run GNU Hello:
|
||||
|
||||
```console
|
||||
# nix shell nixpkgs#hello -c hello --greeting 'Hi everybody!'
|
||||
Hi everybody!
|
||||
```
|
||||
|
||||
* Run GNU Hello in a chroot store:
|
||||
|
||||
```console
|
||||
# nix shell --store ~/my-nix nixpkgs#hello -c hello
|
||||
```
|
||||
|
||||
* Start a shell providing GNU Hello in a chroot store:
|
||||
|
||||
```console
|
||||
# nix shell --store ~/my-nix nixpkgs#hello nixpkgs#bashInteractive -c bash
|
||||
```
|
||||
|
||||
Note that it's necessary to specify `bash` explicitly because your
|
||||
default shell (e.g. `/bin/bash`) generally will not exist in the
|
||||
chroot.
|
||||
|
||||
# Description
|
||||
|
||||
`nix shell` runs a command in an environment in which the `$PATH`
|
||||
variable provides the specified *installables*. If not command is
|
||||
specified, it starts the default shell of your user account.
|
||||
|
||||
)""
|
Loading…
Reference in a new issue