Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,68 @@ brew bundle --file Brewfile-cask
brew bundle --file Brewfile-app
```

### `*nix` Install [Nix](https://nixos.org/download.html)

```bash
# For single-user installation
sh <(curl -L https://nixos.org/nix/install) --no-daemon

# For multi-user installation
sh <(curl -L https://nixos.org/nix/install)

# macOS 10.15 Catalina or newer needs this extra step
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
```

#### Benefits of Nix

- **Reproducible**: Same packages and versions across all machines
- **Declarative**: System configuration defined in code
- **Reliable**: No dependency conflicts, clean rollbacks
- **Multi-user**: Different users can have different configurations without interference
- **Atomic upgrades and rollbacks**: Easy to go back if something breaks
- **Works alongside Homebrew**: Can be used together with existing setup

### `MacOS` Install [nix-darwin](https://github.com/LnL7/nix-darwin)

```bash
# First ensure Nix is installed from the step above

# Clone this repo to get the darwin configuration
# or use the example configuration below to create your own
git clone https://github.com/dfdgsdfg/dotfiles.git
cd dotfiles

# Build the initial configuration (first-time setup)
nix build .#darwinConfigurations.$(hostname -s).system

# Apply the configuration
./result/sw/bin/darwin-rebuild switch --flake .#
```

### Using Nix and nix-darwin

The Nix configuration is organized as follows:

- `flake.nix`: The main entry point for nix-darwin
- `nix/darwin-configuration.nix`: Base configuration for macOS systems
- `nix/home.nix`: Home Manager configuration for user environment

To customize for your machine:

1. Edit `flake.nix` to change "yourhost" to your machine's hostname
2. Customize `nix/home.nix` with your Git information and preferred packages
3. Create a host-specific configuration file by copying `nix/example-host.nix` to `nix/yourhostname.nix`
4. Update the configuration: `darwin-rebuild switch --flake .#`

After setting up, you can update your system with:

```bash
# Update packages and apply configuration
darwin-rebuild switch --flake .#
```

### `*nix` Config [mise](https://github.com/jdx/mise)
```sh
mise i
Expand Down
6 changes: 6 additions & 0 deletions dot_config/fish/config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman


# Nix
if test -e ~/.nix-profile/etc/profile.d/nix.sh
bass source ~/.nix-profile/etc/profile.d/nix.sh
end


# Homebrew, mise
switch (sysctl -n machdep.cpu.brand_string)
case '*Apple*'
Expand Down
32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
description = "Dotfiles nix-darwin configuration";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
darwin.url = "github:lnl7/nix-darwin";
darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = inputs@{ self, nixpkgs, darwin, home-manager, ... }: {
darwinConfigurations = {
# Change "yourhost" to your hostname
# You can get your hostname by running `hostname -s` in terminal
# Multiple hosts can be defined here for different machines
yourhost = darwin.lib.darwinSystem {
system = "aarch64-darwin"; # For Apple Silicon Mac, use "x86_64-darwin" for Intel
modules = [
./nix/darwin-configuration.nix
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.${builtins.getEnv "USER"} = import ./nix/home.nix;
}
];
specialArgs = { inherit inputs; };
};
};
};
}
2 changes: 2 additions & 0 deletions nix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
result
result-*
86 changes: 86 additions & 0 deletions nix/darwin-configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{ config, pkgs, inputs, ... }:

{
# Set up nix settings
nix.settings = {
experimental-features = [ "nix-command" "flakes" ];
substituters = [
"https://cache.nixos.org/"
];
};

# Allow unfree packages
nixpkgs.config.allowUnfree = true;

# Auto upgrade nix package and the daemon service
services.nix-daemon.enable = true;

# Used for backwards compatibility
system.stateVersion = 4;

# Create /etc/zshrc that loads the nix-darwin environment
programs.zsh.enable = true;

# Enable fish shell
programs.fish.enable = true;

# Install packages
environment.systemPackages = with pkgs; [
# Common CLI tools already in Brewfile
git
neovim
wget
bat
fd
ripgrep
jq
yq
# Add any other packages you want installed system-wide
];

# Set environment variables
environment.variables = {
EDITOR = "nvim";
};

# Install homebrew - allows coexistence with Nix
# Comment this out if you prefer to manage Homebrew separately
homebrew = {
enable = true;
onActivation = {
autoUpdate = true;
cleanup = "zap"; # Remove unmanaged formulae
};
global = {
brewfile = true;
};
# Define homebrew packages here if you want to manage via nix-darwin
# Otherwise keep your Brewfile in the repo
taps = [];
brews = [];
casks = [];
};

# System preferences/settings
system.defaults = {
dock = {
autohide = true;
minimize-to-application = true;
};
finder = {
AppleShowAllExtensions = true;
QuitMenuItem = true;
};
NSGlobalDomain = {
AppleKeyboardUIMode = 3;
AppleShowAllExtensions = true;
InitialKeyRepeat = 15;
KeyRepeat = 2;
NSAutomaticCapitalizationEnabled = false;
NSAutomaticDashSubstitutionEnabled = false;
NSAutomaticPeriodSubstitutionEnabled = false;
NSAutomaticQuoteSubstitutionEnabled = false;
NSAutomaticSpellingCorrectionEnabled = false;
};
};
}
32 changes: 32 additions & 0 deletions nix/example-host.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This is an example file showing how to create host-specific configurations
# Copy this file and rename it to your hostname.nix to customize your setup
{ config, pkgs, ... }:

{
# Import the base configuration
imports = [ ./darwin-configuration.nix ];

# Override or add settings specific to this machine
environment.systemPackages = with pkgs; [
# Add host-specific packages here
];

# Host-specific system preferences
system.defaults = {
# Override or extend system preferences for this host
};

# Host-specific homebrew configuration
homebrew = {
# You can override the base homebrew configuration here
taps = [
# Host-specific taps
];
brews = [
# Host-specific brews
];
casks = [
# Host-specific casks
];
};
}
54 changes: 54 additions & 0 deletions nix/home.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{ config, pkgs, ... }:

{
# Home Manager needs a bit of information about you and the
# paths it should manage.
home.username = builtins.getEnv "USER";
home.homeDirectory = builtins.getEnv "HOME";

# Let Home Manager install and manage itself.
programs.home-manager.enable = true;

# Fish shell configuration
programs.fish = {
enable = true;
interactiveShellInit = ''
# Add any fish shell configuration here
# This will complement the existing fish config
'';
plugins = [
# You can add fish plugins here
];
};

# Starship prompt
programs.starship = {
enable = true;
enableFishIntegration = true;
};

# Git configuration
programs.git = {
enable = true;
userName = "Your Name"; # Customize this
userEmail = "your.email@example.com"; # Customize this
delta = {
enable = true;
};
};

# Packages that should be installed to the user profile
home.packages = with pkgs; [
# CLI tools
atuin
zoxide
fzf
navi
# Add other packages you want installed
];

# This value determines the Home Manager release that your
# configuration is compatible with. The recommended approach is
# to not set it and let Home Manager figure out the appropriate version.
home.stateVersion = "23.11";
}