diff options
Diffstat (limited to 'posts')
-rw-r--r-- | posts/nixOS.md | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/posts/nixOS.md b/posts/nixOS.md new file mode 100644 index 0000000..7e91f93 --- /dev/null +++ b/posts/nixOS.md | |||
@@ -0,0 +1,94 @@ | |||
1 | I have been eyeing operating systems with functional package | ||
2 | managers for a while now, aka, NixOS or Guix. Reproducible | ||
3 | builds, declarative and rollback-able system configuration, | ||
4 | system consistency, all sound pretty cool. I have been using | ||
5 | NixOS for about a month now. | ||
6 | |||
7 | ### Installation | ||
8 | |||
9 | I went with their minimal installation ISO. The installation | ||
10 | was pretty smooth from start to end, no hitches there. The | ||
11 | entire [manual](https://nixos.org/manual/nixos/stable/) is | ||
12 | available offline, and is accessible during the | ||
13 | installation. Very handy. | ||
14 | |||
15 | ### Setup | ||
16 | |||
17 | The entire system is configured via | ||
18 | `/etc/nixos/configuration.nix`. Wifi, `libinput` gestures, | ||
19 | audio, locale settings, there are options for literally | ||
20 | everything. You can declaratively write down the packages | ||
21 | you want installed too. With fresh installs of most distros, | ||
22 | I usually fumble with getting things like screen backlight | ||
23 | and media keys to work. If I do manage to fix it, I can't | ||
24 | carry it forward to future installations trivially. Getting | ||
25 | all my hardware to work on NixOS is as easy as: | ||
26 | |||
27 | ``` | ||
28 | { | ||
29 | server.xserver.libinput.enable = true; # touchpad | ||
30 | programs.light.enable = true; # backlight | ||
31 | hardware.pulseaudio.enable = true; # audio | ||
32 | networking.wireless.enable = true; # wifi | ||
33 | } | ||
34 | ``` | ||
35 | |||
36 | ### Developing with Nix | ||
37 | |||
38 | Nix makes it easy to enter environments that aren't affected | ||
39 | by your system configuration using `nix-shell`. | ||
40 | |||
41 | Builds may be generated by specifying a `default.nix` file, | ||
42 | and running `nix-build`. Conventional package managers | ||
43 | require you to specify a dependency list, but there is no | ||
44 | guarantee that this list is complete. The package will build | ||
45 | on your machine even if you forget a dependency. However, | ||
46 | with Nix, packages are installed to `/nix/store`, and not | ||
47 | global paths such as `/usr/bin/...`, if your project builds, | ||
48 | it means you have included every last one. | ||
49 | |||
50 | Issues on most my projects have been "unable to build | ||
51 | because `libxcb` is missing", or "this version of `openssl` | ||
52 | is too old". Tools like `cargo` and `pip` are poor package | ||
53 | managers. While they *can* guarantee that Rust or Python | ||
54 | dependencies are met, they make assumptions about the | ||
55 | target system. | ||
56 | |||
57 | For example, [this | ||
58 | website](https://github.com/nerdypepper/site) is now built | ||
59 | using Nix, anyone using Nix may simply, clone the repository | ||
60 | and run `./generate.sh`, and it would *just work*, while | ||
61 | keeping your global namespace clean™: | ||
62 | |||
63 | ```bash | ||
64 | #! /usr/bin/env nix-shell | ||
65 | #! nix-shell -i bash -p eva pandoc esh | ||
66 | |||
67 | # some bash magic ;) | ||
68 | ``` | ||
69 | |||
70 | Dependencies are included with the `-p` flag, the shell | ||
71 | script is executed with an interpreter, specified with the | ||
72 | `-i` flag. | ||
73 | |||
74 | ### Impressions | ||
75 | |||
76 | NixOS is by no means, simple. As a newcomer, using Nix was | ||
77 | not easy, heck, I had to learn a purely functional, lazy | ||
78 | language to just build programs. There is a lot to be | ||
79 | desired on the tooling front as well. A well fleshed out LSP | ||
80 | plugin would be nice ([rnix-lsp looks | ||
81 | promising](https://github.com/nix-community/rnix-lsp)). | ||
82 | |||
83 | Being able to rollback changes at a system level is cool. | ||
84 | Package broke something? Just `nixos-rebuild switch | ||
85 | --rollback`! Deleted `nix` by mistake? Find the binary in | ||
86 | `/nix/store` and rollback! You aren't punished for not | ||
87 | thinking twice. | ||
88 | |||
89 | I don't see myself switching to anything else in the near | ||
90 | future, NixOS does a lot of things right. If I ever need to | ||
91 | reinstall NixOS, I can generate an [image of my current | ||
92 | system](https://github.com/nix-community/nixos-generators). | ||
93 | |||
94 | [![](https://u.peppe.rs/6m.png)](https://u.peppe.rs/6m.png) | ||