I am indebted to Chris Martin's gist about installing NixOS from an Ubuntu live CD.
Unfortunately, the Ubuntu Live CD did not work for me, so I used Linux Mint's 21.1 live CD from a USB drive.
You'll need to partition the MacBook's internal storage device. You may want a different configuration than I did. I am keeping Mac OS on a smaller partition just because. So first: I booted into Mac OS to use Disk Utility to shrink the main Mac OS APFS partition, leaving over 100GB of empty space for the three partitions I'd be creating for NixOS in the next step.
Once I finished that, I booted into the Linux Mint USB. To do this:
- Restart the laptop, then hold the Option key during the boot sequence to get into the boot manager.
- Use the arrow keys to navigate to the USB drive, which probably has a name like "EFI".
Once booted, you can start the partitioning process. Start your favourite disk
partitioning program. If you don't do this that often, GParted is a GUI
tool that's easy to use and is included as part of the Linux Mint live USB. No
matter which program you choose (fdisk
would be a great CLI tool!), you'll
likely want three partitions on the internal storage device:
- Name:
boot
Filesystem:fat
Size: 500MB
Flags:boot
,esp
- Name:
swap
Filesystem:linux-swap
Size: The amount of RAM your laptop has + 2GB - Name:
root
Filesystem:ext4
Size: Remaining empty space
Ensure that you save the partition map before exiting your partitioning program.
And take note of the locations of your new partitions. Mine were at locations
like: /dev/nvme0n1p3
and p5
, but yours may look different (i.e. /dev/sda1
,
/dev/sda2
, or similar). Also take note of which location is which partition,
as this will be important.
Now that we've successfully partitioned the storage device, it's time to
install. Open a terminal and enter a rooted shell environment by typing sudo bash
.
Go to the NixOS download page in a web browser and copy the link for the version of NixOS you need. I'm using the GNOME, 64-bit Intel/AMD version.
In your terminal, paste the URL as an argument to wget
to download the ISO to
the current directory:
wget \
https://channels.nixos.org/nixos-22.11/latest-nixos-gnome-x86_64-linux.iso \
nixos.iso
You'll also want a matching release of nixpkgs. In this case, I've downloaded an
ISO for 22.11
, so I'll navigate [to NixOS/nixpkgs
release tags on
GitHub][nixpkgs] and copy the location to the zipped release archive and wget
that as well:
wget https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.zip \
nixpkgs-22.11.zip
Mount the ISO:
mkdir nixos
mount -o loop nixos.iso nixos
Extract the Nix store so we can use some of the provided executables in a moment:
mkdir /nix
unsquashfs -d /nix/store nixos/nix-store.squashfs
Find the executables we need and ensure they're in the executables PATH
:
INSTALL=$(find /nix/store -path "*-nixos-install/bin/nixos-install")
INSTANTIATE=$(find /nix/store -path "*-nix-*/bin/nix-instantiate")
GENERATE_CONFIG=$(find /nix/store -path "*-nixos-generate-config/bin/nixos-generate-config")
export PATH="$(dirname $INSTALL):$(dirname $INSTANTIATE):$(dirname $GENERATE_CONFIG):$PATH"
Create the build group and build user:
groupadd --system nixbld
useradd --system \
--home-dir /var/empty \
--shell $(which nologin) \
-g nixbld \
-G nixbld nixbld0
Unzip the nixpkgs repository we downloaded ealier and construct the NIX_PATH
:
unzip nixpkgs-22.11.zip
mv nix-pkgs-* nixpkgs
export NIX_PATH=nixpkgs=/home/root/nixpkgs
Mount our partitions so we can copy stuff to them:
mount <your-root-partition> /mnt
mkdir /mnt/boot
mount <your-boot-partition> /mnt/boot
Copy the Nix store from the ISO to your root partition's root nix/
directory:
mkdir /mnt/nix
unsquashfs -d /mnt/nix/store nixos/nix-store.squashfs
If everything above worked, you should be able to successfully generate config and use the installer script:
nixos-generate-config --root /mnt
nixos-install --root /mnt