# nix-darwin

import {
  nixDaemonServices,
  nixInstaller,
  removeNixGroupUsers,
  shellConfigBackups,
} from "@/lib/mdx-constants";
## Getting started

This guide walks you through setting up macOS with nix-darwin to configure native settings and preinstall essential apps and configurations.

### References

<ReferenceLinks references={frontmatter.references} />

---

## Setup

1.  ### Make directory

        ```sh
        mkdir ~/.nix-config && cd ~/.nix-config
        ```

2.  ### Add nix files

        ```nix title="flake.nix"
        flakeNix
        ```
        ```nix title="configuration.nix"
        configurationNix
        ```
        ```nix title="system.nix"
        systemNix
        ```

3.  ### Install nix

        ```sh
        curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix |   sh -s -- install
        ```

        - Insert `Y` to install Determinate Nix or `N` for NixOS.
        - Insert `Y` to continue.

        

4.  ### Install nix-darwin

        ```sh
        nix run nix-darwin/master#darwin-rebuild -- switch --flake .#{{HOSTNAME_VAR}}
        ```

5.  ### Build
        ```sh
        darwin-rebuild switch --flake .#{{HOSTNAME_VAR}}
        ```

---

## Uninstall

1.  ### Remove unused profiles

        ```sh
        nix-collect-garbage --delete-old
        ```

2.  ### Uninstall nix-darwin

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

3.  ### Uninstall nix

        ```sh
        /nix/nix-installer uninstall
        ```

4.  ### Remove nix artifacts

    

   1. #### Edit system shell configs

            Edit /etc/zshrc, /etc/bashrc and /etc/bash.bashrc to remove the lines sourcing nix-daemon.sh.

   2. #### Remove shell config backups

            If these files haven’t been altered since installing Nix you can simply put the backups back in place.

            ```sh
            sudo mv /etc/zshrc.backup-before-nix /etc/zshrc
            sudo mv /etc/bashrc.backup-before-nix /etc/bashrc
            sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
            ```

   3. #### Stop and remove the Nix daemon services

            ```sh
            sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
            sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
            sudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plist
            sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist
            ```

   4. #### Remove the nixbld group and the \_nixbuildN users

            ```sh
            sudo dscl . -delete /Groups/nixbld

            for u in $(sudo dscl . -list /Users | grep _nixbld); do
                sudo dscl . -delete /Users/$u
            done
            ```

   5. #### Edit fstab

            Edit fstab using sudo vifs to remove the line mounting the Nix Store volume on /nix, which looks like UUID=\<uuid\> /nix apfs rw,noauto,nobrowse,suid,owners or LABEL=Nix\040Store /nix apfs rw,nobrowse. This will prevent automatic mounting of the Nix Store volume.

   6. #### Edit synthetic.conf

            Edit /etc/synthetic.conf to remove the nix line. If this is the only line in the file you can remove it entirely, sudo rm /etc/synthetic.conf. This will prevent the creation of the empty /nix directory to provide a mountpoint for the Nix Store volume.

   7. #### Remove the files Nix added to your system

            ```sh
            sudo rm -rf /etc/nix ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.local/state/nix /System/Volumes/Data/private/var/root/.nix-defexpr /System/Volumes/Data/private/var/root/.cache/nix /private/var/root/.nix-defexpr /private/var/root/.cache/nix
            ```

   8. #### Remove the Nix Store volume

            ```sh
            sudo diskutil apfs deleteVolume /nix
            ```

   9. #### Verify

            Look for a “Nix Store” volume in the output of the following command.

            ```sh
            diskutil list
            ```

---

## Manual configurations

Defaults that aren’t configurable with nix-darwin.

### Notifications

- Allow notifications when the screen is locked > <code>false</code>

### Desktop & Dock

- Default web browser

### Lock Screen

- When Switching User > Login window shows > <code>Name and password</code>

### Trackpad

- Secondary click > <code>Click in Bottom Right Corner</code>

### Finder sidebar

**Favorites**

- [x] Recents
- [x] AirDrop
- [x] Applications
- [x] Desktop
- [x] Documents
- [x] Downloads
- [ ] Movies
- [ ] Music
- [ ] Pictures
- [x] $USER

**iCloud**

- [ ] iCloud Drive
- [ ] Shared

**Locations**

- [ ] Device
- [x] Hard disks
- [x] External disks
- [ ] CDs, DVDs, and iOS Devices
- [ ] Cloud Storage
- [ ] Bonjour computers
- [ ] Connected servers

**Tags**

- [ ] Recent Tags

#### View Options

- [x] Always open in list view
- [x] Browse in list view
- Group By: <code>None</code>
- Sort By: <code>Date Modified</code>

**Show Columns:**

- [x] Date Modified
- [x] Date Created
- [ ] Date Last Opened
- [ ] Date Added
- [x] Size
- [x] Kind
- [ ] Version
- [ ] Comments
- [ ] Tags

**Misc**

- [x] Use relative dates
- [x] Calculate all sizes
- [x] Show icon preview

<button disabled style={{ color: "var(--sl-color-text)" }}>
  Use as Defaults
</button>

---

## Troublshooting

### Reset finder preferences

```sh wrap preserveIndent
rm ~/Library/Preferences/com.apple.finder.plist
defaults delete com.apple.finder
killall Finder
sudo reboot
```
