Skip to content

Commit 4079785

Browse files
author
Noam Yorav-Raphael
committed
Format markdown with Prettier
1 parent 5d75cb2 commit 4079785

18 files changed

+102
-102
lines changed

pills/01-why-you-should-give-it-try.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Let's say you need an nginx service and also an nginx-openresty service. You hav
2626

2727
Or suppose that you want to run two different instances of mysql: 5.2 and 5.5. The same thing applies, plus you have to also make sure the two mysqlclient libraries do not collide.
2828

29-
This is not impossible but it *is* very inconvenient. If you want to install two whole stacks of software like GNOME 3.10 and GNOME 3.12, you can imagine the amount of work.
29+
This is not impossible but it _is_ very inconvenient. If you want to install two whole stacks of software like GNOME 3.10 and GNOME 3.12, you can imagine the amount of work.
3030

3131
From an administrator's point of view: you can use containers. The typical solution nowadays is to create a container per service, especially when different versions are needed. That somewhat solves the problem, but at a different level and with other drawbacks. For example, needing orchestration tools, setting up a shared cache of packages, and new machines to monitor rather than simple services.
3232

@@ -36,7 +36,7 @@ And so on. Nix solves all this at the packaging level and solves it well. A sing
3636

3737
## Being purely functional
3838

39-
Nix makes no assumptions about the global state of the system. This has many advantages, but also some drawbacks of course. The core of a Nix system is the Nix store, usually installed under `/nix/store`, and some tools to manipulate the store. In Nix there is the notion of a *derivation* rather than a package. The difference can be subtle at the beginning, so I will often use the words interchangeably.
39+
Nix makes no assumptions about the global state of the system. This has many advantages, but also some drawbacks of course. The core of a Nix system is the Nix store, usually installed under `/nix/store`, and some tools to manipulate the store. In Nix there is the notion of a _derivation_ rather than a package. The difference can be subtle at the beginning, so I will often use the words interchangeably.
4040

4141
Derivations/packages are stored in the Nix store as follows: `/nix/store/hash-name`, where the hash uniquely identifies the derivation (this isn't quite true, it's a little more complex), and the name is the name of the derivation.
4242

@@ -85,7 +85,7 @@ If there is a data format change, then migrating to the new data format remains
8585

