diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 000000000..f4d8491cf --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,43 @@ +name: Nix +on: + pull_request: + branches: + - main +jobs: + nix-check: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v30 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Run Flake Check + run: nix flake check --all-systems + nix-darwin: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v30 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare system files + run: | + sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin || true + sudo mv /etc/shells /etc/shells.before-nix-darwin || true + - name: Run Nix Darwin + run: make update + nix-format: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v30 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Check formatting + run: make nix-format-check diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..093ddb0f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# AI +.aider* + +# Nix +.nix-defexpr +.nix-profile +.nix-store +.nix-channels + +# Ignore +result +ref diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..325dd5b8b --- /dev/null +++ b/Makefile @@ -0,0 +1,167 @@ +##@ Variables + +# Detect architecture and OS +ARCH := $(shell uname -m) +OS := $(shell uname -s) + +# Nix configuration system +NIX_SYSTEM := $(shell if [ "$(OS)" = "Darwin" ] && [ "$(ARCH)" = "arm64" ]; then \ + echo "aarch64-darwin"; \ + elif [ "$(OS)" = "Darwin" ] && [ "$(ARCH)" = "x86_64" ]; then \ + echo "x86_64-darwin"; \ + elif [ "$(OS)" = "Linux" ] && [ "$(ARCH)" = "x86_64" ]; then \ + echo "x86_64-linux"; \ + elif [ "$(OS)" = "Linux" ] && [ "$(ARCH)" = "aarch64" ]; then \ + echo "aarch64-linux"; \ + else \ + echo "unsupported"; \ + fi) +NIX_CONFIG_TYPE := $(shell if [ "$(OS)" = "Darwin" ]; then \ + echo "darwinConfigurations"; \ + else \ + echo "nixosConfigurations"; \ + fi) +NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || echo "not_found") +NIX_FLAGS := --extra-experimental-features 'flakes nix-command' + +# User's home directory +HOME_DIR := $(shell echo $$HOME) +CONFIG_DIR := $(HOME_DIR)/.config + +##@ Help + +# Default target +.PHONY: default +default: help + +# Help target +.PHONY: help +help: + @echo "Available targets:" + @echo " install - Set up full environment" + @echo " build - Build Nix configuration" + @echo " switch - Apply Nix configuration" + @echo " update - Update Nix flake and configurations" + @echo " format - Format Nix files" + @echo " format-check - Check Nix formatting" + @echo " pr - Create and push a PR (usage: make pr m='commit message' b='branch-name' t='PR title')" + +##@ General + +.PHONY: install +install: nix-install + +.PHONY: build +build: nix-build + +.PHONY: check +check: nix-check + +.PHONY: format +format: nix-format + +.PHONY: switch +switch: nix-switch + +.PHONY: update +update: nix-update + +##@ Nix + +.PHONY: nix-check +nix-check: + @echo "Checking Nix environment..." + @if [ "$(NIX_ENV)" = "not_found" ]; then \ + echo "❌ Nix environment not found. Please ensure Nix is installed and run:"; \ + exit 1; \ + fi + @echo "✅ Nix environment found!" + +.PHONY: nix-install +nix-install: + @if [ "$(NIX_ENV)" = "not_found" ]; then \ + echo "Installing Nix environment..."; \ + curl -L https://nixos.org/nix/install | sh; \ + fi + @echo "✅ Nix environment installed!" + +.PHONY: nix-update +nix-update: nix-flake-update nix-switch + +.PHONY: nix-flake-update +nix-flake-update: + @echo "🔄 Updating flake.lock..." + @if [ "$$CI" = "true" ]; then \ + echo "Bypassing flake update in CI"; \ + else \ + nix flake update $(NIX_FLAGS); \ + fi + @echo "✨ flake.lock updated!" + +.PHONY: nix-format +nix-format: + @echo "Formatting Nix files..." + @nix fmt + @echo "✨ Formatting complete" + +.PHONY: nix-format-check +nix-format-check: + @echo "Checking Nix formatting..." + @nix fmt -- --fail-on-change + @echo "✅ All Nix files are properly formatted" + +.PHONY: nix-build +nix-build: + @echo "🔄 Building Nix configuration..." + @if [ "$$CI" = "true" ]; then \ + echo "Running in CI"; \ + nix build .#darwinConfigurations.runner.system $(NIX_FLAGS) --show-trace; \ + else \ + if [ "$(NIX_SYSTEM)" = "unsupported" ]; then \ + echo "❌ Unsupported system architecture: $(OS) $(ARCH)"; \ + exit 1; \ + fi; \ + nix build .#$(NIX_CONFIG_TYPE).$(NIX_SYSTEM).system $(NIX_FLAGS) --show-trace; \ + fi + @echo "✅ Nix configuration built successfully!" + +.PHONY: nix-switch +nix-switch: nix-build + @echo "🔄 Applying Nix configuration..." + @if [ "$$CI" = "true" ]; then \ + ./result/sw/bin/darwin-rebuild switch --flake .#runner; \ + elif [ "$(OS)" = "Darwin" ]; then \ + ./result/sw/bin/darwin-rebuild switch --flake .#$(NIX_SYSTEM); \ + else \ + sudo nixos-rebuild switch --flake .#$(NIX_SYSTEM); \ + fi + @echo "✨ Configuration applied successfully!" + +##@ GitHub + +.PHONY: pr +pr: + @if ! command -v gh &> /dev/null; then \ + echo "❌ GitHub CLI not found. Please run 'make install' to install it."; \ + exit 1; \ + fi + @if [ -z "$(b)" ]; then \ + echo "❌ Branch name required. Usage: make pr m='commit message' b='branch-name' t='PR title'"; \ + exit 1; \ + fi + @if [ -z "$(m)" ]; then \ + echo "❌ Commit message required. Usage: make pr m='commit message' b='branch-name' t='PR title'"; \ + exit 1; \ + fi + @echo "Creating PR branch and pushing changes..." + @git checkout -b feature/$(b) + @git add . + @git commit -m "$(m)" + @git push -u origin feature/$(b) + @echo "Creating PR..." + @if [ -z "$(t)" ]; then \ + gh pr create --fill; \ + else \ + gh pr create --title "$(t)" --body "$(m)"; \ + fi + @echo "✨ PR created successfully!" diff --git a/README.md b/README.md index 27ef622f0..be51c9c1a 100644 --- a/README.md +++ b/README.md @@ -1 +1,187 @@ -# dotfiles \ No newline at end of file +# Dotfiles + +Cross-platform dotfiles management using Nix Home Manager for macOS and Ubuntu. + +## Features + +- Cross-platform configuration management using Nix Home Manager +- Consistent development environment across macOS and Ubuntu +- Declarative configuration for reproducible setups +- Version controlled dotfiles and package management +- Automated installation and setup process + +## Prerequisites + +- Nix Package Manager +- Git +- Home Manager + +## Installation + +### 1. Install Nix Package Manager + +#### macOS +```bash +sh <(curl -L https://nixos.org/nix/install) --daemon +``` + +#### Ubuntu +```bash +sh <(curl -L https://nixos.org/nix/install) --daemon +``` + +### 2. Install Home Manager + +After installing Nix, set up your environment: + +```bash +# Source Nix environment (add this to your shell's rc file) +source ~/.nix-profile/etc/profile.d/nix.sh +``` + +Home Manager will be automatically installed when needed. + +### 3. Clone and Setup + +1. Clone this repository: +```bash +git clone https://github.com/shunkakinoki/dotfiles.git ~/.dotfiles +cd ~/.dotfiles +``` + +2. Apply the Home Manager configuration: +```bash +# Ensure Nix environment is sourced +source ~/.nix-profile/etc/profile.d/nix.sh + +# Apply configuration (will install Home Manager if needed) +make switch +``` + +## Synchronization + +To sync changes across machines: + +1. On the source machine: +```bash +git add . +git commit -m "Update configuration" +git push +``` + +2. On other machines: +```bash +cd ~/.dotfiles +git pull +home-manager switch +``` + +## Included Tools and Configurations + +- Shell: Zsh with Oh My Zsh +- Editor: Neovim with essential plugins +- Version Control: Git with sensible defaults +- Terminal Multiplexer: Tmux +- Development Tools: + - ripgrep + - fd + - fzf + - jq + - tree +- Programming Languages: + - Node.js + - Python 3 + - Rust + +## Troubleshooting + +If you encounter issues: + +1. Ensure Nix and Home Manager are properly installed: +```bash +nix --version +home-manager --version +``` + +2. Check for configuration errors: +```bash +home-manager build +``` + +3. View Home Manager logs: +```bash +journalctl -u home-manager-shunkakinoki +``` + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Contributing + +You can contribute in two ways: + +### Quick PR Creation + +Use our one-line command to create PRs directly: +```bash +# Basic usage (auto-fills PR title and body from commit) +make pr m='Your commit message' b='your-branch-name' + +# With custom PR title +make pr m='Your commit message' b='your-branch-name' t='Your PR title' +``` + +For example: +```bash +# Auto-filled PR title/body +make pr m='Add new zsh aliases' b='zsh-aliases' + +# Custom PR title +make pr m='Add new zsh aliases' b='zsh-aliases' t='feat: Enhanced ZSH Configuration' +``` + +This will: +1. Create a new feature branch +2. Add all changes +3. Commit with your message +4. Push to GitHub +5. Create a PR using GitHub CLI + - If no title (`t`) is provided, it will auto-fill from the commit + - If title is provided, it will use that with the commit message as the PR body + +Prerequisites: +- GitHub CLI is included in the Nix configuration +- Authenticate with GitHub: +```bash +gh auth login +``` + +### Manual Process + +1. Fork the repository +2. Create your feature branch (`git checkout -b feature/amazing-feature`) +3. Commit your changes (`git commit -m 'Add some amazing feature'`) +4. Push to the branch (`git push origin feature/amazing-feature`) +5. Open a Pull Request + +### Before Submitting + +Make sure to: +- Run `make format` to format Nix files +- Run `make format-check` to verify formatting +- Test your changes with `make switch` + +## Acknowledgments + +- [Nix](https://nixos.org/) +- [Home Manager](https://github.com/nix-community/home-manager) +- [Oh My Zsh](https://ohmyz.sh/) + +## Development Workflow + +This repository follows a PR-based workflow to ensure configuration stability. + +### Code Formatting + +All Nix files must be formatted using `nixpkgs-fmt` \ No newline at end of file diff --git a/REFERENCES.md b/REFERENCES.md new file mode 100644 index 000000000..747746b4c --- /dev/null +++ b/REFERENCES.md @@ -0,0 +1,6 @@ +# References + +- Mitchell Hashimoto's [nixos-config](https://github.com/mitchellh/nixos-config) +- Dustin Lyons' [nixos-config](https://github.com/dustinlyons/nixos-config) +- takeokunn's [nix-configuration](https://github.com/takeokunn/nixos-configuration) +- Carlos's [dotfiles](https://github.com/caarlos0/dotfiles) diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..dc0c85115 --- /dev/null +++ b/flake.lock @@ -0,0 +1,138 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1738453229, + "narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1739381933, + "narHash": "sha256-4gvobxITgcrNGfwsVG5a46QzQCX89btIYw23p0ilbcc=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "15b59d4191b993ebdfcb1f61b834fced217882ba", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1739302241, + "narHash": "sha256-NXQXFU6HOschZ+8ZKrNOlwlHelez8vPl+dCiUaJ82/U=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "a6746213b138fe7add88b19bafacd446de574ca7", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739138025, + "narHash": "sha256-M4ilIfGxzbBZuURokv24aqJTbdjPA9K+DtKUzrJaES4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b2243f41e860ac85c0b446eadc6930359b294e79", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1738452942, + "narHash": "sha256-vJzFZGaCpnmo7I6i416HaBLpC+hvcURh/BQwROcGIp8=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "home-manager": "home-manager", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1738953846, + "narHash": "sha256-yrK3Hjcr8F7qS/j2F+r7C7o010eVWWlm4T1PrbKBOxQ=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4f09b473c936d41582dd744e19f34ec27592c5fd", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..2051d2aaf --- /dev/null +++ b/flake.nix @@ -0,0 +1,67 @@ +{ + description = "Shun Kakinoki's Nix Configuration"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.05"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nix-darwin = { + url = "github:LnL7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + flake-parts, + treefmt-nix, + ... + }@inputs: + + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-linux" + ]; + + imports = [ treefmt-nix.flakeModule ]; + + flake = { + darwinConfigurations = { + aarch64-darwin = import ./hosts/darwin { inherit inputs; }; + runner = import ./hosts/darwin { + inherit inputs; + hostname = "runner"; + username = "runner"; + }; + }; + }; + + perSystem = + { ... }: + { + treefmt = { + projectRootFile = "flake.nix"; + programs = { + actionlint.enable = true; + biome.enable = true; + jsonfmt.enable = true; + nixfmt.enable = true; + shfmt.enable = true; + stylua.enable = true; + taplo.enable = true; + yamlfmt.enable = true; + }; + }; + }; + }; +} diff --git a/home-manager/default.nix b/home-manager/default.nix new file mode 100644 index 000000000..d664b800b --- /dev/null +++ b/home-manager/default.nix @@ -0,0 +1,51 @@ +{ + system, + nixpkgs, + lib ? nixpkgs.lib, +}: +let + # nvfetcher + # sources = pkgs.callPackage ../_sources/generated.nix { }; + + # packages + overlay = import ./overlay; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = overlay; + }; + packages = import ./packages { inherit pkgs; }; + + # misc + misc = import ./misc; + + # modules + modules = import ./modules; + + # Import programs + programs = import ./programs { + inherit lib pkgs; + sources = { }; + }; + + # services + services = import ./services { + inherit pkgs; + }; + +in +{ + imports = misc ++ modules ++ programs ++ services; + + home.stateVersion = "24.11"; + home.packages = packages; + + accounts.email.accounts = { + Gmail = { + primary = true; + flavor = "gmail.com"; + realName = "Shun Kakinoki"; + address = "shunkakinoki@gmail.com"; + }; + }; +} diff --git a/home-manager/misc/default.nix b/home-manager/misc/default.nix new file mode 100644 index 000000000..2bc15e204 --- /dev/null +++ b/home-manager/misc/default.nix @@ -0,0 +1,3 @@ +[ + ./nix +] diff --git a/home-manager/misc/nix/default.nix b/home-manager/misc/nix/default.nix new file mode 100644 index 000000000..12e689e73 --- /dev/null +++ b/home-manager/misc/nix/default.nix @@ -0,0 +1,8 @@ +{ + nix = { + enable = true; + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; +} diff --git a/home-manager/modules/default.nix b/home-manager/modules/default.nix new file mode 100644 index 000000000..2a5648efd --- /dev/null +++ b/home-manager/modules/default.nix @@ -0,0 +1,3 @@ +[ + ./dust +] diff --git a/home-manager/modules/dust/default.nix b/home-manager/modules/dust/default.nix new file mode 100644 index 000000000..dd45e785e --- /dev/null +++ b/home-manager/modules/dust/default.nix @@ -0,0 +1,25 @@ +{ + pkgs, + lib, + config, + ... +}: +let + cfg = config.programs.dust; +in +with lib; +{ + options.programs.dust = { + enable = mkEnableOption "A more intuitive version of du in rust"; + package = mkPackageOption pkgs "du-dust" { }; + config = mkOption { + type = types.lines; + default = ""; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile."dust/config.toml".text = cfg.config; + }; +} diff --git a/home-manager/overlay/default.nix b/home-manager/overlay/default.nix new file mode 100644 index 000000000..1e3ec7217 --- /dev/null +++ b/home-manager/overlay/default.nix @@ -0,0 +1 @@ +[ ] diff --git a/home-manager/packages/default.nix b/home-manager/packages/default.nix new file mode 100644 index 000000000..841404ae9 --- /dev/null +++ b/home-manager/packages/default.nix @@ -0,0 +1,11 @@ +{ pkgs }: +with pkgs; +[ + dust + gh + ghq + go + neofetch + ollama + rustup +] diff --git a/home-manager/programs/default.nix b/home-manager/programs/default.nix new file mode 100644 index 000000000..2c40e9f5f --- /dev/null +++ b/home-manager/programs/default.nix @@ -0,0 +1,17 @@ +{ + lib, + pkgs, + sources, +}: +let + dust = import ./dust; + gh = import ./gh; + starship = import ./starship; + zsh = import ./zsh { inherit lib pkgs; }; +in +[ + dust + gh + starship + zsh +] diff --git a/home-manager/programs/dust/default.nix b/home-manager/programs/dust/default.nix new file mode 100644 index 000000000..6c4a0b44c --- /dev/null +++ b/home-manager/programs/dust/default.nix @@ -0,0 +1,5 @@ +{ + programs.gh = { + enable = true; + }; +} diff --git a/home-manager/programs/gh/default.nix b/home-manager/programs/gh/default.nix new file mode 100644 index 000000000..ef9521319 --- /dev/null +++ b/home-manager/programs/gh/default.nix @@ -0,0 +1,9 @@ +{ + programs.gh = { + enable = true; + settings = { + git_protocol = "ssh"; + prompt = "enabled"; + }; + }; +} diff --git a/home-manager/programs/starship/default.nix b/home-manager/programs/starship/default.nix new file mode 100644 index 000000000..0432971bd --- /dev/null +++ b/home-manager/programs/starship/default.nix @@ -0,0 +1,6 @@ +{ + programs.starship = { + enable = true; + enableZshIntegration = true; + }; +} diff --git a/home-manager/programs/zsh/default.nix b/home-manager/programs/zsh/default.nix new file mode 100644 index 000000000..17e1892fa --- /dev/null +++ b/home-manager/programs/zsh/default.nix @@ -0,0 +1,42 @@ +{ lib, pkgs, ... }: + +{ + programs.zsh = { + enable = true; + enableCompletion = true; + autosuggestion.enable = true; + syntaxHighlighting.enable = true; + historySubstringSearch.enable = true; + + history = { + size = 50000; + save = 50000; + path = "$HOME/.zsh_history"; + ignoreDups = true; + share = true; + extended = true; + }; + + initExtra = '' + # Initialize Starship + eval "$(starship init zsh)" + + eval "$(sheldon source)" + eval "$(direnv hook zsh)" + eval "$(/opt/homebrew/bin/brew shellenv)" + source "$HOME/.rye/env" + + # FNM (Fast Node Manager) configuration + export FNM_DIR="$HOME/Library/Application Support/fnm" + export FNM_COREPACK_ENABLED="false" + export FNM_ARCH="arm64" + export FNM_RESOLVE_ENGINES="false" + export FNM_LOGLEVEL="info" + export FNM_NODE_DIST_MIRROR="https://nodejs.org/dist" + export FNM_VERSION_FILE_STRATEGY="local" + + # OpenRouter API Key + export OPENROUTER_API_KEY_AVANTE=$(security find-generic-password -a "avante" -s "shunkakinoki" -w) + ''; + }; +} diff --git a/home-manager/services/default.nix b/home-manager/services/default.nix new file mode 100644 index 000000000..7a79ac474 --- /dev/null +++ b/home-manager/services/default.nix @@ -0,0 +1,7 @@ +{ pkgs }: +let + ollamaModule = import ./ollama { inherit pkgs; }; +in +[ + ollamaModule +] diff --git a/home-manager/services/ollama/default.nix b/home-manager/services/ollama/default.nix new file mode 100644 index 000000000..e31b64bf9 --- /dev/null +++ b/home-manager/services/ollama/default.nix @@ -0,0 +1,6 @@ +{ pkgs }: +{ + services.ollama = { + enable = pkgs.stdenv.isLinux; + }; +} diff --git a/hosts/darwin/default.nix b/hosts/darwin/default.nix new file mode 100644 index 000000000..d113c41fe --- /dev/null +++ b/hosts/darwin/default.nix @@ -0,0 +1,34 @@ +{ + inputs, + username ? "shunkakinoki", + hostname ? "aarch64-darwin", +}: +let + inherit (inputs) nix-darwin home-manager; + system = "aarch64-darwin"; + configuration = + { ... }: + { + networking.hostName = hostname; + users.users.${username}.home = "/Users/${username}"; + }; +in +nix-darwin.lib.darwinSystem { + inherit system; + inherit (inputs.nixpkgs) lib; + specialArgs = { + inherit username; + }; + modules = [ + configuration + ../../nix-darwin + home-manager.darwinModules.home-manager + { + home-manager.useUserPackages = true; + home-manager.users."${username}" = import ../../home-manager { + inherit system; + nixpkgs = inputs.nixpkgs; + }; + } + ]; +} diff --git a/install.sh b/install.sh new file mode 100755 index 000000000..78beff289 --- /dev/null +++ b/install.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Exit on error +set -e + +# Detect OS +if [[ $OSTYPE == "darwin"* ]]; then + OS="macos" +elif [[ $OSTYPE == "linux-gnu"* ]]; then + OS="linux" +else + echo "Unsupported operating system: $OSTYPE" + exit 1 +fi + +# Install Nix if not already installed +if ! command -v nix &>/dev/null; then + echo "Installing Nix..." + if [[ $OS == "macos" ]]; then + sh <(curl -L https://nixos.org/nix/install) --daemon + else + sh <(curl -L https://nixos.org/nix/install) --daemon + fi +fi diff --git a/nix-darwin/config/dock.nix b/nix-darwin/config/dock.nix new file mode 100644 index 000000000..a4d164b1e --- /dev/null +++ b/nix-darwin/config/dock.nix @@ -0,0 +1,31 @@ +{ + imports = [ + ./dock + ]; + + local = { + dock.enable = true; + dock.entries = [ + { path = "/Applications/Slack.app/"; } + { path = "/System/Applications/Messages.app/"; } + { path = "/System/Applications/Facetime.app/"; } + { path = "/Applications/Telegram.app/"; } + { path = "/System/Applications/Music.app/"; } + { path = "/System/Applications/News.app/"; } + { path = "/System/Applications/Photos.app/"; } + { path = "/System/Applications/Photo Booth.app/"; } + { path = "/System/Applications/TV.app/"; } + { path = "/System/Applications/Home.app/"; } + { + path = "${config.users.users.${user}.home}/.local/share/"; + section = "others"; + options = "--sort name --view grid --display folder"; + } + { + path = "${config.users.users.${user}.home}/.local/share/downloads"; + section = "others"; + options = "--sort name --view grid --display stack"; + } + ]; + }; +} diff --git a/nix-darwin/config/fonts.nix b/nix-darwin/config/fonts.nix new file mode 100644 index 000000000..3b71fdff5 --- /dev/null +++ b/nix-darwin/config/fonts.nix @@ -0,0 +1,9 @@ +{ pkgs }: +{ + fonts = { + packages = [ + pkgs.fira-code + pkgs.jetbrains-mono + ]; + }; +} diff --git a/nix-darwin/config/homebrew.nix b/nix-darwin/config/homebrew.nix new file mode 100644 index 000000000..d4757759b --- /dev/null +++ b/nix-darwin/config/homebrew.nix @@ -0,0 +1,45 @@ +{ + homebrew = { + enable = true; + onActivation = { + autoUpdate = true; + upgrade = true; + cleanup = "zap"; + extraFlags = [ "--force" ]; + }; + taps = [ + "homebrew/cask" + "homebrew/services" + ]; + brews = [ + "direnv" + "gnupg" + "mas" + "pinentry-mac" + "sheldon" + ]; + casks = [ + "chatgpt" + "cursor" + "discord" + "docker" + "figma" + "ghostty" + "google-chrome" + "google-drive" + "hammerspoon" + "linear-linear" + "notion" + "raycast" + "screen-studio" + "sf-symbols" + "slack" + "visual-studio-code" + "zoom" + ]; + masApps = { + "Notability" = 360593530; + "Xcode" = 497799835; + }; + }; +} diff --git a/nix-darwin/config/launchd.nix b/nix-darwin/config/launchd.nix new file mode 100644 index 000000000..65922631d --- /dev/null +++ b/nix-darwin/config/launchd.nix @@ -0,0 +1,14 @@ +{ pkgs }: +{ + launchd.agents.ollama = { + serviceConfig = { + ProgramArguments = [ + "${pkgs.ollama}/bin/ollama" + "serve" + ]; + KeepAlive = true; + RunAtLoad = true; + EnvironmentVariables.OLLAMA_HOST = "0.0.0.0"; + }; + }; +} diff --git a/nix-darwin/config/networking.nix b/nix-darwin/config/networking.nix new file mode 100644 index 000000000..9319bb717 --- /dev/null +++ b/nix-darwin/config/networking.nix @@ -0,0 +1,14 @@ +{ + networking = { + knownNetworkServices = [ + "Wi-Fi" + "Ethernet Adaptor" + "Thunderbolt Ethernet" + ]; + dns = [ + "8.8.8.8" + "8.8.4.4" + "1.1.1.1" + ]; + }; +} diff --git a/nix-darwin/config/nix.nix b/nix-darwin/config/nix.nix new file mode 100644 index 000000000..6ad3171ea --- /dev/null +++ b/nix-darwin/config/nix.nix @@ -0,0 +1,9 @@ +{ + nix = { + optimise.automatic = true; + settings = { + experimental-features = "nix-command flakes"; + max-jobs = 8; + }; + }; +} diff --git a/nix-darwin/config/security.nix b/nix-darwin/config/security.nix new file mode 100644 index 000000000..cf0471d38 --- /dev/null +++ b/nix-darwin/config/security.nix @@ -0,0 +1,9 @@ +{ username }: +{ + security = { + sudo.extraConfig = '' + ${username} ALL=NOPASSWD: ALL + ''; + pam.enableSudoTouchIdAuth = true; + }; +} diff --git a/nix-darwin/config/system.nix b/nix-darwin/config/system.nix new file mode 100644 index 000000000..5c8374e35 --- /dev/null +++ b/nix-darwin/config/system.nix @@ -0,0 +1,79 @@ +{ pkgs }: +{ + ids.gids.nixbld = 350; + system = { + stateVersion = 4; + defaults = { + SoftwareUpdate.AutomaticallyInstallMacOSUpdates = true; + LaunchServices.LSQuarantine = false; + CustomSystemPreferences = { + "com.apple.screensaver" = { + askForPassword = true; + askForPasswordDelay = 0; + }; + "com.apple.screencapture" = { + location = "~/Desktop"; + type = "png"; + }; + }; + NSGlobalDomain = { + AppleShowAllExtensions = true; + InitialKeyRepeat = 15; + KeyRepeat = 2; + NSAutomaticCapitalizationEnabled = false; + NSAutomaticSpellingCorrectionEnabled = false; + NSNavPanelExpandedStateForSaveMode = true; + NSNavPanelExpandedStateForSaveMode2 = true; + PMPrintingExpandedStateForPrint = true; + PMPrintingExpandedStateForPrint2 = true; + "com.apple.swipescrolldirection" = true; + "com.apple.keyboard.fnState" = false; + }; + finder = { + AppleShowAllExtensions = true; + AppleShowAllFiles = true; + FXEnableExtensionChangeWarning = false; + _FXShowPosixPathInTitle = true; + CreateDesktop = false; + QuitMenuItem = true; + ShowPathbar = true; + ShowStatusBar = true; + }; + dock = { + autohide = true; + persistent-apps = [ + "/System/Applications/Reminders.app" + "/System/Applications/Notes.app" + "/System/Applications/Calendar.app" + "/Applications/Chrome.app" + "/Applications/Ghostty.app" + "/System/Applications/Mail.app" + "/System/Applications/Messages.app" + "/Applications/Discord.app" + "/System/Applications/Music.app" + ]; + orientation = "bottom"; + showhidden = true; + mru-spaces = false; + minimize-to-application = true; + show-recents = false; + static-only = true; + tilesize = 48; + magnification = false; + }; + trackpad = { + Clicking = true; + Dragging = true; + TrackpadRightClick = true; + TrackpadThreeFingerDrag = false; + ActuationStrength = 0; + FirstClickThreshold = 0; + SecondClickThreshold = 0; + TrackpadThreeFingerTapGesture = 2; + }; + }; + # activationScripts.extraActivation.text = '' + # softwareupdate --all --install + # ''; + }; +} diff --git a/nix-darwin/config/time.nix b/nix-darwin/config/time.nix new file mode 100644 index 000000000..700b74bf2 --- /dev/null +++ b/nix-darwin/config/time.nix @@ -0,0 +1,3 @@ +{ + # time.timeZone = "America/San_Francisco"; +} diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix new file mode 100644 index 000000000..6efa2133d --- /dev/null +++ b/nix-darwin/default.nix @@ -0,0 +1,29 @@ +{ + pkgs, + lib, + username, + ... +}: +let + fonts = import ./config/fonts.nix { inherit pkgs; }; + # homebrew = import ./config/homebrew.nix; + launchd = import ./config/launchd.nix { inherit pkgs; }; + networking = import ./config/networking.nix; + nix = import ./config/nix.nix; + security = import ./config/security.nix { inherit username; }; + system = import ./config/system.nix { inherit pkgs; }; + time = import ./config/time.nix; + +in +{ + imports = [ + fonts + # homebrew + launchd + networking + nix + security + system + time + ]; +}