2023-07-04 04:18:46 +00:00
# Usage of the New CLI
2023-06-23 14:41:34 +00:00
2023-07-04 04:18:46 +00:00
Once you have enabled `nix-command` and `flake` , you can use the `nix help` command to obtain information about the [New Nix Commands][New Nix Commands]. Here are some useful examples:
2023-06-23 14:41:34 +00:00
```bash
2023-07-04 04:18:46 +00:00
# The following command installs and runs the `ponysay` package from the `nixpkgs` flake.
# The `nixpkgs` flake refers to the `nixpkgs` repository on GitHub, which contains a `flake.nix` file.
# `nixpkgs` is a flake registry ID for `github:NixOS/nixpkgs/nixos-unstable`.
# You can find all the flake registry IDs at <https://github.com/NixOS/flake-registry/blob/master/flake-registry.json>.
2023-06-23 14:41:34 +00:00
echo "Hello Nix" | nix run "nixpkgs#ponysay"
# this command is the same as above, but use a full flake URI instead of falkeregistry id.
echo "Hello Nix" | nix run "github:NixOS/nixpkgs/nixos-unstable#ponysay"
# instead of treat flake package as an application,
# this command use `devShells.example` in flake `zero-to-nix`'s outputs, to setup the development environment,
# and then open a bash shell in that environment.
nix develop "github:DeterminateSystems/zero-to-nix#example"
# instead of using a remote flake, you can open a bash shell using the flake located in the current directory.
mkdir my-flake & & cd my-flake
2023-06-30 09:00:03 +00:00
# init a flake with template
2023-06-23 14:41:34 +00:00
nix flake init --template "github:DeterminateSystems/zero-to-nix#javascript-dev"
# open a bash shell using the flake in current directory
nix develop
# or if your flake has multiple devShell outputs, you can specify which one to use.
nix develop .#example
# build package `bat` from flake `nixpkgs`, and put a symlink `result` in the current directory.
mkdir build-nix-package & & cd build-nix-package
nix build "nixpkgs#bat"
# build a local flake is the same as nix develop, skip it
```
2023-07-06 03:04:52 +00:00
We will introduce more details about `nix develop` , `nix shell` and `nix run` in the next chapter.
2023-06-23 14:41:34 +00:00
[New Nix Commands]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html