aboutsummaryrefslogtreecommitdiff
path: root/src/nix/flake-init.md
blob: fc1f4f805041e38d99566233e6cb148d3e197045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
R""(

# Examples

* Create a flake using the default template:

  ```console
  # nix flake init
  ```

* List available templates:

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

* Create a flake from a specific template:

  ```console
  # nix flake init -t templates#simpleContainer
  ```

# Description

This command creates a flake in the current directory by copying the
files of a template. It will not overwrite existing files. The default
template is `templates#templates.default`, but this can be overridden
using `-t`.

# Template definitions

A flake can declare templates through its `templates` output
attribute. A template has two attributes:

* `description`: A one-line description of the template, in CommonMark
  syntax.

* `path`: The path of the directory to be copied.

* `welcomeText`: A block of markdown text to display when a user initializes a
  new flake based on this template.


Here is an example:

```
outputs = { self }: {

  templates.rust = {
    path = ./rust;
    description = "A simple Rust/Cargo project";
    welcomeText = ''
      # Simple Rust/Cargo Template
      ## Intended usage
      The intended usage of this flake is...

      ## More info
      - [Rust language](https://www.rust-lang.org/)
      - [Rust on the NixOS Wiki](https://nixos.wiki/wiki/Rust)
      - ...
    '';
  };

  templates.default = self.templates.rust;
}
```

)""