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: articles/how-i-would-learn-nix-if-i-could-do-it-again.md
+29-24Lines changed: 29 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -8,38 +8,41 @@ prev:
8
8
9
9
# NixOS and Home Manager
10
10
11
-
If declaratively defining your user environment, hell, your complete operating system, sounds like a joy to you, then Nix is the tool for you. While I could go at length about what nix is™ or go off on a tangent about how poorly documented™ it is, many have gone before me. If that is the kind of content you are looking for then this is not the article for you. I'll only briefly touch on those subjects before taking you along for a ride, after which I hope you will be able to take the wheel and ride off into the sunset by yourself. Albeit with a sidecar or a pair of training wheels.
11
+
If declaratively defining your complete operating system and user environment sounds like a joy to you, then Nix is the tool for you. There is a bit of a learning curve but in this blog post I'll try to make that as smooth as possible for you. Lets go for a ride, a learning how to learn, after which you'll be able to take the wheel and ride off into the sunset by yourself. Albeit with a sidecar or a small set of training wheels.
12
12
13
-
## What is this Nix you speak of?
13
+
## What's this Nix you speak of?
14
14
15
-
If you are reading this then chances are you are somewhat familiar but struggling to find your way around the ecosystem. On the off chance that you stumbled upon my blog some other way, I will briefly go over the basics:
15
+
If you are reading this then chances are you are somewhat familiar but struggling to find your way around the ecosystem. On the off chance that you stumbled upon this blog some other way, I'll briefly go over the basics:
16
16
17
-
In a nutshell, Nix is a deployment system dreamed up by Eelco Dolstra et al. back in 2004. It was created to deal with some of the issues that arise when distributing and building software across different machines and operating environments.
17
+
In summary, Nix is a deployment system dreamed up by Eelco Dolstra et al. back in 2004 to deal with some of the issues that arise when distributing and building software across different machines and operating environments.
18
18
19
-
It's a tool and functional programming language used to package up software into what Nix calls `derivations`. A derivation is a higher order package that bundles everything that is required to idempotently build a piece of software. If you want to learn more about the issues Nix set out to solve and how it works at this particular layer of the cake, I would recommend you give [the abstract of their master thesis](https://edolstra.github.io/pubs/nspfssd-lisa2004-final.pdf) a read.
19
+
It's a tool and functional programming language used to package up software into what Nix calls `derivations`. A derivation is a higher order package that bundles everything that's required to purely build a piece of software. If you want to learn more about the issues Nix set out to solve and how it works at this particular layer of the cake, I highly recommend that you read through [the abstract of their master thesis](https://edolstra.github.io/pubs/nspfssd-lisa2004-final.pdf).
20
20
21
-
What often confuses newcomers is that there is also a Nix based Linux distribution aptly named NixOS. What Nix does, that is building, packaging and distribution of software is essentially all that is needed for and handled by your average bare metal Linux distribution. That someone would eventually come along and package those derivations and modules up into a Linux installer was only a matter of time.
21
+
What often confuses newcomers is that there is also a Nix based Linux distribution aptly named NixOS. Nix builds, packages, and distributes software which is essentially everything needed for and handled by your average bare metal Linux distribution. That someone would eventually come along and package those derivations and modules up into a handy Linux installer was only a matter of time.
22
22
23
-
## Looking for a Quick Fix?
23
+
## Looking for a quick fix?
24
24
25
-
The way Nix works is a bit of a paradigm shift and that's one of the reasons people have a hard time getting into it. Another is the somewhat abysmal state of its documentation. While attempts are on the way to improve upon that, information on how Nix works is still scattered across different websites and wikipedia pages. For those of you with shorter attention spans, these are the resources I will recommend you go through in this article:
25
+
The way Nix works is a bit of a paradigm shift and that's one of the reasons people have a hard time getting into it. Another is the somewhat abysmal state of its documentation. While attempts are on the way to improve upon that, information on how Nix works is still scattered across different websites and Wikipedia pages. For those of you with shorter attention spans, these are the resources I'll recommend you go through in this article. Don't bother with other websites:
26
26
27
-
1.https://nix.dev - Take your first steps here. Don't get lost on Nix Pills or some other obscure website.
28
-
1.https://nix.dev/manual/nix - For when you want to dive deeper.
29
-
1.https://nixos.org/manual/nixos/stable - For those who want to run NixOS.
30
-
1.https://nix-community.github.io/home-manager - For your cross platform dotfiles.
31
-
1.https://mynixos.com - For finding existing packages and their configuration options.
32
-
1.https://github.com/NixOS/nixpkgs - The Nix package repository where the work on all derivations is done.
33
-
1.https://wiki.nixos.org/wiki/NixOS_Wiki - The official wiki (sadly sometimes still outdated compared to the community maintained wiki)
27
+
1.<https://nix.dev> - Take your first steps here. Don't get lost on Nix Pills or some other obscure website.
28
+
1.<https://nix.dev/manual/nix> - For when you want to dig deeper.
29
+
1.<https://nixos.org/manual/nixos/stable> - For those who want to run NixOS.
30
+
1.<https://nix-community.github.io/home-manager> - For managing your user environment separately.
31
+
1.<https://mynixos.com> - For finding existing packages and their configuration options.
32
+
1.<https://github.com/NixOS/nixpkgs> - The Nix package repository where the work on all derivations takes place.
33
+
1.<https://wiki.nixos.org/wiki/NixOS_Wiki> - The official wiki
34
+
35
+
Check these sources first, then consider alternatives such as the community maintained Wikipedia (which is in the process of being phased out).
34
36
35
37
## A four-step plan to learning Nix
36
38
37
39
### Learn to read the syntax
38
40
39
-
It's a lot and you will want to take a methodical approach to learning. If you are just starting out I would advise against diving deep into Nix shells or the way packaging and building derivations work. It's valuable knowledge but at this stage it's more important that you are able to read the language itself. Start by going over the [language basics](https://nix.dev/tutorials/nix-language) so you have an idea of what it is you are looking at when writing your first `configuration.nix` or `flake.nix`.
41
+
It's a lot and you'll want to take a methodical approach to learning. If you are just starting out avoid diving deep into Nix shells or the way packaging and building derivations work. It's valuable knowledge but at this stage it's more important that you are able to read the language itself. Start by going over the [language basics](https://nix.dev/tutorials/nix-language) so you have an idea of what it's you are looking at when writing your first `configuration.nix` or `flake.nix`.
42
+
43
+
### Go over the configuration syntax and module system
40
44
41
-
### Go over the Configuration Syntax and Module System
42
-
Many of the examples or repositories you will be referencing and drawing inspiration from can be a bit intimidating and will often contain custom code, use nix flakes or depend on other libraries to extend functionality. If you don't understand how Nix ties all of this together you will quickly get lost. Spend some time learning about the [configuration syntax](https://nixos.org/manual/nixos/stable/#sec-configuration-syntax) and [the Nix module system](https://nix.dev/tutorials/module-system).
45
+
Many of the examples or repositories you will be referencing and drawing inspiration from can be a bit intimidating and will often contain custom code, use nix flakes or depend on other libraries to extend it's functionalities. If you don't understand how Nix ties all of this together you'll quickly get lost. Spend some time learning about the [configuration syntax](https://nixos.org/manual/nixos/stable/#sec-configuration-syntax) and [the Nix module system](https://nix.dev/tutorials/module-system).
43
46
44
47
In summary, assuming you understand what an attribute set is, Nix modules consist of functions taking a single attribute set as a parameter and returning an attribute set adhering to a specific schema:
45
48
@@ -54,12 +57,14 @@ In summary, assuming you understand what an attribute set is, Nix modules consis
54
57
};
55
58
}
56
59
```
60
+
57
61
### Use Nix to configure a well-known application
58
-
Since Nix has the largest package repository in the world, chances are your favorite piece of software is already packaged up into a derivation and actively being maintained. See if you can find it by searching for it on [MyNixOS](https://mynixos.com). As an example, I will use my favorite shell, Zsh:
62
+
63
+
Since Nix has the largest package repository in the world, chances are your favorite piece of software is already packaged up into a derivation and actively being maintained. See if you can find it by searching for it on [MyNixOS](https://mynixos.com). As an example, lets take a look at the Unix shell, Zsh:
In the screenshot above you can see that Zsh exists as a derivation (`nixpkgs/package/zsh`) in the nixpkgs package repository as well as a Nix Module (`nixpkgs/option/programs.zsh`). Oftentimes there already exists a Nix module to simplify configuring the application and abstracting away any complexities that may be involved with it. To use the Zsh module we can simply enable it as follows:
67
+
In the screenshot above you can see that Zsh exists as a derivation (`nixpkgs/package/zsh`) as well as a Nix Module (`nixpkgs/option/programs.zsh`). Oftentimes a Nix module already exists to simplify configuring the application and abstracting away any complexities that may be involved with it. To use the Zsh module lets enable it as follows:
63
68
64
69
```nix
65
70
{...}:
@@ -86,18 +91,18 @@ Clicking through MyNixOS provides additional information about the `enable` modu
Once you feel you are somewhat comfortable with the Nix language and you understand how the module system works, you should definitely take a look at some of these module files in the nixpkgs repository. You'll likely find them surprisingly straightforward to understand. Especially when you have configured a couple of applications and built a module yourself!
94
+
Once you feel you are somewhat comfortable with the Nix language and you understand how the module system works, you should definitely take a look at some of these module files in the `nixpkgs` repository. You'll likely find them surprisingly straightforward to understand. Especially when you have configured a couple of applications and built a module yourself.
90
95
91
96
### Learn how to package an application
92
97
93
-
Go ahead and dive into the [First Steps](https://nix.dev/tutorials/first-steps/) learning about nix shells and [packaging existing software with Nix](https://nix.dev/tutorials/packaging-existing-software). Once you are done working through those guides you should find that almost all the puzzle pieces have fallen into place.
98
+
Go ahead and read through the [First Steps](https://nix.dev/tutorials/first-steps/) learning about nix shells and [packaging existing software with Nix](https://nix.dev/tutorials/packaging-existing-software). Once you have worked through those guides you should find that almost all the puzzle pieces have naturally fallen into place.
94
99
95
100
## Home Manager
96
101
97
-
Home Manager is a tool created by the Nix community to specifically manage your user's home directory, separately from your OS. It provides an additional set of Nix modules specifically dedicated to managing your user programs, configuration files, environment variables, etc. At its core, it's just Nix, built on top of Nix and the very module system you have since become familiar with. It's just wired up a little differently. For more information, [check out the official documentation](https://nix-community.github.io/home-manager).
102
+
Home Manager is a tool created by the Nix community to specifically manage your user's home directory, separately from your OS. It provides an additional set of Nix modules specifically dedicated to managing your user programs, configuration files, environment variables, etc. At its core, it's just Nix, built on top of Nix and the module system you have since become familiar with. It's just wired up a little differently. For more information, [check out the official documentation](https://nix-community.github.io/home-manager).
98
103
99
104
## Still here? Impressive
100
105
101
-
That's it. You should now be able to take your bike off that kickstand and go for a ride all on your own. If you are craving some more inspiration, you are welcome to take a look at my humble [NixOS](https://github.com/99linesofcode/nixos-config) and [Home Manager](https://github.com/99linesofcode/home-manager) repositories. They are heavily inspired by the work of others and still very much a work in progress but perhaps you can find some use for them.
106
+
That's it. You should now be able to take your bike off that kickstand and go for a ride all on your own. If you are craving some more inspiration, you are welcome to take a look at my humble [NixOS](https://github.com/99linesofcode/nixos-config) and [Home Manager](https://github.com/99linesofcode/home-manager) repositories. They're heavily inspired by the work of others and still a work in progress but perhaps you can find some use for them.
0 commit comments