mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
readme: update with new flaky instructions
This commit is contained in:
parent
5288a72354
commit
22620845fe
3 changed files with 63 additions and 25 deletions
80
README.md
80
README.md
|
@ -7,12 +7,14 @@
|
|||
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](https://github.com/NixOS/nixpkgs), quite similar to [NixOS](https://nixos.org/).
|
||||
nix-darwin is built up around [Nixpkgs](https://github.com/NixOS/nixpkgs), quite similar to [NixOS](https://nixos.org/).
|
||||
|
||||
## Install
|
||||
## Installing
|
||||
|
||||
To install nix-darwin, a working installation of [Nix](https://github.com/NixOS/nix#installation) is required.
|
||||
|
||||
> NOTE: Using `darwin-installer` is no longer necessary on flake based systems.
|
||||
|
||||
```bash
|
||||
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
|
||||
./result/bin/darwin-installer
|
||||
|
@ -73,15 +75,39 @@ Configuration lives in `~/.nixpkgs/darwin-configuration.nix`. Check out
|
|||
There is also preliminary support for building your configuration using a [flake](https://nixos.wiki/wiki/Flakes). This
|
||||
is mostly based on the flake support that was added to NixOS.
|
||||
|
||||
A minimal example of using an existing configuration.nix:
|
||||
### Step 1. Creating `flake.nix`
|
||||
|
||||
<details>
|
||||
<summary>Getting started from scratch</summary>
|
||||
<p></p>
|
||||
|
||||
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`:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.config/nix-darwin
|
||||
cd ~/.config/nix-darwin
|
||||
nix flake init -t nix-darwin
|
||||
```
|
||||
|
||||
Make sure to replace all occurrences of `simple` with your short hostname which you can find by running `hostname -s`.
|
||||
|
||||
> NOTE: Make sure to change `nixpkgs.hostPlatform` to `aarch64-darwin` if you are using Apple Silicon.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Migrating from an existing configuration.nix</summary>
|
||||
<p></p>
|
||||
|
||||
Add the following to `flake.nix` in the same folder as `configuration.nix`:
|
||||
|
||||
```nix
|
||||
{
|
||||
description = "John's darwin system";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-23.05-darwin";
|
||||
darwin.url = "github:lnl7/nix-darwin/master";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";
|
||||
darwin.url = "github:LnL7/nix-darwin/master";
|
||||
darwin.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
|
@ -93,6 +119,30 @@ A minimal example of using an existing configuration.nix:
|
|||
}
|
||||
```
|
||||
|
||||
Make sure to replace `Johns-MacBook` with your short hostname which you can find by running `hostname -s`.
|
||||
|
||||
> NOTE: Make sure to set `nixpkgs.hostPlatform` in your `configuration.nix` to either `x86_64-darwin` (Intel) or `aarch64-darwin` (Apple Silicon).
|
||||
|
||||
</details>
|
||||
|
||||
### Step 2. Installing `nix-darwin`
|
||||
|
||||
Instead of using `darwin-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:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
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.
|
||||
|
||||
|
@ -110,16 +160,6 @@ darwin.lib.darwinSystem {
|
|||
# inputs.self, inputs.darwin, and inputs.nixpkgs can be accessed here
|
||||
```
|
||||
|
||||
Since the installer doesn't work with flakes out of the box yet, nix-darwin will need to
|
||||
be bootstrapped using the installer or manually. Afterwards the flake based
|
||||
configuration can be built. The `hostname(1)` of your system will be used to decide
|
||||
which darwin configuration is applied if it's not specified explicitly in the flake ref.
|
||||
|
||||
```sh
|
||||
nix build ~/.config/darwin\#darwinConfigurations.Johns-MacBook.system
|
||||
./result/sw/bin/darwin-rebuild switch --flake ~/.config/darwin
|
||||
```
|
||||
|
||||
## Manual Install
|
||||
|
||||
```bash
|
||||
|
@ -149,9 +189,10 @@ $(nix-build '<darwin>' -A system --no-out-link)/sw/bin/darwin-rebuild switch
|
|||
(nix-build '<darwin>' -A system --no-out-link)/sw/bin/darwin-rebuild switch
|
||||
```
|
||||
|
||||
This will create and manage a system profile in `/run/current-system`, just like nixos.
|
||||
This will create and manage a system profile in `/run/current-system`, just like NixOS.
|
||||
|
||||
The default `NIX_PATH` in nix-darwin will look for this repository in `~/.nix-defexpr/darwin` and for your configuration in `~/.nixpkgs/darwin-configuration.nix`.
|
||||
|
||||
By default, nix-darwin will look in your `NIX_PATH` for this repository at `~/.nix-defexpr/darwin` and your configuration at `~/.nixpkgs/darwin-configuration.nix`.
|
||||
If you want to change these you can set your own with `nix.nixPath = [ ];`.
|
||||
|
||||
```
|
||||
|
@ -212,7 +253,8 @@ nix-build release.nix -A tests.environment-path
|
|||
|
||||
## Contributing
|
||||
|
||||
Let's make nix on darwin awesome!
|
||||
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
|
||||
|
@ -238,4 +280,4 @@ 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](https://matrix.to/#/#macos:nixos.org)
|
||||
- @lnl7 on twitter
|
||||
- @LnL7 on twitter
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
darwin.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, darwin, nixpkgs }:
|
||||
outputs = inputs@{ self, darwin, nixpkgs }:
|
||||
let
|
||||
configuration = { pkgs, ... }: {
|
||||
# List packages installed in system profile. To search by name, run:
|
||||
|
|
|
@ -48,11 +48,7 @@ let
|
|||
if dscl . -list /Users | grep -q '^nixbld'; then
|
||||
echo "[1;31mwarning: Detected old style nixbld users[0m" >&2
|
||||
echo "These can cause migration problems when upgrading to certain macOS versions" >&2
|
||||
echo "Running the installer again will remove and recreate the users in a way that avoids these problems" >&2
|
||||
echo >&2
|
||||
echo "$ darwin-install" >&2
|
||||
echo >&2
|
||||
echo "or enable to automatically manage the users" >&2
|
||||
echo "You can enable the following option to migrate to new style nixbld users" >&2
|
||||
echo >&2
|
||||
echo " nix.configureBuildUsers = true;" >&2
|
||||
echo >&2
|
||||
|
|
Loading…
Reference in a new issue