Skip to content

Commit

Permalink
{environment,readme}: default configuration path to /etc/nix-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
emilazy committed Jan 18, 2025
1 parent 24353d1 commit 69b2588
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2025-01-18
- The default configuration path for all new installations
is `/etc/nix-darwin`. This was already the undocumented
default for `darwin-rebuild switch` when using flakes. This
is implemented by setting `environment.darwinConfig` to
`"/etc/nix-darwin/configuration.nix"` by default when
`system.stateVersion` ≥ 6.

2024-09-10
- The default Nix build user group ID is now set to 350 when
`system.stateVersion` ≥ 5, to reflect the default for new Nix
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ Despite being an experimental feature in Nix currently, nix-darwin recommends th
<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`:
If you don't have an existing `configuration.nix`, you can run the following commands to generate a basic `flake.nix` inside `/etc/nix-darwin`:

```bash
mkdir -p ~/.config/nix-darwin
cd ~/.config/nix-darwin
sudo mkdir -p /etc/nix-darwin
sudo chown $(id -nu):$(id -ng) /etc/nix-darwin
cd /etc/nix-darwin

# To use Nixpkgs unstable:
nix flake init -t nix-darwin/master
Expand Down Expand Up @@ -88,15 +89,15 @@ Make sure to set `nixpkgs.hostPlatform` in your `configuration.nix` to either `x
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:

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

### 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
darwin-rebuild switch
```

#### Using flake inputs
Expand Down Expand Up @@ -124,7 +125,7 @@ nix-darwin.lib.darwinSystem {

### Step 1. Creating `configuration.nix`

Copy the [simple](./modules/examples/simple.nix) example to `~/.config/nix-darwin/configuration.nix`.
Copy the [simple](./modules/examples/simple.nix) example to `/etc/nix-darwin/configuration.nix`.

### Step 2. Adding `nix-darwin` channel

Expand All @@ -143,7 +144,7 @@ To install `nix-darwin`, you can just run `darwin-rebuild switch` to install nix

```bash
nix-build '<darwin>' -A darwin-rebuild
./result/bin/darwin-rebuild switch -I darwin-config=$HOME/.config/nix-darwin/configuration.nix
./result/bin/darwin-rebuild switch
```

### Step 4. Using `nix-darwin`
Expand Down
20 changes: 18 additions & 2 deletions modules/environment/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,24 @@ in
};

environment.darwinConfig = mkOption {
type = types.either types.path types.str;
default = "$HOME/.nixpkgs/darwin-configuration.nix";
type = types.nullOr (types.either types.path types.str);
default =
if config.nixpkgs.flake.setNixPath then
# Don’t set this for flake‐based systems.
null
else if config.system.stateVersion >= 6 then
"/etc/nix-darwin/configuration.nix"
else
"$HOME/.nixpkgs/darwin-configuration.nix";
defaultText = literalExpression ''
if config.nixpkgs.flake.setNixPath then
# Don’t set this for flake‐based systems.
null
else if config.system.stateVersion >= 6 then
"/etc/nix-darwin/configuration.nix"
else
"$HOME/.nixpkgs/darwin-configuration.nix"
'';
description = ''
The path of the darwin configuration.nix used to configure the system,
this updates the default darwin-config entry in NIX_PATH. Since this
Expand Down
2 changes: 1 addition & 1 deletion modules/examples/flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;
system.stateVersion = 6;

# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
Expand Down
2 changes: 1 addition & 1 deletion modules/examples/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ in
echo "ok"
'';

system.stateVersion = 5;
system.stateVersion = 6;
}
4 changes: 2 additions & 2 deletions modules/examples/lnl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
programs.zsh.enableFzfGit = true;
programs.zsh.enableFzfHistory = true;

programs.zsh.variables.cfg = "$HOME/.config/nixpkgs/darwin/configuration.nix";
programs.zsh.variables.cfg = "/etc/nix-darwin/configuration.nix";
programs.zsh.variables.darwin = "$HOME/.nix-defexpr/darwin";
programs.zsh.variables.nixpkgs = "$HOME/.nix-defexpr/nixpkgs";

Expand Down Expand Up @@ -322,5 +322,5 @@
nix.configureBuildUsers = true;
nix.nrBuildUsers = 32;

system.stateVersion = 5;
system.stateVersion = 6;
}
5 changes: 1 addition & 4 deletions modules/examples/simple.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
[ pkgs.vim
];

# Use custom location for configuration.nix.
environment.darwinConfig = "$HOME/.config/nix-darwin/configuration.nix";

# Enable alternative shell support in nix-darwin.
# programs.fish.enable = true;

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;
system.stateVersion = 6;
}
2 changes: 1 addition & 1 deletion modules/system/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ let
darwinConfig=$(NIX_PATH=$nixPath nix-instantiate --find-file darwin-config) || true
if ! test -e "$darwinConfig"; then
echo "error: Changed <darwin-config> but target does not exist, aborting activation" >&2
echo "Create ''${darwinConfig:-~/.nixpkgs/darwin-configuration.nix} or set environment.darwinConfig:" >&2
echo "Create ''${darwinConfig:-/etc/nix-darwin/configuration.nix} or set environment.darwinConfig:" >&2
echo >&2
echo " environment.darwinConfig = \"$(nix-instantiate --find-file darwin-config 2> /dev/null || echo '***')\";" >&2
echo >&2
Expand Down
2 changes: 1 addition & 1 deletion modules/system/version.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ in
system.maxStateVersion = mkOption {
internal = true;
type = types.int;
default = 5;
default = 6;
};

system.darwinLabel = mkOption {
Expand Down

0 comments on commit 69b2588

Please sign in to comment.