update
This commit is contained in:
107
README.md
107
README.md
@@ -21,8 +21,6 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
|
||||
- [Building and Switching](#building-and-switching)
|
||||
- [Common Commands](#common-commands)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [Dirty Git Tree](#dirty-git-tree)
|
||||
- [Path Does Not Exist](#path-does-not-exist)
|
||||
- [References](#references)
|
||||
|
||||
## Overview
|
||||
@@ -42,35 +40,42 @@ By splitting the configuration into multiple files under `./modules/`, each file
|
||||
After installing Nix, you can install nix-darwin (one recommended approach is from the official Nix-Darwin docs).
|
||||
|
||||
## Modules
|
||||
- **flake.nix**: The top-level file defining all inputs (nixpkgs, nix-darwin, home-manager, nix-homebrew) and outputs (your nix-darwin configuration). Imports each module (e.g., `./modules/darwin/homebrew.nix`) into `darwinConfigurations.<hostname>.modules`.
|
||||
|
||||
- **flake.nix**: The top-level file defining all inputs (nixpkgs, nix-darwin, home-manager, nix-homebrew) and outputs.
|
||||
- **modules/darwin/apps/**:
|
||||
- `homebrew.nix`: Holds Homebrew-related configurations (brew packages, casks, etc.).
|
||||
- `nixpackages.nix`: Holds your `environment.systemPackages`.
|
||||
- `services.nix`: Configures system services (e.g., Tailscale, nix-daemon, security/pam).
|
||||
- `default.nix`: Aggregates all .nix files in the directory for easier reference by the flake.
|
||||
- `default.nix`: Aggregates all .nix files in the directory.
|
||||
- **modules/darwin/security/**:
|
||||
- `default.nix`: Consolidated configurations for security related settings.
|
||||
- **modules/darwin/system/**:
|
||||
- `appearance.nix`: Appearance related settings (e.g., dock, interface, login window settings, etc ).
|
||||
- `finder.nix`: Finder related customizations.
|
||||
- `system.nix`: System configuration (e.g., trackpad, keyboard mapping, screenshot default location, etc...).
|
||||
- `default.nix`: Aggregates all .nix files in directory for easier reference by the flake
|
||||
- `system.nix`: System configuration (e.g., trackpad, keyboard mapping, screenshot default location, etc.).
|
||||
- `default.nix`: Aggregates all .nix files in directory.
|
||||
- **modules/home/**:
|
||||
- `<username>/dotfiles.nix`: Holds user-level dotfiles managed by Home Manager (e.g., `~/.gitconfig`, `~/.ssh/config`).
|
||||
- **rebuild.sh**: A convenience script that typically runs something like:
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
darwin-rebuild switch --flake .#<hostname>
|
||||
```
|
||||
- `<username>/`: User-specific configurations
|
||||
- `<username>/terminal/`: Terminal-related configurations including shell setup
|
||||
- `<username>/terminal/starship/`: Starship prompt configurations
|
||||
|
||||
## Management Script
|
||||
|
||||
The repository includes an interactive management script (`manage.sh`) that provides a unified interface for common tasks:
|
||||
|
||||
```sh
|
||||
./manage.sh
|
||||
```
|
||||
|
||||
The script offers the following options:
|
||||
|
||||
1. **Rebuild configuration**: Rebuilds the current configuration
|
||||
2. **Update flakes and rebuild**: Updates all flake inputs and rebuilds
|
||||
3. **Clean nix store**: Runs garbage collection on the Nix store
|
||||
4. **Exit**: Exits the script
|
||||
|
||||
For rebuild operations (options 1 and 2), the script will:
|
||||
- Prompt for the hostname (defaults to "swaphb-mba" if not specified)
|
||||
- Execute the appropriate commands
|
||||
|
||||
## How to Use
|
||||
|
||||
In the `flake.nix` file, you can define host-specific and user-specific variables using let-bindings. Examples shown in the `flake.nix` file.
|
||||
|
||||
To add a new host or user, update the `hostVars` and `userVars` sections in the `flake.nix` file with the new configurations. Follow the existing structure to ensure consistency.
|
||||
|
||||
Execution:
|
||||
|
||||
1. **Clone the repository**:
|
||||
```sh
|
||||
git clone https://github.com/your-username/nix-darwin-config.git
|
||||
@@ -81,76 +86,46 @@ Execution:
|
||||
Follow the instructions on the [Nix website](https://nixos.org/download.html) to install Nix.
|
||||
|
||||
3. **Enable Flakes**:
|
||||
Ensure that flakes are enabled in your Nix configuration:
|
||||
```sh
|
||||
mkdir -p ~/.config/nix
|
||||
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
|
||||
```
|
||||
|
||||
4. **Apply Configuration**:
|
||||
To apply the configuration for a specific host, run:
|
||||
```sh
|
||||
nix build .#darwinConfigurations.<hostname>.system
|
||||
./result/sw/bin/darwin-rebuild switch --flake .
|
||||
nix run nix-darwin --extra-experimental-features nix-command --extra-experimental-features flakes -- switch --flake .#swaphb-mba
|
||||
```
|
||||
|
||||
Replace `<hostname>` with the actual hostname defined in the `flake.nix` file (e.g., `swaphb-mba`).
|
||||
|
||||
## Building and Switching
|
||||
|
||||
1. Clone this repo (or ensure you have your local copy).
|
||||
2. Install nix-darwin if you haven’t already.
|
||||
3. From the root of this repository (where `flake.nix` resides), run:
|
||||
```sh
|
||||
darwin-rebuild switch --flake .#<hostname>
|
||||
```
|
||||
Replace `<hostname>` with the actual name of your system defined in `flake.nix` (e.g., `swaphb-mba`).
|
||||
|
||||
Alternatively, if you have a script `rebuild.sh`, run:
|
||||
|
||||
```sh
|
||||
./rebuild.sh
|
||||
```
|
||||
which should do the same command under the hood.
|
||||
Select option 1 to rebuild the configuration, and enter your hostname when prompted.
|
||||
|
||||
## Common Commands
|
||||
|
||||
All common commands are now available through the management script (`./manage.sh`). However, you can still run commands manually if needed:
|
||||
|
||||
- **Build without switching**:
|
||||
```sh
|
||||
darwin-rebuild build --flake .#<hostname>
|
||||
```
|
||||
This only builds the configuration but doesn’t apply it.
|
||||
|
||||
- **Show changes**:
|
||||
```sh
|
||||
darwin-rebuild dry-activate --flake .#<hostname>
|
||||
```
|
||||
See what changes will be made without applying them.
|
||||
|
||||
- **List available flake outputs**:
|
||||
```sh
|
||||
nix flake show
|
||||
```
|
||||
- **Build with switching**
|
||||
```sh
|
||||
darwin-rebuild switch --flake .#<hostname>
|
||||
```
|
||||
- **Update upstream flakes**
|
||||
```sh
|
||||
nix flake update
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Dirty Git Tree
|
||||
|
||||
If you see warnings like:
|
||||
If you see warnings about a dirty Git tree:
|
||||
```
|
||||
warning: Git tree '/path/to/your/repo' is dirty
|
||||
```
|
||||
It means you have uncommitted changes.
|
||||
|
||||
**Solution**: Either commit the changes or pass `--impure` (not recommended), or stage/commit the changes to keep the flake happy:
|
||||
**Solution**: Commit your changes:
|
||||
```sh
|
||||
git add -A
|
||||
git commit -m "Commit message"
|
||||
@@ -158,23 +133,19 @@ git commit -m "Commit message"
|
||||
|
||||
### Path Does Not Exist
|
||||
|
||||
If you get an error similar to:
|
||||
If you get path-related errors:
|
||||
```
|
||||
error: path '/nix/store/...-source/modules/darwin/homebrew.nix' does not exist
|
||||
```
|
||||
It usually means:
|
||||
|
||||
- You haven’t actually created or committed the file.
|
||||
- There’s a typo or case mismatch in the file name.
|
||||
- The file is in a different directory than you think.
|
||||
|
||||
**Solution**: Make sure the file exists, check for correct spelling/capitalization, and commit it to Git.
|
||||
**Solution**:
|
||||
- Verify the file exists
|
||||
- Check for correct spelling/capitalization
|
||||
- Ensure the file is committed to Git
|
||||
|
||||
## References
|
||||
|
||||
- [NixOS Wiki: Flakes](https://nixos.wiki/wiki/Flakes)
|
||||
- [nix-darwin](https://github.com/LnL7/nix-darwin)
|
||||
- [Home Manager](https://github.com/nix-community/home-manager)
|
||||
- [nix-homebrew (zhaofengli-wip)](https://github.com/zhaofengli/nix-homebrew)
|
||||
|
||||
With this multi-file approach, you can easily add, remove, or tweak individual modules without having a giant monolithic `flake.nix`.
|
||||
- [nix-homebrew (zhaofengli-wip)](https://github.com/zhaofengli/nix-homebrew)
|
||||
Reference in New Issue
Block a user