all repos — gemini-redirect @ 12c4c2886f3cb8692493c92fde959f8561c5b8fd

content/blog/installing_nixos_2.md (view raw)

  1```meta
  2created: 2019-02-15
  3updated: 2019-02-16
  4```
  5
  6Installing NixOS, Take 2
  7========================
  8
  9This is my second take at installing NixOS, after a while being frustrated with Arch Linux and the fact that a few kernel upgrades ago, the system crashed randomly from time to time. `journalctl` did not have any helpful hints and I thought reinstalling could be worthwhile anyway.
 10
 11This time, I started with more knowledge! The first step is heading to the [NixOS website](https://nixos.org) and downloading their minimal installation CD for 64 bits. I didn't go with their graphical live CD, because their [installation manual](https://nixos.org/nixos/manual) is a wonderful resource that guides you nicely.
 12
 13Once you have downloaded their `.iso`, you should probably verify it's `sha256sum` and make sure that it matches. The easiest thing to do in my opinion is using an USB to burn the image in it. Plug it in and check its device name with `fdisk -l`. In my case, it was `/dev/sdb`, so I went ahead with it and ran `dd if=nixos.iso of=/dev/sdb status=progress`. Make sure to run `sync` once that's done.
 14
 15If either `dd` or `sync` seem "stuck" in the end, they are just flushing the changes to disk to make sure all is good. This is normal, and depends on your drives.
 16
 17Now, reboot your computer with the USB plugged in and make sure to boot into it. You should be welcome with a pretty screen. Just select the first option and wait until it logs you in as root. Once you're there you probably want to `loadkeys es` or whatever your keyboard layout is, or you will have a hard time with passwords, since the characters are all over the place.
 18
 19In a clean disk, you would normally create the partitions now. In my case, I already had the partitions made (100MB for the EFI system, where `/boot` lives, 40GB for the root `/` partition with my old Linux installation, and 700G for `/home`), so I didn't need to do anything here. The manual showcases `parted`, but I personally use `fdisk`, which has very helpful help I check every time I use it.
 20
 21**Important**: The `XY` in `/dev/sdXY` is probably different in your system! Make sure you use `fdisk -l` to see the correct letters and numbers!
 22
 23With the partitions ready in my UEFI system, I formatted both `/` and `/boot` just to be safe with `mkfs.ext4 -L nixos /dev/sda2` and `mkfs.fat -F 32 -n boot /dev/sda1` (remember that these are the letters and numbers used in my partition scheme). Don't worry about the warning in the second command regarding lowercase letters and Windows. It's not really an issue.
 24
 25Now, since we gave each partition a label, we can easily mount them through `mount /dev/disk/by-label/nixos /mnt` and, in UEFI systems, be sure to `mkdir -p /mnt/boot` and `mount /dev/disk/by-label/boot /mnt/boot`. I didn't bother setting up swap, since I have 8GB of RAM in my laptop and that's really enough for my use case.
 26
 27With that done, we will now ask the configuration wizard to do some work for us (in particular, generate a template) with `nixos-generate-config --root /mnt`. This generates a very well documented file that we should edit right now (and this is important!) with whatever editor you prefer. I used `vim`, but you can change it for `nano` if you prefer.
 28
 29On to the configuration file, we need to enable a few things, so `vim /mnt/etc/nixos/configuration.nix` and start scrolling down. We want to make sure to uncomment:
 30
 31```
 32# We really want network!
 33networking.wireless.enable = true;
 34
 35# This "fixes" the keyboard layout. Put the one you use.
 36i18n = {
 37consoleKeyMap = "es";
 38}
 39
 40# Timezones are tricky so let's get this right.
 41time.timeZone = "Europe/Madrid";
 42
 43# We *really* want some base packages installed, such as
 44# wpa_supplicant, or we won't have a way to connect to the
 45# network once we install...
 46environment.systemPackages = with pkgs; [
 47wpa_supplicant wget curl vim neovim cmus mpv firefox git tdesktop
 48];
 49
 50# Printing is useful, sure, enable CUPS
 51services.printing.enable = true;
 52
 53# We have speakers, let's make use of them.
 54sound.enable = true;
 55hardware.pulseaudio.enable = true;
 56
 57# We want the X11 windowing system enabled, in Spanish.
 58services.xserver.enable = true;
 59services.xserver.layout = "es";
 60
 61# I want a desktop manager in my laptop.
 62# I personally prefer XFCE, but the manual shows plenty
 63# of other options, such as Plasma, i3 WM, or whatever.
 64services.xserver.desktopManager.xfce.enable = true;
 65services.xserver.desktopManager.default = "xfce";
 66
 67# Touchpad is useful (although sometimes annoying) in a laptop
 68services.xserver.libinput.enable = true;
 69
 70# We don't want to do everything as root!
 71users.users.lonami = {
 72isNormalUser = true;
 73uid = 1000;
 74home = "/home/lonami";
 75extraGroups = [ "wheel" "networkmanager" "audio" ];
 76};
 77```
 78
 79*(Fun fact, I overlooked the configuration file until I wrote this and hadn't noticed sound/pulseaudio was there. It wasn't hard to find online how to enable it though!)*
 80
 81Now, let's modify `hardware-configuration.nix`. But if you have `/home` in a separate partition like me, you should run `blkid` to figure out its UUID. To avoid typing it out myself, I just ran `blkid >> /mnt/etc/nixos/hardware-configuration.nix` so that I could easily move it around with `vim`:
 82
 83```
 84# (stuff...)
 85
 86fileSystems."/home" =
 87{ device = "/dev/disk/by-uuid/d344c686-cae7-4dd3-840e-308eddf86608";
 88fsType = "ext4";
 89};
 90
 91# (more stuff...)
 92```
 93
 94Note that, obviously, you should put your own partition's UUID there. Modifying the configuration is where I think the current NixOS' manual should have made more emphasis, at this step of the installation. They do detail it below, but that was already too late in my first attempt. Anyway, you can boot from the USB and run `nixos-install` as many times as you need until you get it working!
 95
 96But before installing, we need to configure the network since there are plenty of things to download. If you want to work from WiFi, you should first figure out the name of your network card with `ip link show`. In my case it's called `wlp3s0`. So with that knowledge we can run `wpa_supplicant -B -i wlp3s0 -c <(wpa_passphrase SSID key)`. Be sure to replace both `SSID` and `key` with the name of your network and password key, respectively. If they have spaces, surround them in quotes.
 97
 98Another funny pitfall was typing `wpa_supplicant` in the command above twice (instead of `wpa_passphrase`). That sure spit out a few funny errors! Once you have ran that, wait a few seconds and `ping 1.1.1.1` to make sure that you can reach the internet. If you do, `^C` and let's install NixOS!
 99
100```
101nixos-install
102```
103
104Well, that was pretty painless. You can now `reboot` and enjoy your new, functional system.
105
106Afterword
107---------
108
109The process of installing NixOS was really painless once you have made sense out of what things mean. I was far more pleased this time than in my previous attempt, despite the four attempts I needed to have it up and running.
110
111However not all is so good. I'm not sure where I went wrong, but the first time I tried with `i3` instead of `xfce`, all I was welcome with was a white, small terminal in the top left corner. I even generated a configuration file with `i3-config-wizard` to make sure it could detect my Mod1/Mod4 keys (which, it did), but even after rebooting, my commands weren't responding. For example, I couldn't manage to open another terminal with `Mod1+Enter`. I'm not even sure that I was in `i3`112
113In my very first attempt, I pressed `Alt+F8` as suggested in the welcome message. This took me an offline copy of the manual, which is really nicely done. Funny enough, though, I couldn't exit `w3m`. Both `Q` and `B` to quit and take me back wouldn't work. Somehow, it kept throwing me back into `w3m`, so I had to forcibly shutdown.
114
115In my second attempt, I also forgot to configure network, so I had no way to download `wpa_supplicant` without having `wpa_supplicant` itself to connect my laptop to the network! So, it was important to do that through the USB before installing it (which comes with the program preinstalled), just by making sure to add it in the configuration file.
116
117Some other notes, if you can't reach the internet, don't add any DNS in `/etc/resolv.conf`. This should be done declaratively in `configuration.nix`.
118
119In the end, I spent the entire afternoon playing around with it, taking breaks and what-not. I still haven't figured out why `nvim` was printing the literal escape character when going from normal to insert mode in the `xfce4-terminal` (and other actions also made it print this "garbage" to the console), why sometimes the network can reach the internet (and only some sites!) and sometimes not, and how to setup dualboot.
120
121But despite all of this, I think it was a worth installing it again. One sure sees things from a different perspective, and gets the chance to write another blog post!
122
123If there's something I overlooked or that could be done better, or maybe you can explain it differently, please be sure to [contact me](https://lonami.dev/contact) to let me know!
124
125Update
126------
127
128Well, that was surprisingly fast feedback. Thank you very much [@bb010g](https://bb010g.keybase.pub/) for it! As they rightfully pointed out, one can avoid adding `/home` manually to `hardware-configuration.nix` if you mount it before generating the configuration files. However, the installation process doesn't need `/home` mounted, so I didn't do it.
129
130The second weird issue with `w3m` is actually a funny one. `Alt+F8` *switches to another TTY*! That's why quitting the program wouldn't do anything. You'd still be in a different TTY! Normally, this is `Ctrl+Alt+FX`, so I hadn't even thought that this is what could be happening. Anyway, the solution is not quitting the program, but rather going back to the main TTY with `Alt+F1`. You can switch back and forth all you need to consult the manual.
131
132More suggestions are having [`home-manager`](https://github.com/rycee/home-manager) manage the graphical sessions, since it should be easier to deal with than the alternatives.
133
134Despite having followed the guide and having read it over and over several times, it seems like my thoughts in this blog post may be a bit messy. So I recommend you also reading through the guide to have two versions of all this, just in case.
135
136Regarding network issues, they use `connman` so that may be worth checking out.
137
138Regarding terminal issues with `nvim` printing the literal escape character, I was told off for not having checked what my `$TERM` was. I hadn't really looked into it much myself, just complained about it here, so sorry for being annoying about that. A quick search in the `nixpkgs` repository lets us find [neovim/default.nix](https://github.com/NixOS/nixpkgs/blob/release-18.09/pkgs/applications/editors/neovim/default.nix), with version 0.3.1. Looking at [Neovim's main repository](https://github.com/neovim/neovim) we can see that this is a bit outdated, but that is fine.
139
140If only I had bothered to look at [Neovim's wiki](https://github.com/neovim/neovim/wiki/FAQ#nvim-shows-weird-symbols-2-q-when-changing-modes), (which they found through [Neovim's GitHub issues](https://github.com/neovim/neovim/issues/7749)) I would've seen that some terminals just don't support the program properly. The solution is, of course, to use a different terminal emulator with better support or to disable the `guicursor` in Neovim's config.
141
142This is a pretty good life lesson. 30 seconds of searching, maybe two minutes and a half for also checking XFCE issues, are often more than enough to troubleshoot your issues. The internet is a big place and more people have surely came across the problem before, so make sure to look online first. In my defense I'll say that it didn't bother me so much so I didn't bother looking for that soon either.