This is my personal Nix system configuration. Mostly I use this to manage my environments for my Mac systems using nix-darwin; however, I have also experimented with creating developer NixOS VMs that run on Parallels (see below).
Generally speaking, the configuration of the host and home environment are separated such that we can define, build and apply these configs separately.I find that I need to more frequently update home configs that host configs, so I think it's useful to separate them.
These configs use Nix flakes.
The structure of this repo was inspired by the excellent Misterio77/nix-config repo, though the two repos have subsequently diverged.
- Install Nix:
sh <(curl -L https://nixos.org/nix/install)
Note: this has only really been tested for multi-user installation.
- Enable flakes:
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
- Bootstrap/install nix-darwin and home-manager:
nix-darwin:
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
./result/bin/darwin-installer
home-manager (standalone):
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
- Clone this repo:
git clone git@github.com:keithschulze/nixos-config.git
- Build and apply host config
darwin-rebuild switch --flake .#matawhero
note: in this case we are applying the matawhero
host configuration as
an example. Other hosts are/can be defined in flake.nix
.
- Build and apply the home configuration
home-manager switch --flake .#keithschulze@matawhero
note: in this case we are applying the keithschulze@matawhero
home configuration as an
example. Other home configrations are/can be defined in flake.nix
.
In order to update packages, we need to update the locked versions:
nix flake update
Before applying or committing this, we should check that it builds correctly with update versions:
darwin-rebuild build --flake .#matawhero
home-manager build --flake .#keithschulze@matawhero
Note: this example only builds host and home configs for a single host and user. We should do this for all that matter.
This is my NixOS Parallels developer VM setup. This is adapted from Mitchell Hashimoto's excellent NixOS VM repo.
If you need an ISO for NixOS, you can build your own in the iso
folder.
For x86-64, I usually just download the official ISO, but I build the
ISO from scratch for aarch64. There is a make target iso/nixos.iso
you can use for
building an ISO. You'll also need a docker
running on your machine for building an ISO.
$ make iso/nixos.iso
Create a Parallels VM with the following settings:
- ISO: NixOS 21.05 or later.
- Disk: SATA 150 GB+
- CPU/Memory: I give at least half my cores and half my RAM, as much as you can.
- Graphics: Full acceleration, full resolution, maximum graphics RAM.
- Network: Shared with my Mac.
- Remove sound card, remove video camera.
- Profile: Disable almost all keybindings
Boot the VM, and using the graphical console, change the root password to "root":
$ sudo su
$ passwd
# change to root
Run ifconfig
and get the IP address of the first device. It is probably
192.168.58.XXX
, but it can be anything. In a terminal with this repository
set this to the NIXADDR
env var:
$ export NIXADDR=<VM ip address>
Perform the initial bootstrap. This will install NixOS on the VM disk image but will not setup any other configurations yet. This prepares the VM for any NixOS customization:
$ make vm/bootstrap0
After the VM reboots, this is usually a good time to take a VM Snapshot because you might want to return to this point while you stuff around with configs. Run the full bootstrap, this will finalize the NixOS customization using this configuration:
$ make vm/bootstrap
At this point, the core will be setup; however, you still need to run
home-manager
to setup the full Desktop environment. Boot the VM and jump into /nix-config
. Run nix develop
and then home-manager switch --flake .