1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00
nix modules for darwin
Find a file
2024-11-21 11:07:47 +11:00
.github examples: change default architecture to aarch64-darwin 2024-11-21 11:07:47 +11:00
doc manualHTML: support --redirects option in nixos-render-docs 2024-11-17 14:19:36 -07:00
modules examples: change default architecture to aarch64-darwin 2024-11-21 11:07:47 +11:00
pkgs installer: remove 2024-11-21 11:07:47 +11:00
tests activate-system: remove enable option 2024-11-15 14:10:48 +11:00
.gitignore Add workflow to auto-update manual 2022-03-22 10:31:55 -07:00
CHANGELOG {ids,checks}: update for new builder UID/GID values 2024-09-11 01:17:01 +01:00
default.nix installer: remove 2024-11-21 11:07:47 +11:00
eval-config.nix Reapply "eval-config: set class" 2024-06-13 14:35:20 +01:00
flake.lock flake.lock: update 2024-06-13 14:33:45 +01:00
flake.nix manual: get revision information when called from flake 2024-11-09 19:46:07 +11:00
LICENSE add license 2017-07-19 20:53:33 +02:00
README.md readme: update Documentation section 2024-11-21 11:07:47 +11:00
release.nix manual: get revision information when called from flake 2024-11-09 19:46:07 +11:00

logo

nix-darwin

Test

Nix modules for darwin, /etc/nixos/configuration.nix for macOS.

This project aims to bring the convenience of a declarative system approach to macOS. nix-darwin is built up around Nixpkgs, quite similar to NixOS.

Prerequisites

The only prerequisite is a Nix implementation, both Nix and Lix are supported.

As the official Nix installer does not include an automated uninstaller, and manual uninstallation on macOS is a complex process, we recommend using one of the following installers instead:

  • The Nix installer from Determinate Systems is only recommended for use with flake-based setups. Make sure you use it without the --determinate flag. The --determinate flag installs the Determinate Nix distribution which does not work out of the box with nix-darwin.
  • The Lix installer supports both flake-based and channel-based setups.

Getting started

Despite being an experimental feature in Nix currently, nix-darwin recommends that beginners use flakes to manage their nix-darwin configurations.

Flakes (Recommended for beginners)

Step 1. Creating flake.nix

Getting started from scratch

If you don't have an existing configuration.nix, you can run the following commands to generate a basic flake.nix inside ~/.config/nix-darwin:

mkdir -p ~/.config/nix-darwin
cd ~/.config/nix-darwin
nix flake init -t nix-darwin
sed -i '' "s/simple/$(scutil --get LocalHostName)/" flake.nix

Make sure to change nixpkgs.hostPlatform to aarch64-darwin if you are using Apple Silicon.

Migrating from an existing configuration.nix

Add the following to flake.nix in the same folder as configuration.nix:

{
  description = "John's darwin system";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
    nix-darwin.url = "github:LnL7/nix-darwin";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs }: {
    darwinConfigurations."Johns-MacBook" = nix-darwin.lib.darwinSystem {
      modules = [ ./configuration.nix ];
    };
  };
}

Make sure to replace Johns-MacBook with your hostname which you can find by running scutil --get LocalHostName.

Make sure to set nixpkgs.hostPlatform in your configuration.nix to either x86_64-darwin (Intel) or aarch64-darwin (Apple Silicon).

Step 2. Installing nix-darwin

Unlike NixOS, nix-darwin does not have an installer, you can just run darwin-rebuild switch to install nix-darwin. As darwin-rebuild won't be installed in your PATH yet, you can use the following command:

nix run nix-darwin -- switch --flake ~/.config/nix-darwin

Step 3. Using nix-darwin

After installing, you can run darwin-rebuild to apply changes to your system:

darwin-rebuild switch --flake ~/.config/nix-darwin

Using flake inputs

Inputs from the flake can also be passed into darwinSystem. These inputs are then accessible as an argument inputs, similar to pkgs and lib, inside the configuration.

# in flake.nix
nix-darwin.lib.darwinSystem {
  modules = [ ./configuration.nix ];
  specialArgs = { inherit inputs; };
}
# in configuration.nix
{ pkgs, lib, inputs }:
# inputs.self, inputs.nix-darwin, and inputs.nixpkgs can be accessed here
Channels

Step 1. Creating configuration.nix

Copy the simple example to ~/.config/nix-darwin/configuration.nix.

Step 2. Adding nix-darwin channel

nix-channel --add https://github.com/LnL7/nix-darwin/archive/master.tar.gz darwin
nix-channel --update

Step 3. Installing nix-darwin

To install nix-darwin, you can just run darwin-rebuild switch to install nix-darwin. As darwin-rebuild won't be installed in your PATH yet, you can use the following command:

nix --extra-experimental-features "nix-command flakes" run nix-darwin -- switch -I darwin-config=$HOME/.config/nix-darwin/configuration.nix

Step 4. Using nix-darwin

After installing, you can run darwin-rebuild to apply changes to your system:

darwin-rebuild switch

Step 5. Updating nix-darwin

You can update nix-darwin using the following command:

nix-channel --update darwin

Documentation

darwin-help will open up a local copy of the reference documentation, it can also be found online here.

The documentation is also available as manpages by running man 5 configuration.nix.

Uninstalling

To run the latest version of the uninstaller, you can run the following command:

nix --extra-experimental-features "nix-command flakes" run nix-darwin#darwin-uninstaller

If that command doesn't work for you, you can try the locally installed uninstaller:

darwin-uninstaller

Tests

There are basic tests that run sanity checks for some of the modules, you can run them like this:

# run all tests
nix-build release.nix -A tests
# or just a subset
nix-build release.nix -A tests.environment-path

Contributing

Let's make Nix on macOS awesome!

Don't hesitate to contribute modules or open an issue.

To build your configuration with local changes you can run this. This flag can also be used to override darwin-config or nixpkgs, for more information on the -I flag look at the nix-build manpage.

darwin-rebuild switch -I darwin=.

If you're adding a module, please add yourself to meta.maintainers, for example

  meta.maintainers = [
    lib.maintainers.alice or "alice"
  ];

  options.services.alicebot = # ...

The or operator takes care of graceful degradation when lib from Nixpkgs goes out of sync.

Also feel free to contact me if you have questions,

  • Matrix - @daiderd:matrix.org, you can find me in #macos:nixos.org
  • @LnL7 on twitter