Home Explore Blog CI



nix

src/nix/flake-new.md
fe0ab8885ba3e109c01cd54990b119baa03addf486f1bb1d0000000300000219
R""(

# Examples

* Create a flake using the default template in the directory `hello`:

  ```console
  # nix flake new hello
  ```

* List available templates:

  ```console
  # nix flake show templates
  ```

* Create a flake from a specific template in the directory `hello`:

  ```console
  # nix flake new hello -t templates#trivial
  ```

# Description

This command creates a flake in the directory `dest-dir`, which must
not already exist. It's equivalent to:

```console
# mkdir dest-dir
# cd dest-dir
# nix flake init
```

)""

Chunks
4741bd96 (1st chunk of `src/nix/flake-new.md`)
Title: Nix Flake New Command: Usage and Description
Summary
The `nix flake new` command initializes a new flake in a specified, non-existent directory (`dest-dir`). It offers flexibility by allowing the user to create a flake using either the default template or a specific template selected from available templates. To specify a template, the `-t` flag is used (e.g., `templates#trivial`). List available templates with `nix flake show templates`. The command combines the actions of creating the directory (`mkdir dest-dir`), changing the current directory (`cd dest-dir`), and initializing a flake (`nix flake init`). It's a quick way to set up a new flake project. `nix flake new hello` uses the default template, while `nix flake new hello -t templates#trivial` uses the `trivial` template.