diff --git a/nix/README.md b/nix/README.md new file mode 100644 index 0000000..5dc8d9e --- /dev/null +++ b/nix/README.md @@ -0,0 +1,22 @@ +# Nix Dotfiles + +This is my folder where I migrate my current dotfile setup to [Nix](https://nixos.org/), [nix-darwin](https://github.com/LnL7/nix-darwin), and [home-manager](https://github.com/nix-community/home-manager). + +> [!DANGER] Warning +> This is a work in progress and I am still learning Nix, so expect things to be broken. + +```sh +# First time install +nix run nix-darwin -- switch --flake ~/.config/nix-darwin +``` + +Make sure this is added to your path: + +```sh +export PATH="/run/current-system/sw/bin:$PATH" +``` + +```sh +# Switch to new configuration +darwin-rebuild switch --flake ~/.dotfiles/nix +``` diff --git a/nix/darwin/default.nix b/nix/darwin/default.nix new file mode 100644 index 0000000..cd335aa --- /dev/null +++ b/nix/darwin/default.nix @@ -0,0 +1,32 @@ +{ pkgs, config, ... }: + +{ + homebrew = import ./homebrew.nix // { enable = true; }; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + services.karabiner-elements.enable = true; + + # Necessary for using flakes on this system. + nix.settings.experimental-features = "nix-command flakes"; + nixpkgs.config.allowUnfree = true; + + # Create /etc/zshrc that loads the nix-darwin environment. + programs.zsh.enable = true; # default shell on catalina + # programs.fish.enable = true; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; + + system.defaults.NSGlobalDomain.ApplePressAndHoldEnabled = false; + system.defaults.dock.autohide = true; + + system.defaults.NSGlobalDomain.InitialKeyRepeat = 15; + system.defaults.NSGlobalDomain.KeyRepeat = 2; + + nixpkgs.hostPlatform = "aarch64-darwin"; + + services.skhd.enable = true; + services.yabai.enable = true; +} diff --git a/nix/darwin/homebrew.nix b/nix/darwin/homebrew.nix new file mode 100644 index 0000000..7c5ecce --- /dev/null +++ b/nix/darwin/homebrew.nix @@ -0,0 +1,8 @@ +{ + # TODO: Activate after migration is complete + # onActivation.cleanup = "uninstall"; + taps = [ ]; + brews = [ ]; + casks = [ "raycast" ]; + masApps = { }; +} diff --git a/nix/flake.lock b/nix/flake.lock new file mode 100644 index 0000000..7c9772a --- /dev/null +++ b/nix/flake.lock @@ -0,0 +1,171 @@ +{ + "nodes": { + "cl-nix-lite": { + "locked": { + "lastModified": 1717972076, + "narHash": "sha256-hnZEsDInTcsVSL5LBGDAZegAxVLBus/wiJh+sNM15zU=", + "owner": "hraban", + "repo": "cl-nix-lite", + "rev": "cc920bfb0a6402d3871f470c98d65266126973e4", + "type": "github" + }, + "original": { + "owner": "hraban", + "repo": "cl-nix-lite", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1697816753, + "narHash": "sha256-40to80AEIyKCQI0xMKCeF5ePoIKTYgjVVCZeu4CnTxM=", + "owner": "hraban", + "repo": "flake-compat", + "rev": "6025bade1336a36014639bc3f67eacc853dab78f", + "type": "github" + }, + "original": { + "owner": "hraban", + "ref": "fixed-output", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719438532, + "narHash": "sha256-/Vmso2ZMoFE3M7d1MRsQ2K5sR8CVKnrM6t1ys9Xjpz4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "1a4f12ae0bda877ec4099b429cf439aad897d7e9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "mac-app-util": { + "inputs": { + "cl-nix-lite": "cl-nix-lite", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1718893255, + "narHash": "sha256-NdSDGdz5eU/EcnGn8ECP1V+mn5hyGOZQ4ybv2bWTpuk=", + "owner": "hraban", + "repo": "mac-app-util", + "rev": "1857b26aceaf64c2b6a357eb83cf34139b6365cc", + "type": "github" + }, + "original": { + "owner": "hraban", + "repo": "mac-app-util", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719128254, + "narHash": "sha256-I7jMpq0CAOZA/i70+HDQO/ulLttyQu/K70cSESiMX7A=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "50581970f37f06a4719001735828519925ef8310", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717868076, + "narHash": "sha256-c83Y9t815Wa34khrux81j8K8ET94ESmCuwORSKm2bQY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cd18e2ae9ab8e2a0a8d715b60c91b54c0ac35ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cd18e2ae9ab8e2a0a8d715b60c91b54c0ac35ff9", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1719254875, + "narHash": "sha256-ECni+IkwXjusHsm9Sexdtq8weAq/yUyt1TWIemXt3Ko=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "mac-app-util": "mac-app-util", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..60d8ac7 --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,39 @@ +{ + description = "My Darwin and home-manager dotfiles"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + + nix-darwin = { + url = "github:LnL7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + mac-app-util.url = "github:hraban/mac-app-util"; + }; + + outputs = { self, nix-darwin, home-manager, nixpkgs, mac-app-util }: { + # Build darwin flake using: + # $ darwin-rebuild switch --flake ~/.dotfiles/nix/.#mac-mini + darwinConfigurations."mac-mini" = nix-darwin.lib.darwinSystem { + modules = [ + ./hosts/mac-mini/configuration.nix + + mac-app-util.darwinModules.default + + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.verbose = true; + home-manager.users.kogakure.imports = [ ./hosts/mac-mini/home.nix mac-app-util.homeManagerModules.default ]; + } + ]; + }; + }; +} diff --git a/nix/home/default.nix b/nix/home/default.nix new file mode 100644 index 0000000..b8afb8f --- /dev/null +++ b/nix/home/default.nix @@ -0,0 +1,33 @@ +{ pkgs, config, lib, home-manager, ... }: + +let + isDarwin = pkgs.stdenv.isDarwin; +in +{ + # https://nix-community.github.io/home-manager/options.html + imports = [ + ./skhd + ./yabai + ]; + + config = { + home.stateVersion = "23.05"; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; + + # TODO: First migrate all fonts + # fonts.fontconfig.enable = true; + + # The home.packages option allows you to install Nix packages into your + # environment. + home.packages = with pkgs; [ + nixpkgs-fmt + ripgrep + ]; + + home.sessionVariables = { + EDITOR = "vim"; + }; + }; +} diff --git a/nix/home/skhd/default.nix b/nix/home/skhd/default.nix new file mode 100644 index 0000000..5ee0daa --- /dev/null +++ b/nix/home/skhd/default.nix @@ -0,0 +1,16 @@ +{ pkgs, config, lib, home-manager, ... }: + +{ + options.services.skhd = { + enable = lib.mkEnableOption "skhd"; + }; + + config = { + home.file.".config/skhd/skhdrc" = lib.mkIf + config.services.skhd.enable + { + source = ./skhdrc; + onChange = "${pkgs.killall}/bin/killall skhd"; + }; + }; +} diff --git a/nix/home/skhd/skhdrc b/nix/home/skhd/skhdrc new file mode 100644 index 0000000..95a856b --- /dev/null +++ b/nix/home/skhd/skhdrc @@ -0,0 +1,55 @@ +# Focus Windows +alt - h : yabai -m window --focus west +alt - j : yabai -m window --focus south +alt - k : yabai -m window --focus north +alt - l : yabai -m window --focus east + +# Swap Managed Windows +shift + alt - h : yabai -m window --swap west +shift + alt - j : yabai -m window --swap south +shift + alt - k : yabai -m window --swap north +shift + alt - l : yabai -m window --swap east + +# Move Managed Windows +shift + alt + ctrl - h : yabai -m window --warp west +shift + alt + ctrl - j : yabai -m window --warp south +shift + alt + ctrl - k : yabai -m window --warp north +shift + alt + ctrl - l : yabai -m window --warp east + +# Rotate Windows +alt - r : yabai -m space --rotate 90 + +# Toggle Window Fullscreen Zoom +alt - f : yabai -m window --toggle zoom-fullscreen + +# Toggle Padding and Gap +alt - g : yabai -m space --toggle padding; yabai -m space --toggle gap + +# Float/Unfloat Window and Center on Screen +alt - t : yabai -m window --toggle float;\ + yabai -m window --grid 8:8:1:1:6:6 + +# Toggle Window Split Type +alt - e : yabai -m window --toggle split + +# Balance Size of Windows +shift + alt - 0 : yabai -m space --balance + +# Move Window and Focus Desktop +shift + alt + ctrl - 1 : yabai -m window --space 1 +shift + alt + ctrl - 2 : yabai -m window --space 2 +shift + alt + ctrl - 3 : yabai -m window --space 3 +shift + alt + ctrl - 4 : yabai -m window --space 4 +shift + alt + ctrl - 5 : yabai -m window --space 5 +shift + alt + ctrl - 6 : yabai -m window --space 6 +shift + alt + ctrl - 7 : yabai -m window --space 7 +shift + alt + ctrl - 8 : yabai -m window --space 8 +shift + alt + ctrl - 9 : yabai -m window --space 9 + +# Send Window to Monitor and Follow Focus +shift + alt - n : yabai -m window --display next; yabai -m display --focus next +shift + alt - p : yabai -m window --display prev; yabai -m display --focus prev + +# Move Focus to Monitor +shift + alt + cmd - h : yabai -m display --focus next +shift + alt + cmd - l : yabai -m display --focus prev diff --git a/nix/home/yabai/default.nix b/nix/home/yabai/default.nix new file mode 100644 index 0000000..99806d1 --- /dev/null +++ b/nix/home/yabai/default.nix @@ -0,0 +1,16 @@ +{ pkgs, lib, config, ... }: + +{ + options.services.yabai = { + enable = lib.mkEnableOption "yabai"; + }; + + config = { + home.file.".config/yabai/yabairc" = lib.mkIf + config.services.yabai.enable + { + source = ./yabairc; + onChange = "${pkgs.killall}/bin/killall yabai"; + }; + }; +} diff --git a/nix/home/yabai/yabairc b/nix/home/yabai/yabairc new file mode 100644 index 0000000..b8c77cb --- /dev/null +++ b/nix/home/yabai/yabairc @@ -0,0 +1,60 @@ + #!/usr/bin/env sh + +sudo yabai --load-sa +yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa" + +# Global settings +yabai -m config mouse_follows_focus off +yabai -m config focus_follows_mouse off +yabai -m config window_origin_display default +yabai -m config window_placement second_child +yabai -m config window_topmost off +yabai -m config window_shadow on +yabai -m config window_opacity off +yabai -m config window_opacity_duration 0.0 +yabai -m config active_window_opacity 1.0 +yabai -m config normal_window_opacity 0.90 +yabai -m config window_border off +yabai -m config window_border_width 6 +yabai -m config active_window_border_color 0xff775759 +yabai -m config normal_window_border_color 0xff555555 +yabai -m config insert_feedback_color 0xffd75f5f +yabai -m config split_ratio 0.70 +yabai -m config auto_balance off +yabai -m config mouse_modifier fn +yabai -m config mouse_action1 move +yabai -m config mouse_action2 resize +yabai -m config mouse_drop_action swap + +# General Space Settings +yabai -m config layout bsp +yabai -m config window_gap 10 + +yabai -m config top_padding 10 +yabai -m config bottom_padding 10 +yabai -m config left_padding 10 +yabai -m config right_padding 10 + +# Sketchybar +# yabai -m config external_bar all:32:0 + +# New window spawns to the right if vertical split, or bottom if horizontal split +yabai -m config window_placement second_child + +# Apps to ignore +yabai -m rule --add app="^System Preferences$" manage=off +yabai -m rule --add app="^System Settings$" manage=off +yabai -m rule --add app="^FortiClient$" manage=off +yabai -m rule --add app="^Calculator$" manage=off +yabai -m rule --add app="^Archive Utility$" manage=off +yabai -m rule --add app="^Alfred Preferences$" manage=off +yabai -m rule --add app="Raycast" manage=off +yabai -m rule --add app="Dropbox Dash" manage=off +yabai -m rule --add app="Proton Pass" manage=off +yabai -m rule --add app="Pika" manage=off +yabai -m rule --add app="Microsoft Teams" manage=off +yabai -m rule --add app="CleanShot X" manage=off mouse_follows_focus=off layer=above +yabai -m rule --add app="^Dash$" sticky=on layer=above manage=off +yabai -m rule --add app="^IINA$" sticky=on layer=above manage=off + +echo "Yabai configuration loaded …" diff --git a/nix/hosts/mac-mini/configuration.nix b/nix/hosts/mac-mini/configuration.nix new file mode 100644 index 0000000..3e51955 --- /dev/null +++ b/nix/hosts/mac-mini/configuration.nix @@ -0,0 +1,12 @@ +{ pkgs, config, ... }: + +{ + imports = [ + ../../darwin + ]; + + users.users.kogakure = { + name = "kogakure"; + home = "/Users/kogakure"; + }; +} diff --git a/nix/hosts/mac-mini/home.nix b/nix/hosts/mac-mini/home.nix new file mode 100644 index 0000000..18a999a --- /dev/null +++ b/nix/hosts/mac-mini/home.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: + +{ + imports = [ + ../../home + ]; + + services.yabai.enable = true; + services.skhd.enable = true; +}