aboutsummaryrefslogtreecommitdiff
path: root/docs/index.xml
diff options
context:
space:
mode:
Diffstat (limited to 'docs/index.xml')
-rw-r--r--docs/index.xml242
1 files changed, 121 insertions, 121 deletions
diff --git a/docs/index.xml b/docs/index.xml
index d45ba57..3246f7a 100644
--- a/docs/index.xml
+++ b/docs/index.xml
@@ -15,53 +15,53 @@
15<title>Novice Nix: Flake Templates</title> 15<title>Novice Nix: Flake Templates</title>
16<description>&lt;p&gt;Flakes are very handy to setup entirely pure, project-specific dependencies (not just dependencies, but build steps, shell environments and more) in a declarative way. Writing Flake expressions can get repetitive though, oftentimes, you’d much rather start off with a skeleton. Luckily, &lt;code&gt;nix&lt;/code&gt; already supports templates!&lt;/p&gt; 16<description>&lt;p&gt;Flakes are very handy to setup entirely pure, project-specific dependencies (not just dependencies, but build steps, shell environments and more) in a declarative way. Writing Flake expressions can get repetitive though, oftentimes, you’d much rather start off with a skeleton. Luckily, &lt;code&gt;nix&lt;/code&gt; already supports templates!&lt;/p&gt;
17&lt;p&gt;You might already be familiar with &lt;code&gt;nix flake init&lt;/code&gt;, that drops a “default” flake expression into your current working directory. If you head over to the manpage:&lt;/p&gt; 17&lt;p&gt;You might already be familiar with &lt;code&gt;nix flake init&lt;/code&gt;, that drops a “default” flake expression into your current working directory. If you head over to the manpage:&lt;/p&gt;
18&lt;pre&gt;&lt;code&gt;nix flake init --help&lt;/code&gt;&lt;/pre&gt; 18&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb1-1"&gt;&lt;a href="#cb1-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;nix&lt;/span&gt; flake init &lt;span class="at"&gt;--help&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
19&lt;p&gt;You will read that &lt;code&gt;nix flake init&lt;/code&gt; creates a flake using the “default template”. Additionally, you can create a flake from a specific template by passing the &lt;code&gt;-t&lt;/code&gt; flag. Where does this default originate from?&lt;/p&gt; 19&lt;p&gt;You will read that &lt;code&gt;nix flake init&lt;/code&gt; creates a flake using the “default template”. Additionally, you can create a flake from a specific template by passing the &lt;code&gt;-t&lt;/code&gt; flag. Where does this default originate from?&lt;/p&gt;
20&lt;h2 id="flake-registries"&gt;Flake Registries&lt;/h2&gt; 20&lt;h2 id="flake-registries"&gt;Flake Registries&lt;/h2&gt;
21&lt;p&gt;Quick detour into registries! Registries are a way to alias popular flakes using identifiers:&lt;/p&gt; 21&lt;p&gt;Quick detour into registries! Registries are a way to alias popular flakes using identifiers:&lt;/p&gt;
22&lt;pre&gt;&lt;code&gt;# list a few predefined registries 22&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb2-1"&gt;&lt;a href="#cb2-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# list a few predefined registries&lt;/span&gt;&lt;/span&gt;
23$ nix registry list 23&lt;span id="cb2-2"&gt;&lt;a href="#cb2-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix registry list&lt;/span&gt;
24. . . 24&lt;span id="cb2-3"&gt;&lt;a href="#cb2-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;.&lt;/span&gt; . . &lt;/span&gt;
25global flake:nixpkgs github:NixOS/nixpkgs 25&lt;span id="cb2-4"&gt;&lt;a href="#cb2-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;global&lt;/span&gt; flake:nixpkgs github:NixOS/nixpkgs&lt;/span&gt;
26global flake:patchelf github:NixOS/patchelf 26&lt;span id="cb2-5"&gt;&lt;a href="#cb2-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;global&lt;/span&gt; flake:patchelf github:NixOS/patchelf&lt;/span&gt;
27global flake:nix-serve github:edolstra/nix-serve 27&lt;span id="cb2-6"&gt;&lt;a href="#cb2-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;global&lt;/span&gt; flake:nix-serve github:edolstra/nix-serve&lt;/span&gt;
28global flake:templates github:NixOS/templates 28&lt;span id="cb2-7"&gt;&lt;a href="#cb2-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;global&lt;/span&gt; flake:templates github:NixOS/templates&lt;/span&gt;
29global flake:nickel github:tweag/nickel 29&lt;span id="cb2-8"&gt;&lt;a href="#cb2-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;global&lt;/span&gt; flake:nickel github:tweag/nickel&lt;/span&gt;
30. . . 30&lt;span id="cb2-9"&gt;&lt;a href="#cb2-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;.&lt;/span&gt; . .&lt;/span&gt;
31 31&lt;span id="cb2-10"&gt;&lt;a href="#cb2-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
32# you can do 32&lt;span id="cb2-11"&gt;&lt;a href="#cb2-11" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# you can do &lt;/span&gt;&lt;/span&gt;
33$ nix flake show nickel 33&lt;span id="cb2-12"&gt;&lt;a href="#cb2-12" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake show nickel&lt;/span&gt;
34 34&lt;span id="cb2-13"&gt;&lt;a href="#cb2-13" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
35# instead of 35&lt;span id="cb2-14"&gt;&lt;a href="#cb2-14" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# instead of &lt;/span&gt;&lt;/span&gt;
36$ nix flake show github:tweag/nickel 36&lt;span id="cb2-15"&gt;&lt;a href="#cb2-15" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake show github:tweag/nickel&lt;/span&gt;
37 37&lt;span id="cb2-16"&gt;&lt;a href="#cb2-16" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
38# which is short for 38&lt;span id="cb2-17"&gt;&lt;a href="#cb2-17" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# which is short for&lt;/span&gt;&lt;/span&gt;
39$ nix flake show git+https://github.com/tweag/nickel&lt;/code&gt;&lt;/pre&gt; 39&lt;span id="cb2-18"&gt;&lt;a href="#cb2-18" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake show git+https://github.com/tweag/nickel&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
40&lt;p&gt;You might notice a registry called &lt;code&gt;templates&lt;/code&gt; aliased to &lt;code&gt;github:NixOS/templates&lt;/code&gt;. Take a peek with &lt;code&gt;nix flake show&lt;/code&gt;:&lt;/p&gt; 40&lt;p&gt;You might notice a registry called &lt;code&gt;templates&lt;/code&gt; aliased to &lt;code&gt;github:NixOS/templates&lt;/code&gt;. Take a peek with &lt;code&gt;nix flake show&lt;/code&gt;:&lt;/p&gt;
41&lt;pre&gt;&lt;code&gt;$ nix flake show templates 41&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb3-1"&gt;&lt;a href="#cb3-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake show templates&lt;/span&gt;
42github:NixOS/templates/79f48a7b822f35c068c5e235da2e9fbd154cecee 42&lt;span id="cb3-2"&gt;&lt;a href="#cb3-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;github:NixOS/templates/79f48a7b822f35c068c5e235da2e9fbd154cecee&lt;/span&gt;&lt;/span&gt;
43├───defaultTemplate: template: A very basic flake 43&lt;span id="cb3-3"&gt;&lt;a href="#cb3-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;├───defaultTemplate:&lt;/span&gt; template: A very basic flake&lt;/span&gt;
44└───templates 44&lt;span id="cb3-4"&gt;&lt;a href="#cb3-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;└───templates&lt;/span&gt;&lt;/span&gt;
45 ├───bash-hello: template: An over-engineered Hello World in bash 45&lt;span id="cb3-5"&gt;&lt;a href="#cb3-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├───bash-hello:&lt;/span&gt; template: An over-engineered Hello World in bash&lt;/span&gt;
46 ├───c-hello: template: An over-engineered Hello World in C 46&lt;span id="cb3-6"&gt;&lt;a href="#cb3-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├───c-hello:&lt;/span&gt; template: An over-engineered Hello World in C&lt;/span&gt;
47 ├───rust-web-server: template: A Rust web server including a NixOS module 47&lt;span id="cb3-7"&gt;&lt;a href="#cb3-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├───rust-web-server:&lt;/span&gt; template: A Rust web server including a NixOS module&lt;/span&gt;
48 ├───simpleContainer: template: A NixOS container running apache-httpd 48&lt;span id="cb3-8"&gt;&lt;a href="#cb3-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├───simpleContainer:&lt;/span&gt; template: A NixOS container running apache-httpd&lt;/span&gt;
49 └───trivial: template: A very basic flake&lt;/code&gt;&lt;/pre&gt; 49&lt;span id="cb3-9"&gt;&lt;a href="#cb3-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;└───trivial:&lt;/span&gt; template: A very basic flake&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
50&lt;p&gt;Aha! There is a flake output called &lt;code&gt;defaultTemplate&lt;/code&gt;. This is the template being sourced when you run &lt;code&gt;nix flake init&lt;/code&gt;. Astute readers may conclude the following:&lt;/p&gt; 50&lt;p&gt;Aha! There is a flake output called &lt;code&gt;defaultTemplate&lt;/code&gt;. This is the template being sourced when you run &lt;code&gt;nix flake init&lt;/code&gt;. Astute readers may conclude the following:&lt;/p&gt;
51&lt;pre&gt;&lt;code&gt;$ nix flake init 51&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb4-1"&gt;&lt;a href="#cb4-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init&lt;/span&gt;
52 52&lt;span id="cb4-2"&gt;&lt;a href="#cb4-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
53# is equivalent to 53&lt;span id="cb4-3"&gt;&lt;a href="#cb4-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# is equivalent to&lt;/span&gt;&lt;/span&gt;
54$ nix flake init -t templates#defaultTemplate 54&lt;span id="cb4-4"&gt;&lt;a href="#cb4-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; templates#defaultTemplate&lt;/span&gt;
55 55&lt;span id="cb4-5"&gt;&lt;a href="#cb4-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
56# is equivalent to 56&lt;span id="cb4-6"&gt;&lt;a href="#cb4-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# is equivalent to&lt;/span&gt;&lt;/span&gt;
57$ nix flake init -t github:NixOS/templates#defaultTemplate 57&lt;span id="cb4-7"&gt;&lt;a href="#cb4-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; github:NixOS/templates#defaultTemplate&lt;/span&gt;
58 58&lt;span id="cb4-8"&gt;&lt;a href="#cb4-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
59# which is short for 59&lt;span id="cb4-9"&gt;&lt;a href="#cb4-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# which is short for&lt;/span&gt;&lt;/span&gt;
60$ nix flake init -t git+https://NixOS/templates#defaultTemplate&lt;/code&gt;&lt;/pre&gt; 60&lt;span id="cb4-10"&gt;&lt;a href="#cb4-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; git+https://NixOS/templates#defaultTemplate&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
61&lt;p&gt;Similarly, the other templates can be accessed via:&lt;/p&gt; 61&lt;p&gt;Similarly, the other templates can be accessed via:&lt;/p&gt;
62&lt;pre&gt;&lt;code&gt;$ nix flake init -t templates#c-hello 62&lt;div class="sourceCode" id="cb5"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb5-1"&gt;&lt;a href="#cb5-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; templates#c-hello&lt;/span&gt;
63$ nix flake init -t templates#simpleContainer 63&lt;span id="cb5-2"&gt;&lt;a href="#cb5-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; templates#simpleContainer&lt;/span&gt;
64# I think you get the drift ...&lt;/code&gt;&lt;/pre&gt; 64&lt;span id="cb5-3"&gt;&lt;a href="#cb5-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# I think you get the drift ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
65&lt;h2 id="rolling-your-own-templates"&gt;Rolling your own templates&lt;/h2&gt; 65&lt;h2 id="rolling-your-own-templates"&gt;Rolling your own templates&lt;/h2&gt;
66&lt;p&gt;Alright, so all we need to do is:&lt;/p&gt; 66&lt;p&gt;Alright, so all we need to do is:&lt;/p&gt;
67&lt;ul&gt; 67&lt;ul&gt;
@@ -70,94 +70,94 @@ $ nix flake init -t templates#simpleContainer
70&lt;li&gt;(&lt;strong&gt;optionally&lt;/strong&gt;) alias our custom templates flake to an identifier using registries, for easier access&lt;/li&gt; 70&lt;li&gt;(&lt;strong&gt;optionally&lt;/strong&gt;) alias our custom templates flake to an identifier using registries, for easier access&lt;/li&gt;
71&lt;/ul&gt; 71&lt;/ul&gt;
72&lt;p&gt;Start off by creating a directory to store your templates in (we will be converting this to a registry later):&lt;/p&gt; 72&lt;p&gt;Start off by creating a directory to store your templates in (we will be converting this to a registry later):&lt;/p&gt;
73&lt;pre&gt;&lt;code&gt;$ mkdir ~/mytemplates&lt;/code&gt;&lt;/pre&gt; 73&lt;div class="sourceCode" id="cb6"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb6-1"&gt;&lt;a href="#cb6-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; mkdir ~/mytemplates&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
74&lt;p&gt;A flake that exposes a “template” as its output looks something like this:&lt;/p&gt; 74&lt;p&gt;A flake that exposes a “template” as its output looks something like this:&lt;/p&gt;
75&lt;pre&gt;&lt;code&gt;# inside ~/mytemplates/flake.nix 75&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode nix"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb7-1"&gt;&lt;a href="#cb7-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# inside ~/mytemplates/flake.nix&lt;/span&gt;&lt;/span&gt;
76 76&lt;span id="cb7-2"&gt;&lt;a href="#cb7-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
77{ 77&lt;span id="cb7-3"&gt;&lt;a href="#cb7-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="kw"&gt;{&lt;/span&gt;&lt;/span&gt;
78 description = &amp;quot;Pepper&amp;#39;s flake templates&amp;quot;; 78&lt;span id="cb7-4"&gt;&lt;a href="#cb7-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;Pepper&amp;#39;s flake templates&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
79 79&lt;span id="cb7-5"&gt;&lt;a href="#cb7-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
80 outputs = { self, ... }: { 80&lt;span id="cb7-6"&gt;&lt;a href="#cb7-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;outputs&lt;/span&gt; = { self, ... }: {&lt;/span&gt;
81 templates = { 81&lt;span id="cb7-7"&gt;&lt;a href="#cb7-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;templates&lt;/span&gt; = {&lt;/span&gt;
82 latex-report = { 82&lt;span id="cb7-8"&gt;&lt;a href="#cb7-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;latex-report&lt;/span&gt; = {&lt;/span&gt;
83 path = ./latex-report-template; 83&lt;span id="cb7-9"&gt;&lt;a href="#cb7-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;path&lt;/span&gt; = ./latex-report-template&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
84 description = &amp;quot;A latex whitepaper project&amp;quot;; 84&lt;span id="cb7-10"&gt;&lt;a href="#cb7-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;A latex whitepaper project&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
85 }; 85&lt;span id="cb7-11"&gt;&lt;a href="#cb7-11" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="kw"&gt;};&lt;/span&gt;&lt;/span&gt;
86 rust-hello = { 86&lt;span id="cb7-12"&gt;&lt;a href="#cb7-12" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;rust-hello&lt;/span&gt; = {&lt;/span&gt;
87 path = ./rust-hello-template; 87&lt;span id="cb7-13"&gt;&lt;a href="#cb7-13" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;path&lt;/span&gt; = ./rust-hello-template&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
88 description = &amp;quot;Simple Hello World in Rust&amp;quot;; 88&lt;span id="cb7-14"&gt;&lt;a href="#cb7-14" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;Simple Hello World in Rust&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
89 }; 89&lt;span id="cb7-15"&gt;&lt;a href="#cb7-15" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
90 }; 90&lt;span id="cb7-16"&gt;&lt;a href="#cb7-16" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
91 }; 91&lt;span id="cb7-17"&gt;&lt;a href="#cb7-17" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
92}&lt;/code&gt;&lt;/pre&gt; 92&lt;span id="cb7-18"&gt;&lt;a href="#cb7-18" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="er"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
93&lt;p&gt;The &lt;code&gt;path&lt;/code&gt; attribute to each template is what gets copied over when you initialize a flake. Running &lt;code&gt;nix flake init -t .#latex-report&lt;/code&gt; will initialize the current directory with the contents of &lt;code&gt;./latex-report-template&lt;/code&gt; (we are yet to populate these directories).&lt;/p&gt; 93&lt;p&gt;The &lt;code&gt;path&lt;/code&gt; attribute to each template is what gets copied over when you initialize a flake. Running &lt;code&gt;nix flake init -t .#latex-report&lt;/code&gt; will initialize the current directory with the contents of &lt;code&gt;./latex-report-template&lt;/code&gt; (we are yet to populate these directories).&lt;/p&gt;
94&lt;p&gt;The output of &lt;code&gt;nix flake show&lt;/code&gt; should be something like:&lt;/p&gt; 94&lt;p&gt;The output of &lt;code&gt;nix flake show&lt;/code&gt; should be something like:&lt;/p&gt;
95&lt;pre&gt;&lt;code&gt;$ nix flake show 95&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb8-1"&gt;&lt;a href="#cb8-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake show&lt;/span&gt;
96path:/home/np/code/nix-stuff/template-tests?narHash=sha256-{...} 96&lt;span id="cb8-2"&gt;&lt;a href="#cb8-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;path:/home/np/code/nix-stuff/template-tests?narHash=sha256-{...}&lt;/span&gt;&lt;/span&gt;
97└───templates 97&lt;span id="cb8-3"&gt;&lt;a href="#cb8-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;└───templates&lt;/span&gt;&lt;/span&gt;
98 ├───latex-report: template: A latex whitepaper project 98&lt;span id="cb8-4"&gt;&lt;a href="#cb8-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├───latex-report:&lt;/span&gt; template: A latex whitepaper project&lt;/span&gt;
99 └───rust-hello: template: Simple Hello World in Rust&lt;/code&gt;&lt;/pre&gt; 99&lt;span id="cb8-5"&gt;&lt;a href="#cb8-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;└───rust-hello:&lt;/span&gt; template: Simple Hello World in Rust&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
100&lt;p&gt;Populate your template directories with content, here are my template directories for example:&lt;/p&gt; 100&lt;p&gt;Populate your template directories with content, here are my template directories for example:&lt;/p&gt;
101&lt;pre&gt;&lt;code&gt;$ tree mytemplates 101&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb9-1"&gt;&lt;a href="#cb9-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; tree mytemplates&lt;/span&gt;
102mytemplates/ 102&lt;span id="cb9-2"&gt;&lt;a href="#cb9-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;mytemplates/&lt;/span&gt;&lt;/span&gt;
103├── flake.nix 103&lt;span id="cb9-3"&gt;&lt;a href="#cb9-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;├──&lt;/span&gt; flake.nix&lt;/span&gt;
104├── latex-report-template 104&lt;span id="cb9-4"&gt;&lt;a href="#cb9-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;├──&lt;/span&gt; latex-report-template&lt;/span&gt;
105│   ├── flake.nix 105&lt;span id="cb9-5"&gt;&lt;a href="#cb9-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;│  &lt;/span&gt; ├── flake.nix&lt;/span&gt;
106│   ├── makefile 106&lt;span id="cb9-6"&gt;&lt;a href="#cb9-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;│  &lt;/span&gt; ├── makefile&lt;/span&gt;
107│   └── src 107&lt;span id="cb9-7"&gt;&lt;a href="#cb9-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;│  &lt;/span&gt; └── src&lt;/span&gt;
108│   ├── meta.sty 108&lt;span id="cb9-8"&gt;&lt;a href="#cb9-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;│  &lt;/span&gt; ├── meta.sty&lt;/span&gt;
109│   └── report.tex 109&lt;span id="cb9-9"&gt;&lt;a href="#cb9-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;│  &lt;/span&gt; └── report.tex&lt;/span&gt;
110└── rust-hello-template 110&lt;span id="cb9-10"&gt;&lt;a href="#cb9-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;└──&lt;/span&gt; rust-hello-template&lt;/span&gt;
111 ├── Cargo.toml 111&lt;span id="cb9-11"&gt;&lt;a href="#cb9-11" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├──&lt;/span&gt; Cargo.toml&lt;/span&gt;
112 ├── flake.nix 112&lt;span id="cb9-12"&gt;&lt;a href="#cb9-12" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;├──&lt;/span&gt; flake.nix&lt;/span&gt;
113 └── src 113&lt;span id="cb9-13"&gt;&lt;a href="#cb9-13" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;└──&lt;/span&gt; src&lt;/span&gt;
114 └── main.rs&lt;/code&gt;&lt;/pre&gt; 114&lt;span id="cb9-14"&gt;&lt;a href="#cb9-14" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;└──&lt;/span&gt; main.rs&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
115&lt;p&gt;And that’s it! Start using your templates with:&lt;/p&gt; 115&lt;p&gt;And that’s it! Start using your templates with:&lt;/p&gt;
116&lt;pre&gt;&lt;code&gt;$ nix flake init -t ~/mytemplates#rust-hello 116&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb10-1"&gt;&lt;a href="#cb10-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; ~/mytemplates#rust-hello&lt;/span&gt;
117$ tree . 117&lt;span id="cb10-2"&gt;&lt;a href="#cb10-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; tree .&lt;/span&gt;
118. 118&lt;span id="cb10-3"&gt;&lt;a href="#cb10-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;.&lt;/span&gt;&lt;/span&gt;
119├── Cargo.toml 119&lt;span id="cb10-4"&gt;&lt;a href="#cb10-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;├──&lt;/span&gt; Cargo.toml&lt;/span&gt;
120├── flake.nix 120&lt;span id="cb10-5"&gt;&lt;a href="#cb10-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;├──&lt;/span&gt; flake.nix&lt;/span&gt;
121└── src 121&lt;span id="cb10-6"&gt;&lt;a href="#cb10-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;└──&lt;/span&gt; src&lt;/span&gt;
122 └── main.rs&lt;/code&gt;&lt;/pre&gt; 122&lt;span id="cb10-7"&gt;&lt;a href="#cb10-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;└──&lt;/span&gt; main.rs&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
123&lt;p&gt;To avoid writing &lt;code&gt;~/mytemplates&lt;/code&gt; each time, simply alias it to a registry:&lt;/p&gt; 123&lt;p&gt;To avoid writing &lt;code&gt;~/mytemplates&lt;/code&gt; each time, simply alias it to a registry:&lt;/p&gt;
124&lt;pre&gt;&lt;code&gt;# alias it to `biscuits` 124&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode bash"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb11-1"&gt;&lt;a href="#cb11-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# alias it to `biscuits`&lt;/span&gt;&lt;/span&gt;
125$ nix registry add biscuits ~/mytemplates 125&lt;span id="cb11-2"&gt;&lt;a href="#cb11-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix registry add biscuits ~/mytemplates&lt;/span&gt;
126 126&lt;span id="cb11-3"&gt;&lt;a href="#cb11-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
127# you will see it listed under `user` registries 127&lt;span id="cb11-4"&gt;&lt;a href="#cb11-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="co"&gt;# you will see it listed under `user` registries&lt;/span&gt;&lt;/span&gt;
128$ nix registry list 128&lt;span id="cb11-5"&gt;&lt;a href="#cb11-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix registry list&lt;/span&gt;
129. . . 129&lt;span id="cb11-6"&gt;&lt;a href="#cb11-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;.&lt;/span&gt; . .&lt;/span&gt;
130user flake:biscuits path:/home/np/template-tests 130&lt;span id="cb11-7"&gt;&lt;a href="#cb11-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;user&lt;/span&gt; flake:biscuits path:/home/np/template-tests&lt;/span&gt;
131. . . 131&lt;span id="cb11-8"&gt;&lt;a href="#cb11-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="bu"&gt;.&lt;/span&gt; . .&lt;/span&gt;
132 132&lt;span id="cb11-9"&gt;&lt;a href="#cb11-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;/span&gt;
133$ nix flake init -t biscuits#latex-report&lt;/code&gt;&lt;/pre&gt; 133&lt;span id="cb11-10"&gt;&lt;a href="#cb11-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;$&lt;/span&gt; nix flake init &lt;span class="at"&gt;-t&lt;/span&gt; biscuits#latex-report&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
134&lt;h2 id="extending-the-official-templates"&gt;Extending the official templates&lt;/h2&gt; 134&lt;h2 id="extending-the-official-templates"&gt;Extending the official templates&lt;/h2&gt;
135&lt;p&gt;I personally, would like the &lt;code&gt;biscuits&lt;/code&gt; registry to include not just my homemade templates, but also the templates from &lt;code&gt;NixOS/templates&lt;/code&gt; (and maybe a couple of other repositories in the wild):&lt;/p&gt; 135&lt;p&gt;I personally, would like the &lt;code&gt;biscuits&lt;/code&gt; registry to include not just my homemade templates, but also the templates from &lt;code&gt;NixOS/templates&lt;/code&gt; (and maybe a couple of other repositories in the wild):&lt;/p&gt;
136&lt;pre&gt;&lt;code&gt; { 136&lt;div class="sourceCode" id="cb12"&gt;&lt;pre class="sourceCode nix"&gt;&lt;code class="sourceCode bash"&gt;&lt;span id="cb12-1"&gt;&lt;a href="#cb12-1" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="kw"&gt;{&lt;/span&gt;&lt;/span&gt;
137 description = &amp;quot;Pepper&amp;#39;s flake templates&amp;quot;; 137&lt;span id="cb12-2"&gt;&lt;a href="#cb12-2" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;Pepper&amp;#39;s flake templates&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
138 138&lt;span id="cb12-3"&gt;&lt;a href="#cb12-3" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;/span&gt;
139+ inputs = { 139&lt;span id="cb12-4"&gt;&lt;a href="#cb12-4" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; inputs = {&lt;/span&gt;
140+ official-templates.url = github:NixOS/templates; 140&lt;span id="cb12-5"&gt;&lt;a href="#cb12-5" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; official-templates.url = github:NixOS/templates&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
141+ other-templates.url = github:some-other/templates; 141&lt;span id="cb12-6"&gt;&lt;a href="#cb12-6" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; other-templates.url = github:some-other/templates&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
142+ }; 142&lt;span id="cb12-7"&gt;&lt;a href="#cb12-7" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; }&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
143 143&lt;span id="cb12-8"&gt;&lt;a href="#cb12-8" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;/span&gt;
144 outputs = { self, official-templates, other-templates ... }: { 144&lt;span id="cb12-9"&gt;&lt;a href="#cb12-9" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;outputs&lt;/span&gt; = { self, official-templates, other-templates ... }: {&lt;/span&gt;
145 145&lt;span id="cb12-10"&gt;&lt;a href="#cb12-10" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;/span&gt;
146 templates = { 146&lt;span id="cb12-11"&gt;&lt;a href="#cb12-11" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;templates&lt;/span&gt; = {&lt;/span&gt;
147 latex-report = { 147&lt;span id="cb12-12"&gt;&lt;a href="#cb12-12" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;latex-report&lt;/span&gt; = {&lt;/span&gt;
148 path = ./latex-report-template; 148&lt;span id="cb12-13"&gt;&lt;a href="#cb12-13" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;path&lt;/span&gt; = ./latex-report-template&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
149 description = &amp;quot;A latex whitepaper project&amp;quot;; 149&lt;span id="cb12-14"&gt;&lt;a href="#cb12-14" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;A latex whitepaper project&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
150 }; 150&lt;span id="cb12-15"&gt;&lt;a href="#cb12-15" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="kw"&gt;};&lt;/span&gt;&lt;/span&gt;
151 rust-hello = { 151&lt;span id="cb12-16"&gt;&lt;a href="#cb12-16" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;rust-hello&lt;/span&gt; = {&lt;/span&gt;
152 path = ./rust-hello-template; 152&lt;span id="cb12-17"&gt;&lt;a href="#cb12-17" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;path&lt;/span&gt; = ./rust-hello-template&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
153 description = &amp;quot;Simple Hello World in Rust, with overloaded Rust toolchain&amp;quot;; 153&lt;span id="cb12-18"&gt;&lt;a href="#cb12-18" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="ex"&gt;description&lt;/span&gt; = &lt;span class="st"&gt;&amp;quot;Simple Hello World in Rust, with overloaded Rust toolchain&amp;quot;&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
154 }; 154&lt;span id="cb12-19"&gt;&lt;a href="#cb12-19" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
155 } 155&lt;span id="cb12-20"&gt;&lt;a href="#cb12-20" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;/span&gt;
156+ // official-templates.templates 156&lt;span id="cb12-21"&gt;&lt;a href="#cb12-21" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; // official-templates.templates&lt;/span&gt;
157+ // other-templates.templates; 157&lt;span id="cb12-22"&gt;&lt;a href="#cb12-22" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt;&lt;span class="ex"&gt;+&lt;/span&gt; // other-templates.templates&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
158 158&lt;span id="cb12-23"&gt;&lt;a href="#cb12-23" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;/span&gt;
159 }; 159&lt;span id="cb12-24"&gt;&lt;a href="#cb12-24" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;span class="kw"&gt;;&lt;/span&gt;&lt;/span&gt;
160 }&lt;/code&gt;&lt;/pre&gt; 160&lt;span id="cb12-25"&gt;&lt;a href="#cb12-25" aria-hidden="true" tabindex="-1"&gt;&lt;/a&gt; &lt;span class="er"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
161&lt;p&gt;Running &lt;code&gt;nix flake show biscuits&lt;/code&gt; will now list templates from the &lt;code&gt;biscuits&lt;/code&gt; registry as well as the ones from &lt;code&gt;NixOS/templates&lt;/code&gt;. Ensure that the names don’t collide though.&lt;/p&gt;</description> 161&lt;p&gt;Running &lt;code&gt;nix flake show biscuits&lt;/code&gt; will now list templates from the &lt;code&gt;biscuits&lt;/code&gt; registry as well as the ones from &lt;code&gt;NixOS/templates&lt;/code&gt;. Ensure that the names don’t collide though.&lt;/p&gt;</description>
162<link>https://peppe.rs/posts/novice_nix:_flake_templates/</link> 162<link>https://peppe.rs/posts/novice_nix:_flake_templates/</link>
163<pubDate>Tue, 05 Oct 2021 16:49:00 +0000</pubDate> 163<pubDate>Tue, 05 Oct 2021 16:49:00 +0000</pubDate>