diff --git a/README.md b/README.md index 493beca..80af669 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dot_config/fish/config.fish b/dot_config/fish/config.fish index 3b2872b..da75007 100644 --- a/dot_config/fish/config.fish +++ b/dot_config/fish/config.fish @@ -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*' diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..34a87ba --- /dev/null +++ b/flake.nix @@ -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; }; + }; + }; + }; +} \ No newline at end of file diff --git a/nix/.gitignore b/nix/.gitignore new file mode 100644 index 0000000..f295f42 --- /dev/null +++ b/nix/.gitignore @@ -0,0 +1,2 @@ +result +result-* \ No newline at end of file diff --git a/nix/darwin-configuration.nix b/nix/darwin-configuration.nix new file mode 100644 index 0000000..6d84edd --- /dev/null +++ b/nix/darwin-configuration.nix @@ -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; + }; + }; +} \ No newline at end of file diff --git a/nix/example-host.nix b/nix/example-host.nix new file mode 100644 index 0000000..a1f4389 --- /dev/null +++ b/nix/example-host.nix @@ -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 + ]; + }; +} \ No newline at end of file diff --git a/nix/home.nix b/nix/home.nix new file mode 100644 index 0000000..f7c6f09 --- /dev/null +++ b/nix/home.nix @@ -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"; +} \ No newline at end of file