A convenience flake for configuring your machine using nix-darwin and home-manager.
- Determinate Nix Installer (recommended)
- Official Nix Installer
See the motivations section of the Determinate Nix Installer section of the for more details.
Create a new configuration by running the following command:
nix flake new --template .#simple-macos nixos-config
This will create a new directory named nixos-config
with the contents of templates/simple-macos. This template is perfect if you're just starting out or have just one machine that you wish to configure.
You must update the nix-machine
configuration in flake.nix
:
{
nix-machine.macos."hostname" = {
nix-machine = {
username = "username";
homeDirectory = "/Users/username";
nixpkgs.hostPlatform = "aarch64-darwin";
shells.zsh.enable = true;
};
};
}
Guidance:
hostname
is the name of your machine. It can be any name you choose, but it is convenient to use the hostname of your machine.username
must be set to your username. For the current user this is the value of$USER
.homeDirectory
must be set to your user's home directory. For the current user this is the value of$HOME
.nixpkgs.hostPlatform
must be set to either:aarch64-darwin
for apple sillicon.x86_64-darwin
for intel based macs.
shells.zsh.enable
keep this as true if you wish to use zsh. If not, remove this line and add your own shell configuration. Other shells are not yet supported innix-machine
.
The following command will build the flake and apply it to your machine. If nix-darwin
or home-manager
ask you to backup any files, follow the instructions and rename them. Then run the command again.
If you used your current machine's hostname as the machine name you can run:
# Replace hostname with the name of your machine:
nix run nix-darwin --extra-experimental-features "nix-command flakes" -- switch --flake .#hostname
# Can be used if you named your machine the same as your hostname
nix run nix-darwin --extra-experimental-features "nix-command flakes" -- switch --flake .#"$(hostname -s)"
Restart your shell session.
You can now slowly iterate on your configuration by adding nix-darwin
and home-manager
configuration. After adding new configuration, you'll need to apply the configuration by running the above command again.
- Configure nix-darwin options in
configuration/nix-darwin
. - Configure home-manager options in
configuration/home-manager
.
My nixos-config can be used as an example.
- Reduce boilerplate by providing sensible default values for nix, nixpkgs, nix-darwin and home-manager.
- Encourage nix-darwin and home-manager configuration re-use. Share configurations between your own machines, and optionally expose it as a flake module to share with others.