diff options
Diffstat (limited to 'posts')
-rw-r--r-- | posts/novice_nix:_flake_templates.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/posts/novice_nix:_flake_templates.md b/posts/novice_nix:_flake_templates.md index 3b38b46..8e25a85 100644 --- a/posts/novice_nix:_flake_templates.md +++ b/posts/novice_nix:_flake_templates.md | |||
@@ -9,7 +9,7 @@ You might already be familiar with `nix flake init`, that | |||
9 | drops a "default" flake expression into your current working | 9 | drops a "default" flake expression into your current working |
10 | directory. If you head over to the manpage: | 10 | directory. If you head over to the manpage: |
11 | 11 | ||
12 | ``` | 12 | ```bash |
13 | nix flake init --help | 13 | nix flake init --help |
14 | ``` | 14 | ``` |
15 | 15 | ||
@@ -23,7 +23,7 @@ does this default originate from? | |||
23 | Quick detour into registries! Registries are a way to alias | 23 | Quick detour into registries! Registries are a way to alias |
24 | popular flakes using identifiers: | 24 | popular flakes using identifiers: |
25 | 25 | ||
26 | ``` | 26 | ```bash |
27 | # list a few predefined registries | 27 | # list a few predefined registries |
28 | $ nix registry list | 28 | $ nix registry list |
29 | . . . | 29 | . . . |
@@ -47,7 +47,7 @@ $ nix flake show git+https://github.com/tweag/nickel | |||
47 | You might notice a registry called `templates` aliased to | 47 | You might notice a registry called `templates` aliased to |
48 | `github:NixOS/templates`. Take a peek with `nix flake show`: | 48 | `github:NixOS/templates`. Take a peek with `nix flake show`: |
49 | 49 | ||
50 | ``` | 50 | ```bash |
51 | $ nix flake show templates | 51 | $ nix flake show templates |
52 | github:NixOS/templates/79f48a7b822f35c068c5e235da2e9fbd154cecee | 52 | github:NixOS/templates/79f48a7b822f35c068c5e235da2e9fbd154cecee |
53 | ├───defaultTemplate: template: A very basic flake | 53 | ├───defaultTemplate: template: A very basic flake |
@@ -63,7 +63,7 @@ Aha! There is a flake output called `defaultTemplate`. This | |||
63 | is the template being sourced when you run `nix flake init`. | 63 | is the template being sourced when you run `nix flake init`. |
64 | Astute readers may conclude the following: | 64 | Astute readers may conclude the following: |
65 | 65 | ||
66 | ``` | 66 | ```bash |
67 | $ nix flake init | 67 | $ nix flake init |
68 | 68 | ||
69 | # is equivalent to | 69 | # is equivalent to |
@@ -78,7 +78,7 @@ $ nix flake init -t git+https://NixOS/templates#defaultTemplate | |||
78 | 78 | ||
79 | Similarly, the other templates can be accessed via: | 79 | Similarly, the other templates can be accessed via: |
80 | 80 | ||
81 | ``` | 81 | ```bash |
82 | $ nix flake init -t templates#c-hello | 82 | $ nix flake init -t templates#c-hello |
83 | $ nix flake init -t templates#simpleContainer | 83 | $ nix flake init -t templates#simpleContainer |
84 | # I think you get the drift ... | 84 | # I think you get the drift ... |
@@ -96,14 +96,14 @@ Alright, so all we need to do is: | |||
96 | Start off by creating a directory to store your templates in | 96 | Start off by creating a directory to store your templates in |
97 | (we will be converting this to a registry later): | 97 | (we will be converting this to a registry later): |
98 | 98 | ||
99 | ``` | 99 | ```bash |
100 | $ mkdir ~/mytemplates | 100 | $ mkdir ~/mytemplates |
101 | ``` | 101 | ``` |
102 | 102 | ||
103 | A flake that exposes a "template" as its output looks | 103 | A flake that exposes a "template" as its output looks |
104 | something like this: | 104 | something like this: |
105 | 105 | ||
106 | ``` | 106 | ```nix |
107 | # inside ~/mytemplates/flake.nix | 107 | # inside ~/mytemplates/flake.nix |
108 | 108 | ||
109 | { | 109 | { |
@@ -132,7 +132,7 @@ populate these directories). | |||
132 | 132 | ||
133 | The output of `nix flake show` should be something like: | 133 | The output of `nix flake show` should be something like: |
134 | 134 | ||
135 | ``` | 135 | ```bash |
136 | $ nix flake show | 136 | $ nix flake show |
137 | path:/home/np/code/nix-stuff/template-tests?narHash=sha256-{...} | 137 | path:/home/np/code/nix-stuff/template-tests?narHash=sha256-{...} |
138 | └───templates | 138 | └───templates |
@@ -143,7 +143,7 @@ path:/home/np/code/nix-stuff/template-tests?narHash=sha256-{...} | |||
143 | Populate your template directories with content, here are my | 143 | Populate your template directories with content, here are my |
144 | template directories for example: | 144 | template directories for example: |
145 | 145 | ||
146 | ``` | 146 | ```bash |
147 | $ tree mytemplates | 147 | $ tree mytemplates |
148 | mytemplates/ | 148 | mytemplates/ |
149 | ├── flake.nix | 149 | ├── flake.nix |
@@ -162,7 +162,7 @@ mytemplates/ | |||
162 | 162 | ||
163 | And that's it! Start using your templates with: | 163 | And that's it! Start using your templates with: |
164 | 164 | ||
165 | ``` | 165 | ```bash |
166 | $ nix flake init -t ~/mytemplates#rust-hello | 166 | $ nix flake init -t ~/mytemplates#rust-hello |
167 | $ tree . | 167 | $ tree . |
168 | . | 168 | . |
@@ -175,7 +175,7 @@ $ tree . | |||
175 | To avoid writing `~/mytemplates` each time, simply alias it | 175 | To avoid writing `~/mytemplates` each time, simply alias it |
176 | to a registry: | 176 | to a registry: |
177 | 177 | ||
178 | ``` | 178 | ```bash |
179 | # alias it to `biscuits` | 179 | # alias it to `biscuits` |
180 | $ nix registry add biscuits ~/mytemplates | 180 | $ nix registry add biscuits ~/mytemplates |
181 | 181 | ||
@@ -195,7 +195,7 @@ not just my homemade templates, but also the templates from | |||
195 | `NixOS/templates` (and maybe a couple of other repositories | 195 | `NixOS/templates` (and maybe a couple of other repositories |
196 | in the wild): | 196 | in the wild): |
197 | 197 | ||
198 | ``` | 198 | ```nix |
199 | { | 199 | { |
200 | description = "Pepper's flake templates"; | 200 | description = "Pepper's flake templates"; |
201 | 201 | ||