diff options
| Commit | 49282fe2b4bcf3c6d0e394c817d5231f9e217dda (patch) | |
|---|---|---|
| Author | 2024-03-04 19:36:18 +0200 | |
| Committer | 2024-03-04 19:36:18 +0200 | |
| Files | 24b2d334cfab5df862d4ac82fef46b1a0c4cfa08 | |
| syndamia.com-49282fe2b4bcf3c6d0e394c817d5231f9e217dda.tar syndamia.com-49282fe2b4bcf3c6d0e394c817d5231f9e217dda.tar.gz syndamia.com-49282fe2b4bcf3c6d0e394c817d5231f9e217dda.zip | ||
| Parent | 3bb126f0ea52bf6c42ff6d569a83cf81ca5b4af0 (diff) | |
(blog/yfno) Added introduction and a little bit of explanation on the basic data types
1 files changed, 97 insertions, 0 deletions
| -rw-r--r-- | src/blog/your-first-nixos-config/index.md | 97 |
diff --git a/src/blog/your-first-nixos-config/index.md b/src/blog/your-first-nixos-config/index.md new file mode 100644 index 0000000..5c38fa2 --- /dev/null +++ b/src/blog/your-first-nixos-config/index.md @@ -0,0 +1,97 @@ +# Your first NixOS config + +With a single [whitepaper](https://edolstra.github.io/pubs/phd-thesis.pdf), Eelco Dolstra created a package management system like no other. +By going against many of UNIX's core ideals, he delivered the *objecitvely* best way to configure and conduct a Linux-based machine. +Though it's now without a price: the relatively steep learning curve. + +I believe this curve is only steep because of the less-than-stellar documentation and resources available online, but it doesn't have to be. + +## Motivation behind Nix + +Files on Linux are normally organized according to the [FHS](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), which forces executable programs to be put in `/bin` and `/usr/bin`, while libraries must live either in `/lib` or `/usr/lib`. +This system forces every binary and library to be "global", without much room for different versions of anything to exist at the same time. +In the days of old, this was perfectly fine, but in the modern era this ideal seems suffocating. + +As software programs have grown, so have their dependencies; before you would've needed less than a half-dozen libraries and external programs to create your application, but today that number can easily grow into the fifties for every-day executeables (like browsers). + +With an increased number of dependencies comes an increased amount of connectivity and inter-dependance between them. +As such, a minor misconfiguration or mismanagement of the hundreds of programs composing a modern system could easily form a crippling avalanche of unresolveable computer issues. + +Here Nix comes to the rescue: what if every application/library/configuration lived in it's own completely separate folder, and you could chose what you needed, depending on the situation? +Now you could have two (or more) applications with different versions of the same dependencies, coexisting together without issue. +By extension, you could store entirely different systems, with different application sets and their subsequent configurations, on the same machine and switch between them with a single "command"[^grub]. + +However, dependencies don't exist only when running an application, but also when building it! +And here we get another problem - modern build processes depend on a lot of "external" data, like special networked resources or global system information. +One may be tempted to just ignore it (with great success), though we would simply be offloading the issue to another part in our system. + +The solution is "binary bit-by-bit reproduceability": everything your applications have access to during the build process is strictly constrained and controled in a reproduceable manner, with the goal of creating the **exact** same program, for the same dependencies (managing even "external" ones), every time. + +## The Nix language + +To provide a generic, unified and extensible way to describe such systems, we need a new programming language: Nix. + +It is dynamically typed, so you could abstract a lot of details from the user, functional, so your code would be as clean and powerful as possible, without sacrificing performance. +But most importantly of all, Nix is lazy-evaluated, meaning nothing is executed, until something depends on it. + +The syntax itself is quite simple. + +### Primitive data types + +There are five of them: + +- Number, could be a whole integer or a floating point number. There is also support for fancier number format, like TODO + +- Boolean, with the values `true` and `false` + +- Null, which is the type of the value `null` + +- String, single-line string literals are done with double quotes: `"text"` + while multi-line are done with `''`: + + ```nix + '' + line1 + line2 + '' + ``` + +- Path, probably the most unique when compared to other languages. + Can be relative `./file.txt` or absolute `/usr/share/`. + +### Composite data types + +These are data types, which use other data types inside them: + +- List, a collection of items, each separated by a space and surrounded with square brackets: `[ value1 value2 value3 ]`. + You can freely mix data types, so `[ "a" 12 ./.. true null ]` is a completely valid list. + +- Attribute set, or more-commonly referred to as "hash-set" or "dictionary" in other languages. + Allows you to create a collection of items, but each item is identified with a String name. + + An attrset element is in the form `name = expression;` (don't forget the ending semicolumn!), and an attribute set is just a row of those, inside curly braces: + + ```nix + { name1 = expression1; name2 = expression2; name3 = expression3; } + ``` + + Accessing elements is done with a `.`, similar to objects in object-oriented languages: + + ```nix + { a = 12; }.a -> returns the number 12 + ``` + + Normally you can skip putting `"` around names inside attribute sets, but you must use them when the compiler can be confused: + + ```nix + { "=" = true; }."=" + ``` + +### Constructs + + +## The Nix package-manager + +## NixOS configurations + +[^grub]: In reality, if literally everything is different between those configurations, you would probably need to reboot and chose from your bootloader, but that's not significant now. |