89 lines
4.3 KiB
Plaintext
89 lines
4.3 KiB
Plaintext
%% title = "derive me some Nix"
|
|
|
|
% id = "01J31356Q1A4Z54F3G7THB1C81"
|
|
- chances are you've heard about Nix or NixOS from somewhere and would like to learn more about it.
|
|
|
|
% id = "01J31356Q1AQE7ZBE2P7FG03G4"
|
|
- if that is the case, welcome to the club!
|
|
we're pretty much in the same bucket.
|
|
I literally just started using Nix a couple days ago, and I found the documentation *really* unclear.
|
|
so here's my shot at a more pedagogical approach.
|
|
|
|
% id = "01J31356Q1N80MYK77MP3BMJ1E"
|
|
- if that's not the case - Nix is a package manager and system configuration language.
|
|
basically, you specify how you want your system to look using config files stored in one place, and Nix _derives_ the system from that config file for you!
|
|
|
|
% id = "01J31356Q13VHG7EN0Q24A6GSM"
|
|
- I emphasized the word _derives_, because _derivation_ is the fundamental operation of Nix the package manager.
|
|
your entire config is specified declaratively, and the entire folder structure and all configuration files are _derived_ from that config.
|
|
but we'll get to that shortly.
|
|
|
|
% id = "01J31356Q1G1X5X9Q7BPDT41R5"
|
|
- people seem to be excited about Nix for many reasons.
|
|
I'm excited because it helps me achieve *online independence.*
|
|
|
|
% id = "01J31356Q12T9Z1WE300PD7J79"
|
|
- did you know that since last weekend (since this was written) this website runs on NixOS?
|
|
|
|
% id = "01J31356Q1KM0TT28D4PHZTAR9"
|
|
- being able to take your VPS's configuration elsewhere and let Nix cook your system up automatically is extremely cool.
|
|
it's something that's always frustrated me with how Linux software is configured -
|
|
lots of little configuration files scattered across `/etc` and sometimes other directories, which ends up being extremely hard to replicate if you ever want to switch server providers.
|
|
|
|
% id = "01J31356Q1D0SJPJB1V4MYPNX9"
|
|
- *and* your system config will end up identical to the one you had before!
|
|
isn't that awesome?
|
|
|
|
% id = "01J31356Q1BNSAF75KDE4PN2PJ"
|
|
- word of warning though: I wouldn't recommend running NixOS on a home PC.
|
|
|
|
% id = "01J31356Q1C13GSD9KSXETWW1B"
|
|
- I use :btw: on my home PC for a very simple reason.
|
|
it's just _really darn simple_ to change anything about my system.
|
|
|
|
% id = "01J31356Q1JZ13FY2XAVVKAN97"
|
|
- need to install a new package? `pacman -S`.
|
|
|
|
% id = "01J31356Q1VJ0HFQYVS1AE7CZB"
|
|
- need to edit system config?
|
|
well first of all no you don't, because other than fundamental config you change during installation, we both know Arch works pretty much works out of the box on your PC,
|
|
but even if you _do_ end up needing to change some config for a workaround, it's generally only because you need a _workaround_ - which may not be needed by the time you reinstall your system.
|
|
|
|
% id = "01J31356Q162ACZG4S6M9YNQX2"
|
|
- and reinstall your OS pretty rarely.
|
|
|
|
% id = "01J31356Q1ZXDA6QX5P978FTPS"
|
|
- most of your _important_ configuration is stored in `$HOME` y'know, and that's easy to keep between reinstalls - you have a separate `/home` partition after all.
|
|
|
|
% id = "01J31356Q1KYMMG64D3TNXH3C5"
|
|
- :btw: is also Really Darn Fast.
|
|
I can't say that about NixOS.
|
|
the package manager is excruciatingly slow to update your system config.
|
|
the initial install took _really_ long for how barebones of a system I specified in my config.
|
|
|
|
% id = "01J31356Q1CA21R7GM9MXGQ7Q4"
|
|
- let's derive us a system! as I mentioned before, everything in Nix is achieved by means of _derivations_.
|
|
|
|
% id = "01J31356Q191D3J645CT75YFEJ"
|
|
- from a programming perspective, a derivation is simply a function `options -> path`, where `options` is an attribute set specifying how the output `path` should be derived.
|
|
|
|
% id = "01J31356Q1PRWPYD0EGGY1ZK3W"
|
|
- and that's *it*.
|
|
|
|
% id = "01J31356Q1445NB18CNBE91CZP"
|
|
- suppose you'd like to download a file from the Internet.
|
|
that's what the `pkgs.fetchurl` function is for.
|
|
|
|
```nix
|
|
# This expression results in a path to the downloaded file.
|
|
pkgs.fetchurl {
|
|
url = "https://liquidex.house";
|
|
# As long as you fill in the hash, which I don't know...
|
|
# Nix will tell you what it should be though!
|
|
hash = "";
|
|
}
|
|
```
|
|
|
|
% id = "01J31356Q1HEW2HCTG27BDFJM2"
|
|
- but where does `pkgs` even come from?
|