Artwork . Games

Install NixOS on a Macbook Air

November 13, 2014

WARNING THIS MIGHT DESTROY YOUR COMPUTER! DO NOT BLAME ME! BACKUP YOUR SYSTEM! WARNING

That being said, I have found installing and using NixOS to be a very rewarding experience. You should, however, read the manual because this guide might be out of date.

Resizing Disk

The first step is to partition your drive correctly. While in OS X:

  • Open Applications/Utilities/Disk Utility.
  • Choose the drive you want to partition.
  • Click the partition tab.
  • Click this plus sign to add a new partition.
  • Drag the slider to resize it.
  • Choose Free Space as the partition format.
  • Click Apply to save your changes.
  • Wait for the partitions to resize! (may take a while)

Obtaining NixOS

While that is happening, you can get your installation medium setup.

  • Download the correct ISO from nixos.org.
  • Burn the image to a USB drive using UNetbootin
  • MIGHT NOT BE NEEDED sudo diskutil rename THE_NAME_OF_YOUR_USB_DRIVE NIXOS_ISO
  • Restart and hold ALT while it loads, then choose EFI BOOT.
  • After the NixOS system boots up, log in with the ‘root’ username.

Networking

The installation depends on an internet connection, but thankfully it is relatively simple to configure. Run the commands:

  • wpa_passphrase ‘mynetwork’ ‘mysecretpassphrase’ | grep -v ‘#psk=“’ >> /etc/wpa_supplicant.conf
  • systemctl restart wpa_supplicant.service

Then wait about 10 seconds while it connects. You can ping www.google.com to make sure it is working.

Partitioning

Partitioning is probably the most daunting step of the process, but if you understand what you need, and what is going on, it is pretty straight forward.

You are going to need three partitions: ext4 at /, vfat at /boot, and swap. You should read up on and be comfortable with gdisk before moving on.

  1. Enter ‘n’ to create a new partition.
  2. Enter the number of the new partition (the default should work fine.)
  3. Press enter for the starting position on the desk.
  4. Enter the size of the partition (+128M means 128 megabytes from the start you chose.)
  5. Enter the partition code (ef00 is ‘EFI boot’, 8200 is ‘Linux swap’, and 8300 is ‘Linux filesystem’.)
  6. Enter the ‘w’ command at the main menu to write your changes to disk.
  7. Anytime you can quit and discard your changes with ‘q.’

You can list the drives using fdisk -l, and determine the one you want. It should almost 100% be ‘/dev/sda’. Now you can start gdisk:

  • gdisk /dev/sda
  • n -> 4 -> [press return] -> +512M -> ef00
  • n -> 5 -> [press return] -> +2G -> 8200
  • n -> 6 -> [press return] -> [press return] -> 8300
  • w -> Y

Now that your partitions are ready you will need to format and label them. In the last step, we put /boot on sda4, swap on sda5, and root on sda6. Change to fit your choices.

  • mkfs.vfat -F32 /dev/sda4
  • mkswap -L swap /dev/sda5
  • mkfs.ext4 -L nixos /dev/sda6
  • mount /dev/disk/by-label/nixos /mnt
  • swapon /dev/sda5
  • mkdir /mnt/boot
  • mount /dev/sda4 /mnt/boot

Your system is now mounted under /mnt.

Basic Setup

The configuration of NixOS is where most of the fun is. These initial steps are just here to get your system installed and working. Later sections will have more in-depth instructions on how to make your new OS more enjoyable to use.

First copy your network config to the drive:

  • cp /etc/wpa_supplicant.conf /mnt/etc/wpa_supplicant.conf

Then generate standard config files:

  • nixos-generate-config –root /mnt

Edit the two files that generated files:

  • nano /mnt/etc/nixos/configuration.nix
  • Uncomment hostName and wireless lines.
  • Add the following to unlock the closed-source Broadcom driver. nixpkgs.config = { allowUnfree = true; };
  • Setup your user (toward the bottom) and add the extraGroups = [ "wheel" ]; line in that group.
  • Save and exit.

  • nano /mnt/etc/nixos/hardware-configuration.nix

  • Remove quotes from around the broadcom line inside the [ ].

  • Add the following toward the bottom, substituting the partition you chose for /boot.

    fileSystems."/boot" =
    { device = "/dev/sda4";
    	  fsType = "vfat";
    	};
    
  • Save and exit.

Installation

And now for the moment you’ve been preparing for:

  • Run nixos-install.
  • Fix any errors in your config files and rerun.
  • reboot (You can hold alt to choose which OS to load!)
  • Login and add passwords for root and your user with ‘psswd.’

Configuration (THIS IS IN PROGRESS!)

The basic workflow is to modify your config and rebuild. You can check out the files I have included in the repo for examples.

  • sudo nano /etc/nixos/configuration.nix
  • sudo nixos-rebuild switch

Other Configs

I would not have been able to get this far without the config from puffnfresh. I will add more great nix setups here as I find them.

.xinitrc

I have included an .xinitrc that has some standard settings that should help with a few things.

  • Keyboard repeat
  • Setting the color profile
  • Adding a wallpaper
  • Swapping right ALT and right SUPER

Window Manager

I like to use i3 as my window manager. I have included my current configuration for that, but even if you want to use something else, toward the bottom are some keybindings for the brightness and volume controls. You can set up the same bindings in whatever window manager you choose. I am still working on the keyboard backlight brightness.

bindcode 232 exec xbacklight -dec 10
bindcode 233 exec xbacklight -inc 10

bindsym XF86AudioRaiseVolume exec amixer -q set Master 2dB+ unmute
bindsym XF86AudioLowerVolume exec amixer -q set Master 2dB- unmute
bindsym XF86AudioMute exec amixer -q set Master toggle

I will be updating the config for this with better support for displaying statistics like the time, battery level, volume, etc. For now, you can run acpi to see the battery level on the command line.

Better GTK theme

  • Extract a theme to ~/.themes
  • Edit the included .gtk-2.0 or use lxappearance to configure

Swap function and media keys

0 Function keys only, 1 is Media keys by default, and 2 is Function keys by default.

  • echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf

Terminal

I have found that Terminator is the easiest terminal to install and configure under NixOS. I have included my config for that.

Chromium

The change I would suggest beyond changing the GTK theme is to copy the supplied .fonts.conf file into your home directory, install the deja vu font family, and set Chrome to use them.

Swap Control and Caps on TTY

You can try to use the included keymap, and then:

  • Uncomment the i18n group changing consoleKeyMap = “[someplace]/Caps2Ctrl.map”;

If that doesn’t work you can always generate it with the following commands:

  • dumpkeys > [someplace]/Caps2Ctrl.map
  • Edit keycode 58 = Caps to Control