Configures NixOS/nix-darwin and Home Manager on my personal machines.
For Apple hardware I recommend running NixOS on either UTM or VMWare Fusion guests inside macOS (see instructions below). While nix-darwin and Home Manager on macOS work reasonably well most of the time, there are still some rough edges, e.g., macOS updates breaking your nix installation. Moreover, not all packages in nixpkgs support macOS. (See also https://discourse.nixos.org/t/darwin-again/29331). The best experience, in my opinion, is therefore running an honest-to-God NixOS on a VM hosted inside macOS. With UTM and VMWare Fusion we can have the best of both worlds. Indeed, both natively support Apple Silicon and their virtualization performance should be close to native when running ARM NixOS. Fusion even supports full 3D acceleration, if that is important to you.
After installing NixOS from a USB drive, follow these steps:
-
Clone this repo and
cdinto it. -
Copy
/etc/nixos/hardware-configuration.nixinto./system(OK to overwrite existing dummy file). -
Build and activate NixOS config:
sudo nixos-rebuild switch --flake .#thinkpad-x1 # the fragment can be dropped if it matches your current host name
# alternatively, using the `apps` provided by the flake:
sudo nix run .#rebuild-thinkpad-x1- Activate home-manager:
nix run .#hm-switch-thinkpad-x1On a ThinkPad X1 you might have to remove the line
hardware.video.hidpi.enable = lib.mkDefault true;
from hardware-configuration.nix if nixos-rebuild complains about this option having no effect.
(Inspired by this gist.)
To bootstrap a fresh macOS install, follow these steps:
- Install Homebrew (only needed for managing GUI apps via casks)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Install Nix:
curl -L https://nixos.org/nix/install | sh- Enable flakes
mkdir -p ~/.config/nix
cat <<EOF > ~/.config/nix/nix.conf
experimental-features = nix-command flakes
EOF- (Probably no longer needed.) To work around this issue
sudo mv /etc/nix/nix.conf /etc/nix/.nix-darwin.bkp.nix.conf- Clone this repo,
cdinto it, then build and activate:
nix run .#rebuild-macbook-pro-m1 # nix-darwin
nix run .#hm-switch-macbook-pro-m1 # home-manager- Uninstall Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
-
Delete everything under
~/.configand any other "dot files" in your home directory. -
Delete all applications that are listed as Homebrew casks in
./system/configuration-darwin.nix -
Follow the steps for a fresh macOS install.
-
Download the latest minimal NixOS ISO for either ARM (recommended for modern Macs with Apple silicon) or Intel:
-
Create a new VM in UTM as follows:
- select "Virtualize";
- select "Linux";
- check "Use Apple Virtualization";
- set boot image to the ISO downloaded in Step 1;
- set VM memory to at least half the memory of the host;
- set VM CPU cores to at least half the cores of the host;
- set the VM drive to a reasonable size (e.g., 256G);
- select the folders you want to share from host to guest (e.g., your home directory);
- save the new VM;
- edit the new VM to enable the NVMe interface on the main drive and disable sound under "Virtualization".
-
Start the VM and boot into the NixOS installer.
-
Use
passwdto set the password of thenixosuser (choose something simple likenixos) -
Note down the IP address of the guest by running
ip addr. -
On the host, execute
just bootstrap-mbp-utm <ip of guest>. You will be prompted for the password from Step 4. This installs NixOS onto the VM via SSH usingnixos-anywhere; it also builds and activates the Home Manager config. -
The VM should be ready to log into with your user and password (not the one in Step 5, of course). From now on simply use
just nixos-switchandjust hm-switchetc. inside the VM to make configuration changes.
(Inspired by https://github.com/mitchellh/nixos-config)
-
Download the latest minimal NixOS ISO for either ARM (recommended for modern Macs with Apple silicon) or Intel:
-
Create a new VM in VMware Fusion using the image above. Select "Other Linux 6.x Kernel ..." (current at time of writing).
-
Customize the VM settings as follows:
- Enable shared folders and add folders as desired (e.g., I like to share
~/Downloadsfrom host to guest). - Disable default applications.
- Create a keyboard & mouse profile where (almost) all key mappings and shortcuts are disabled. This creates the most immersive experience and avoids conflicts when working in the VM.
- Give at least half of the available CPU cores and RAM.
- Enable 3D hardware acceleration with max shared memory; enable full retina resolution.
- Set a reasonable disk size, e.g., 250GB.
- Remove the sound card and camera.
- Enable shared folders and add folders as desired (e.g., I like to share
-
Start the VM, select the NixOS installer from the boot menu and wait to be dropped into a shell as user
nixos. -
Set a simple password for the
nixosuser usingpasswd(I set it tonixos). It will only be used during installation. -
Note down the IP address of the guest using
ip addr. -
On the host, execute
just bootstrap-mbp-vmw <ip of guest>. You will be prompted for the password from Step 5. This installs NixOS onto the VM via SSH usingnixos-anywhere; it also builds and activates the Home Manager config. -
The VM should be ready to log into with your user and password (not the one in Step 5, of course). From now on simply use
just nixos-switchandjust hm-switchetc. inside the VM to make configuration changes.
- Do not regenerate
hardware-configuration.nixusingnixos-generate-configon the VM as the generated file will have conflicting settings for the file system, which is managed bydisko. (You can make it work by commenting out the file system settings.) Instead, keep the file that was copied during the bootstrap (but don't commit it). - You may have to set the display scaling in Gnome manually.
- If the
nix-configrepo copied during the bootstrap was set up to connect to the remote using http, you have to change it to ssh before being able to push:git remote set-url origin [email protected]:buntec/nix-config.git
Download the latest release from https://github.com/nix-community/NixOS-WSL/releases.
Double-click the nixos.wsl file to install.
Launch the distro from a Powershell with wsl -d NixOS.
Follow the instructions to update channels and rebuild/switch.
Create a nix shell with the required tools: nix-shell -p git vim just.
Clone this repo and do nixos-generate-config to generate /etc/nixos/hardware-configuration.nix.
Overwrite system/hardware-configuration with the generated config but remove all file system mounts.
Run sudo nix run .#rebuild-wsl-dark --experimental-features 'nix-command flakes'.
In Windows Terminal change the command line for the NixOS profile to C:\WINDOWS\system32\wsl.exe -d NixOS --user buntec.
Open a new NixOS tab (now correctly logged in as buntec instead of nixos).
Clone once more this repo and do just hm-switch to build and activate HM.