Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Manage your macOS using Nix

License

NotificationsYou must be signed in to change notification settings

nix-darwin/nix-darwin

Repository files navigation

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 aroundNixpkgs, quite similar toNixOS.

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 theLix installer, which supports both flake-based and channel-based setups.

The installer you use doesn't affect which Nix interpreter your system will use later on. nix-darwin manages the Nix installation by default and will default to upstream Nix. If you wish to use Lix instead of Nix, setnix.package = pkgs.lix in your configuration.

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. Creatingflake.nix

Getting started from scratch

If you don't have an existingconfiguration.nix, you can run the following commands to generate a basicflake.nix inside/etc/nix-darwin:

sudo mkdir -p /etc/nix-darwinsudo chown$(id -nu):$(id -ng) /etc/nix-darwincd /etc/nix-darwin# To use Nixpkgs unstable:nix flake init -t nix-darwin/master# To use Nixpkgs 25.05:nix flake init -t nix-darwin/nix-darwin-25.05sed -i''"s/simple/$(scutil --get LocalHostName)/" flake.nix

Make sure to check ifnixpkgs.hostPlatform is set to eitherx86_64-darwin for Intel oraarch64-darwin for Apple Silicon.

Migrating from an existing configuration.nix

Add the following toflake.nix in the same folder asconfiguration.nix:

{description="John's darwin system";inputs={# Use `github:NixOS/nixpkgs/nixpkgs-25.05-darwin` to use Nixpkgs 25.05.nixpkgs.url="github:NixOS/nixpkgs/nixpkgs-unstable";# Use `github:nix-darwin/nix-darwin/nix-darwin-25.05` to use Nixpkgs 25.05.nix-darwin.url="github:nix-darwin/nix-darwin/master";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 replaceJohns-MacBook with your hostname which you can find by runningscutil --get LocalHostName.

Make sure to setnixpkgs.hostPlatform in yourconfiguration.nix to eitherx86_64-darwin (Intel) oraarch64-darwin (Apple Silicon).

Step 2. Installingnix-darwin

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

# To use Nixpkgs unstable:sudo nix run nix-darwin/master#darwin-rebuild -- switch# To use Nixpkgs 25.05:sudo nix run nix-darwin/nix-darwin-25.05#darwin-rebuild -- switch

Step 3. Usingnix-darwin

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

sudo darwin-rebuild switch

Using flake inputs

Inputs from the flake can also be passed intodarwinSystem. These inputs are thenaccessible as an argumentinputs, similar topkgs andlib, inside the configuration.

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

Step 1. Creatingconfiguration.nix

Copy thesimple example to/etc/nix-darwin/configuration.nix.

Step 2. Addingnix-darwin channel

# If you use Nixpkgs unstable (the default):sudo nix-channel --add https://github.com/nix-darwin/nix-darwin/archive/master.tar.gz darwin# If you use Nixpkgs 25.05:sudo nix-channel --add https://github.com/nix-darwin/nix-darwin/archive/nix-darwin-25.05.tar.gz darwinsudo nix-channel --update

Step 3. Installingnix-darwin

To installnix-darwin, you can just rundarwin-rebuild switch to install nix-darwin. Asdarwin-rebuild won't be installed in yourPATH yet, you can use the following command:

nix-build'<darwin>' -A darwin-rebuildsudo ./result/bin/darwin-rebuild switch -I darwin-config=/etc/nix-darwin/configuration.nix

Step 4. Usingnix-darwin

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

sudo darwin-rebuild switch

Step 5. Updatingnix-darwin

You can update Nixpkgs andnix-darwin using the following command:

sudo nix-channel --update

Documentation

The reference documentation is available:

  • Online:nix-darwin reference
  • Locally in your browser via thedarwin-help command
  • As a manual page viaman 5 configuration.nix

Uninstalling

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

sudo 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:

sudo darwin-uninstaller

Tests

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

# run all testsnix-build release.nix -A tests# or just a subsetnix-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. Thisflag can also be used to override darwin-config or nixpkgs, for moreinformation on the-I flag look at the nix-buildmanpage.

sudo darwin-rebuild switch -I darwin=.

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

meta.maintainers=[lib.maintainers.aliceor"alice"];options.services.alicebot=# ...

Theor operator takes care of graceful degradation whenlib from Nixpkgsgoes out of sync.

Feel free to contact us on Matrix if you have questions:

About

Manage your macOS using Nix

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

[8]ページ先頭

©2009-2026 Movatter.jp