You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: pills/01-why-you-should-give-it-try.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Let's say you need an nginx service and also an nginx-openresty service. You hav
26
26
27
27
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.
28
28
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.
30
30
31
31
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.
32
32
@@ -36,7 +36,7 @@ And so on. Nix solves all this at the packaging level and solves it well. A sing
36
36
37
37
## Being purely functional
38
38
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.
40
40
41
41
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.
42
42
@@ -85,7 +85,7 @@ If there is a data format change, then migrating to the new data format remains
85
85
86
86
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/).
87
87
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.
89
89
90
90
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.
Copy file name to clipboardexpand all lines: pills/02-install-on-your-running.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ For installation instructions, please refer to the Nix Reference Manual on [ Ins
8
8
9
9
## Installation
10
10
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.
12
12
13
13
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.
14
14
@@ -50,7 +50,7 @@ Note: If this is the first time you're using Nix after the initial installation,
50
50
51
51
<divclass="warning">
52
52
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.
54
54
55
55
</div>
56
56
@@ -124,11 +124,11 @@ You can see for yourself, don't worry if you see multiple bash derivations:
124
124
125
125
Keeping the store in `/nix` means we can grab the binary cache from nixos.org (just like you grab packages from debian mirrors) otherwise:
126
126
127
-
-glibc would be installed under `/foo/store`
127
+
- glibc would be installed under `/foo/store`
128
128
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`
130
130
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.
132
132
133
133
After all `/nix` is a sensible place for the store.
Copy file name to clipboardexpand all lines: pills/03-enter-environment.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -28,13 +28,13 @@ Back to the installation:
28
28
29
29
Now you can run `hello`. Things to notice:
30
30
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.
32
32
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.
34
34
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.
36
36
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.
38
38
39
39
We can list generations without walking through the `/nix` hierarchy:
40
40
@@ -135,7 +135,7 @@ A nicer view of the closure:
135
135
$ nix-store -q --tree `which man`
136
136
[...]
137
137
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.
139
139
140
140
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`.
141
141
@@ -162,7 +162,7 @@ The first option is to rollback:
162
162
163
163
The second option is to install Nix, thus creating a new generation:
Copy file name to clipboardexpand all lines: pills/04-basics-of-language.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ Escaping `${...}` within double quoted strings is done with the backslash. Withi
106
106
107
107
## Lists
108
108
109
-
Lists are a sequence of expressions delimited by space (*not* comma):
109
+
Lists are a sequence of expressions delimited by space (_not_ comma):
110
110
111
111
nix-repl> [ 2 "foo" true (2+3) ]
112
112
[ 2 "foo" true 5 ]
@@ -201,7 +201,7 @@ This kind of expression is something you rarely see in other languages. You can
201
201
nix-repl> with longName; a + b
202
202
7
203
203
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:
Copy file name to clipboardexpand all lines: pills/05-functions-and-imports.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -115,13 +115,13 @@ That's it, you give a name to the whole parameter with name@ before the set patt
115
115
116
116
Advantages of using argument sets:
117
117
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.
119
119
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.
121
121
122
122
Disadvantages:
123
123
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.
125
125
126
126
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).
127
127
@@ -173,11 +173,11 @@ So how do we pass information to the module? Use functions, like we did with `mu
173
173
174
174
Explaining:
175
175
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`.
177
177
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.
179
179
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.
181
181
182
182
So when is the message shown? Only when it needs to be evaluated.
Copy file name to clipboardexpand all lines: pills/06-our-first-derivation.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,11 @@ That's where the real power comes in.
14
14
15
15
The `derivation` function receives a set as its first argument. This set requires at least the following three attributes:
16
16
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.
18
18
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.
20
20
21
-
-builder: is the binary program that builds the derivation.
21
+
- builder: is the binary program that builds the derivation.
22
22
23
23
First of all, what's the name of our system as seen by nix?
24
24
@@ -39,11 +39,11 @@ What's that `.drv` file? It is the specification of how to build the derivation,
39
39
40
40
Before continuing, some analogies with the C language:
41
41
42
-
-`.nix` files are like `.c` files.
42
+
-`.nix` files are like `.c` files.
43
43
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.
45
45
46
-
-out paths are then the product of the build.
46
+
- out paths are then the product of the build.
47
47
48
48
Both drv paths and out paths are stored in the nix store as you can see.
49
49
@@ -257,9 +257,9 @@ Nix does not build derivations **during evaluation** of Nix expressions. In fact
257
257
258
258
An important separation is made in Nix:
259
259
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).
261
261
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).
263
263
264
264
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.
Copy file name to clipboardexpand all lines: pills/07-working-derivation.md
+10-10
Original file line number
Diff line number
Diff 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
29
29
30
30
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.
31
31
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:
Let's inspect those environment variables printed during the build process.
82
82
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.
84
84
85
-
-`$PATH` plays the same game as `$HOME`
85
+
-`$PATH` plays the same game as `$HOME`
86
86
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)
88
88
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
90
90
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.
92
92
93
93
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.
94
94
@@ -148,7 +148,7 @@ And its `simple_builder.sh`:
148
148
mkdir $out
149
149
gcc -o $out/simple $src
150
150
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:
152
152
153
153
```
154
154
nix-repl> :l <nixpkgs>
@@ -196,9 +196,9 @@ Now you can build it with `nix-build simple.nix`. This will create a symlink `re
196
196
197
197
nix-build does two jobs:
198
198
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
200
200
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.
202
202
203
203
Finally, it creates the symlink.
204
204
@@ -230,4 +230,4 @@ This syntax only makes sense inside sets. There's no magic involved, it's simply
230
230
231
231
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.
232
232
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.
Copy file name to clipboardexpand all lines: pills/08-generic-builders.md
+4-3
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,7 @@ Darwin (i.e. macOS) builds typically use `clang` rather than `gcc` for a C compi
71
71
}
72
72
73
73
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
+
74
75
</div>
75
76
76
77
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:
226
227
227
228
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:
228
229
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.
230
231
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`.
232
233
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).
234
235
235
236
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.
Copy file name to clipboardexpand all lines: pills/10-developing-with-nix-shell.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -31,9 +31,9 @@ This means that we can `source` our `builder.sh`, and it will build the derivati
31
31
32
32
The derivation didn't install, but it did build. Note the following:
33
33
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.
35
35
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.
37
37
38
38
We are able to `cd` into `hello-2.10` and type `make`, because `make` is now available.
0 commit comments