/mbp-nixos

Instructions and scripts related to getting NixOS running on a newer generation MBP

Primary LanguageNix

NixOS on MBP

This is a repo that will house notes and scripts related to getting NixOS running on a newer generation (late 2013+) MacBook Pro laptop (Retina).

There is currently no Linux driver for the Retina MBP webcam on the
newer generation laptops. So...there is that. Don't say I didn't
warn you.

Prerequisites

Get comfortable with the Nix package manager on OSX first.

To do that you should install Nix and set it up on Yosemite to work somewhat reasonably:

These scripts I wrote while trying to automate it myself, but probably aren’t great. Bug reports and patches welcomed. :)

Preparing Installation Media

Contrary to other reports on the internet (in the wild) you do not need to prerpare your bootable USB installer on another Linux distro.

I wrote the script bin/prepare-boot-drive-from-iso which could use some more testing by others (please file bugs if you come across them).

Before Installing

You will need to resize your OSX partition. I resized mine to 50Gb. I did this booting into the setup/rescue partition and using the disk utility from there.

You cannot resize the current root partition thus why you need to do this :)

Leave the rest as empty.

Stage1 Installer Workaround

Yeah, I know, we need a workaround already. On 14.12 installer you will likely encounter a problem with the device detected as the installer (i.e. it will not).

Basically it will choose /dev/sdc if it is already mounted as /dev/sdb or vice versa. And then inevitable fail.

Anyway, to get moving on this here is what I did:

Choose interactive shell to fix "/dev/sdc: No medium found" errors in stage 1.
Then the fix is the following:

* find proper device by `dmesg | grep 'logical blocks'` to find device for
  your USB drive. Say it is `/dev/sdb`.
* Now mount it at /mnt-root/iso: `mount /dev/sbd1 /mnt-root/iso`.

Preparing Partitions in Stage2

If you are unsure on how to configure your partitions, then I recommended the following basic setup (this is what I did):

$ sudo gdisk -l /dev/sda

GPT fdisk (gdisk) version 0.8.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 490234752 sectors, 233.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): XXXXXXXXXXXXXXXXXXXXXXXX
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 490234718
Partitions will be aligned on 8-sector boundaries
Total free space is 6 sectors (3.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640        98957655   47.0 GiB    AF05  Customer
   3        98957656       100227415   620.0 MiB   AB00  Recovery HD
   4       100227416       205085015   50.0 GiB    8300  nixosroot
   5       205085016       272193879   32.0 GiB    8200  nixosswap
   6       272193880       490234718   104.0 GiB   8300  nixoshome

I did this with the following commands after stage2 loaded in the NixOS installer:

# mkfs.ext4 -L nixosroot /dev/sda4
# mkswap -L nixosswap /dev/sda5
# mkfs.ext4 -L nixoshome /dev/sda6
# mount /dev/sda4 /mnt
# mount /dev/sda1 /mnt/boot

Make sure you mount /dev/sda1 under /mnt/boot. Then you can run: nixos-install

HTH

Configuration Post-Install

My /etc/nixos/configuration.nix for the MBP can be found at etc/nixos/configuration.nix.

Some parts of note that are required for the MBP are:

Boot Options

Use gummiboot. I got gummiboot working straight away.

{
  # Other stuff up here....

  boot.loader.grub.enable = false;
  boot.loader.gummiboot.enable = true;
  # I lowered this timeout because 4 seconds is too long for me
  boot.loader.gummiboot.timeout = 2;
  # Whether or not the installation process should modify EFI boot variables
  boot.loader.efi.canTouchEfiVariables = true;
  # If you rely on a dirty /tmp dir you are doing it wrong. Your laptop will
  # never be cattle.
  boot.cleanTmpDir = true;
  # This gets your audio output and input (mic) working
  boot.extraModprobeConfig = ''
    options libata.force=noncq
    options resume=/dev/sda5
    options snd_hda_intel index=0 model=intel-mac-auto id=PCH
    options snd_hda_intel index=1 model=intel-mac-auto id=HDMI
    options snd-hda-intel model=mbp101
    options hid_apple fnmode=2
  '';
  # because we are using the EFI mount for boot, which is small (tiny actually)
  # I switched these to false.
  boot.loader.generationsDir.enable = false;
  boot.loader.generationsDir.copyKernels = false;

  # other stuff down here
}

Other

TODO