8686
Nix lets you compose software at build time with maximum flexibility, and with builds being as reproducible as possible. Not only that, due to its nature deploying systems in the cloud is so easy, consistent, and reliable that in the Nix world all existing self-containment and orchestration tools are deprecated by [NixOps](http://nixos.org/nixops/).
8787

88-
It however *currently* falls short when working with dynamic composition at runtime or replacing low level libraries, due to the need to rebuild dependencies.
88+
It however _currently_ falls short when working with dynamic composition at runtime or replacing low level libraries, due to the need to rebuild dependencies.
8989

9090
That may sound scary, however after running NixOS on both a server and a laptop desktop, I'm very satisfied so far. Some of the architectural problems just need some man-power, other design problems still need to be solved as a community.
9191

pills/02-install-on-your-running.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For installation instructions, please refer to the Nix Reference Manual on [ Ins
88

99
## Installation
1010

11-
These articles are not a tutorial on *using* Nix. Instead, we're going to walk through the Nix system to understand the fundamentals.
11+
These articles are not a tutorial on _using_ Nix. Instead, we're going to walk through the Nix system to understand the fundamentals.
1212

1313
The first thing to note: derivations in the Nix store refer to other derivations which are themselves in the Nix store. They don't use `libc` from our system or anywhere else. It's a self-contained store of all the software we need to bootstrap up to any particular package.
1414

@@ -50,7 +50,7 @@ Note: If this is the first time you're using Nix after the initial installation,
5050

5151
<div class="warning">
5252

53-
Important: Never change `/nix/store` manually. If you do, then it will no longer be in sync with the sqlite db, unless you *really* know what you are doing.
53+
Important: Never change `/nix/store` manually. If you do, then it will no longer be in sync with the sqlite db, unless you _really_ know what you are doing.
5454

5555
</div>
5656

@@ -124,11 +124,11 @@ You can see for yourself, don't worry if you see multiple bash derivations:
124124

125125
Keeping the store in `/nix` means we can grab the binary cache from nixos.org (just like you grab packages from debian mirrors) otherwise:
126126

127-
- glibc would be installed under `/foo/store`
127+
- glibc would be installed under `/foo/store`
128128

129-
- Thus bash would need to point to glibc under `/foo/store`, instead of under `/nix/store`
129+
- Thus bash would need to point to glibc under `/foo/store`, instead of under `/nix/store`
130130

131-
- So the binary cache can't help, because we need a *different* bash, and so we'd have to recompile everything ourselves.
131+
- So the binary cache can't help, because we need a _different_ bash, and so we'd have to recompile everything ourselves.
132132

133133
After all `/nix` is a sensible place for the store.
134134

pills/03-enter-environment.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Back to the installation:
2828

2929
Now you can run `hello`. Things to notice:
3030

31-
- We installed software as a user, and only for the Nix user.
31+
- We installed software as a user, and only for the Nix user.
3232

33-
- It created a new user environment. That's a new generation of our Nix user profile.
33+
- It created a new user environment. That's a new generation of our Nix user profile.
3434

35-
- The [nix-env](https://nixos.org/manual/nix/stable/command-ref/nix-env.html) tool manages environments, profiles and their generations.
35+
- The [nix-env](https://nixos.org/manual/nix/stable/command-ref/nix-env.html) tool manages environments, profiles and their generations.
3636

37-
- We installed `hello` by derivation name minus the version. I repeat: we specified the **derivation name** (minus the version) to install it.
37+
- We installed `hello` by derivation name minus the version. I repeat: we specified the **derivation name** (minus the version) to install it.
3838

3939
We can list generations without walking through the `/nix` hierarchy:
4040

@@ -135,7 +135,7 @@ A nicer view of the closure:
135135
$ nix-store -q --tree `which man`
136136
[...]
137137

138-
With the above command, you can find out exactly why a *runtime* dependency, be it direct or indirect, exists for a given derivation.
138+
With the above command, you can find out exactly why a _runtime_ dependency, be it direct or indirect, exists for a given derivation.
139139

140140
The same applies to environments. As an exercise, run `nix-store -q --tree ~/.nix-profile`, and see that the first children are direct dependencies of the user environment: the installed derivations, and the `manifest.nix`.
141141

@@ -162,7 +162,7 @@ The first option is to rollback:
162162

163163
The second option is to install Nix, thus creating a new generation:
164164

165-
$ /nix/store/ig31y9gfpp8pf3szdd7d4sf29zr7igbr-nix-2.1.3/bin/nix-env -i /nix/store/ig31y9gfpp8pf3szdd7d4sf29zr7igbr-nix-2.1.3/bin/nix-env
165+
$ /nix/store/ig31y9gfpp8pf3szdd7d4sf29zr7igbr-nix-2.1.3/bin/nix-env -i /nix/store/ig31y9gfpp8pf3szdd7d4sf29zr7igbr-nix-2.1.3/bin/nix-env
166166

167167
## Channels
168168

pills/04-basics-of-language.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Escaping `${...}` within double quoted strings is done with the backslash. Withi
106106

107107
## Lists
108108

109-
Lists are a sequence of expressions delimited by space (*not* comma):
109+
Lists are a sequence of expressions delimited by space (_not_ comma):
110110

111111
nix-repl> [ 2 "foo" true (2+3) ]
112112
[ 2 "foo" true 5 ]
@@ -201,7 +201,7 @@ This kind of expression is something you rarely see in other languages. You can
201201
nix-repl> with longName; a + b
202202
7
203203

204-
That's it, it takes an attribute set and includes symbols from it in the scope of the inner expression. Of course, only valid identifiers from the keys of the set will be included. If a symbol exists in the outer scope and would also be introduced by the `with`, it will *not* be shadowed. You can however still refer to the attribute set:
204+
That's it, it takes an attribute set and includes symbols from it in the scope of the inner expression. Of course, only valid identifiers from the keys of the set will be included. If a symbol exists in the outer scope and would also be introduced by the `with`, it will _not_ be shadowed. You can however still refer to the attribute set:
205205

206206
nix-repl> let a = 10; in with longName; a + b
207207
14

pills/05-functions-and-imports.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ That's it, you give a name to the whole parameter with name@ before the set patt
115115

116116
Advantages of using argument sets:
117117

118-
- Named unordered arguments: you don't have to remember the order of the arguments.
118+
- Named unordered arguments: you don't have to remember the order of the arguments.
119119

120-
- You can pass sets, that adds a whole new layer of flexibility and convenience.
120+
- You can pass sets, that adds a whole new layer of flexibility and convenience.
121121

122122
Disadvantages:
123123

124-
- Partial application does not work with argument sets. You have to specify the whole attribute set, not part of it.
124+
- Partial application does not work with argument sets. You have to specify the whole attribute set, not part of it.
125125

126126
You may find similarities with [Python \*\*kwargs](https://docs.python.org/3/faq/programming.html#how-can-i-pass-optional-or-keyword-parameters-from-one-function-to-another).
127127

@@ -173,11 +173,11 @@ So how do we pass information to the module? Use functions, like we did with `mu
173173

174174
Explaining:
175175

176-
- In `test.nix` we return a function. It accepts a set, with default attributes `b`, `trueMsg` and `falseMsg`.
176+
- In `test.nix` we return a function. It accepts a set, with default attributes `b`, `trueMsg` and `falseMsg`.
177177

178-
- `builtins.trace` is a [built-in function](https://nixos.org/manual/nix/stable/expressions/builtins.html) that takes two arguments. The first is the message to display, the second is the value to return. It's usually used for debugging purposes.
178+
- `builtins.trace` is a [built-in function](https://nixos.org/manual/nix/stable/expressions/builtins.html) that takes two arguments. The first is the message to display, the second is the value to return. It's usually used for debugging purposes.
179179

180-
- Then we import `test.nix`, and call the function with that set.
180+
- Then we import `test.nix`, and call the function with that set.
181181

182182
So when is the message shown? Only when it needs to be evaluated.
183183

pills/06-our-first-derivation.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ That's where the real power comes in.
1414

1515
The `derivation` function receives a set as its first argument. This set requires at least the following three attributes:
1616

17-
- name: the name of the derivation. In the nix store the format is hash-name, that's the name.
17+
- name: the name of the derivation. In the nix store the format is hash-name, that's the name.
1818

19-
- system: is the name of the system in which the derivation can be built. For example, x86_64-linux.
19+
- system: is the name of the system in which the derivation can be built. For example, x86_64-linux.
2020

21-
- builder: is the binary program that builds the derivation.
21+
- builder: is the binary program that builds the derivation.
2222

2323
First of all, what's the name of our system as seen by nix?
2424

@@ -39,11 +39,11 @@ What's that `.drv` file? It is the specification of how to build the derivation,
3939

4040
Before continuing, some analogies with the C language:
4141

42-
- `.nix` files are like `.c` files.
42+
- `.nix` files are like `.c` files.
4343

44-
- `.drv` files are intermediate files like `.o` files. The `.drv` describes how to build a derivation; it's the bare minimum information.
44+
- `.drv` files are intermediate files like `.o` files. The `.drv` describes how to build a derivation; it's the bare minimum information.
4545

46-
- out paths are then the product of the build.
46+
- out paths are then the product of the build.
4747

4848
Both drv paths and out paths are stored in the nix store as you can see.
4949

@@ -257,9 +257,9 @@ Nix does not build derivations **during evaluation** of Nix expressions. In fact
257257

258258
An important separation is made in Nix:
259259

260-
- **Instantiate/Evaluation time**: the Nix expression is parsed, interpreted and finally returns a derivation set. During evaluation, you can refer to other derivations because Nix will create .drv files and we will know out paths beforehand. This is achieved with [nix-instantiate](https://nixos.org/manual/nix/stable/command-ref/nix-instantiate.html).
260+
- **Instantiate/Evaluation time**: the Nix expression is parsed, interpreted and finally returns a derivation set. During evaluation, you can refer to other derivations because Nix will create .drv files and we will know out paths beforehand. This is achieved with [nix-instantiate](https://nixos.org/manual/nix/stable/command-ref/nix-instantiate.html).
261261

262-
- **Realise/Build time**: the .drv from the derivation set is built, first building .drv inputs (build dependencies). This is achieved with [nix-store -r](https://nixos.org/manual/nix/stable/command-ref/nix-store.html#operation---realise).
262+
- **Realise/Build time**: the .drv from the derivation set is built, first building .drv inputs (build dependencies). This is achieved with [nix-store -r](https://nixos.org/manual/nix/stable/command-ref/nix-store.html#operation---realise).
263263

264264
Think of it as of compile time and link time like with C/C++ projects. You first compile all source files to object files. Then link object files in a single executable.
265265

pills/07-working-derivation.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ What we have to do is create something in the path `$out`, be it a file or a dir
2929

3030
In addition, we print out the environment variables during the build process. We cannot use env for this, because env is part of coreutils and we don't have a dependency to it yet. We only have bash for now.
3131

32-
Like for coreutils in the previous pill, we get a blessed bash for free from our magic nixpkgs stuff:
32+
Like for coreutils in the previous pill, we get a blessed bash for free from our magic nixpkgs stuff:
3333

3434
```
3535
nix-repl> :l <nixpkgs>
@@ -80,15 +80,15 @@ declare -x system="x86_64-linux"
8080

8181
Let's inspect those environment variables printed during the build process.
8282

83-
- `$HOME` is not your home directory, and `/homeless-shelter` doesn't exist at all. We force packages not to depend on `$HOME` during the build process.
83+
- `$HOME` is not your home directory, and `/homeless-shelter` doesn't exist at all. We force packages not to depend on `$HOME` during the build process.
8484

85-
- `$PATH` plays the same game as `$HOME`
85+
- `$PATH` plays the same game as `$HOME`
8686

87-
- `$NIX_BUILD_CORES` and `$NIX_STORE` are [nix configuration options](https://nixos.org/manual/nix/stable/command-ref/conf-file.html)
87+
- `$NIX_BUILD_CORES` and `$NIX_STORE` are [nix configuration options](https://nixos.org/manual/nix/stable/command-ref/conf-file.html)
8888

89-
- `$PWD` and `$TMP` clearly show that nix created a temporary build directory
89+
- `$PWD` and `$TMP` clearly show that nix created a temporary build directory
9090

91-
- Then `$builder`, `$name`, `$out`, and `$system` are variables set due to the .drv file's contents.
91+
- Then `$builder`, `$name`, `$out`, and `$system` are variables set due to the .drv file's contents.
9292

9393
And that's how we were able to use `$out` in our derivation and put stuff in it. It's like Nix reserved a slot in the nix store for us, and we must fill it.
9494

@@ -148,7 +148,7 @@ And its `simple_builder.sh`:
148148
mkdir $out
149149
gcc -o $out/simple $src
150150

151-
Don't worry too much about where those variables come from yet; let's write the derivation and build it:
151+
Don't worry too much about where those variables come from yet; let's write the derivation and build it:
152152

153153
```
154154
nix-repl> :l <nixpkgs>
@@ -196,9 +196,9 @@ Now you can build it with `nix-build simple.nix`. This will create a symlink `re
196196

197197
nix-build does two jobs:
198198

199-
- [ nix-instantiate ](https://nixos.org/manual/nix/stable/command-ref/nix-instantiate.html): parse and evaluate `simple.nix` and return the .drv file corresponding to the parsed derivation set
199+
- [ nix-instantiate ](https://nixos.org/manual/nix/stable/command-ref/nix-instantiate.html): parse and evaluate `simple.nix` and return the .drv file corresponding to the parsed derivation set
200200

201-
- [ `nix-store -r` ](https://nixos.org/manual/nix/stable/command-ref/nix-store.html#operation---realise): realise the .drv file, which actually builds it.
201+
- [ `nix-store -r` ](https://nixos.org/manual/nix/stable/command-ref/nix-store.html#operation---realise): realise the .drv file, which actually builds it.
202202

203203
Finally, it creates the symlink.
204204

@@ -230,4 +230,4 @@ This syntax only makes sense inside sets. There's no magic involved, it's simply
230230

231231
We will generalize the builder. You may have noticed that we wrote two separate `builder.sh` scripts in this post. We would like to have a generic builder script instead, especially since each build script goes in the nix store: a bit of a waste.
232232

233-
*Is it really that hard to package stuff in Nix? No*, here we're studying the fundamentals of Nix.
233+
_Is it really that hard to package stuff in Nix? No_, here we're studying the fundamentals of Nix.

pills/08-generic-builders.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Darwin (i.e. macOS) builds typically use `clang` rather than `gcc` for a C compi
7171
}
7272

7373
Later, we will show how Nix can automatically handle these differences. For now, please be just aware that changes similar to the above may be needed in what follows.
74+
7475
</div>
7576

7677
Now build it with `nix-build hello.nix` and you can launch `result/bin/hello`. Nothing easier, but do we have to create a builder.sh for each package? Do we always have to pass the dependencies to the `derivation` function?
@@ -226,11 +227,11 @@ Then we rewrite `hello.nix` as follows:
226227

227228
Finally! We got a very simple description of a package! Below are a couple of remarks that you may find useful as you're continuing to understand the nix language:
228229

229-
- We assigned to pkgs the import that we did in the previous expressions in the "with". Don't be afraid, it's that straightforward.
230+
- We assigned to pkgs the import that we did in the previous expressions in the "with". Don't be afraid, it's that straightforward.
230231

231-
- The mkDerivation variable is a nice example of partial application, look at it as (`import ./autotools.nix`) `pkgs`. First we import the expression, then we apply the `pkgs` parameter. That will give us a function that accepts the attribute set `attrs`.
232+
- The mkDerivation variable is a nice example of partial application, look at it as (`import ./autotools.nix`) `pkgs`. First we import the expression, then we apply the `pkgs` parameter. That will give us a function that accepts the attribute set `attrs`.
232233

233-
- We create the derivation specifying only name and src. If the project eventually needed other dependencies to be in PATH, then we would simply add those to buildInputs (not specified in hello.nix because empty).
234+
- We create the derivation specifying only name and src. If the project eventually needed other dependencies to be in PATH, then we would simply add those to buildInputs (not specified in hello.nix because empty).
234235

235236
Note we didn't use any other library. Special C flags may be needed to find include files of other libraries at compile time, and ld flags at link time.
236237

pills/10-developing-with-nix-shell.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ This means that we can `source` our `builder.sh`, and it will build the derivati
3131

3232
The derivation didn't install, but it did build. Note the following:
3333

34-
- We sourced `builder.sh` and it ran all of the build steps, including setting up the `PATH` for us.
34+
- We sourced `builder.sh` and it ran all of the build steps, including setting up the `PATH` for us.
3535

36-
- The working directory is no longer a temp directory created by `nix-build`, but is instead the directory in which we entered the shell. Therefore, `hello-2.10` has been unpacked in the current directory.
36+
- The working directory is no longer a temp directory created by `nix-build`, but is instead the directory in which we entered the shell. Therefore, `hello-2.10` has been unpacked in the current directory.
3737

3838
We are able to `cd` into `hello-2.10` and type `make`, because `make` is now available.
3939

0 commit comments

Comments
 (0)