feat(nix): proper nix-darwin setup with new MBA

Changed files
+212 -138
nix
+174
nix/darwin.nix
··· 1 + { self, pkgs, pkgs-unstable, ... }: { 2 + # List packages installed in system profile. To search by name, run: 3 + # $ nix-env -qaP | grep wget 4 + environment.systemPackages = 5 + [ 6 + pkgs.brave 7 + pkgs.fzf 8 + pkgs.tmux 9 + pkgs.tree 10 + pkgs.vim 11 + # I don't want to touch this due to current neovim settings. 12 + # remove it when lux.nvim is out 13 + (pkgs-unstable.lua5_1.withPackages (ps: with ps; [luarocks])) 14 + ]; 15 + 16 + # Necessary for using flakes on this system. 17 + nix.settings.experimental-features = "nix-command flakes"; 18 + # Enable rosetta binaries 19 + nix.settings.extra-platforms = "x86_64-darwin aarch64-darwin"; 20 + 21 + # Enable alternative shell support in nix-darwin. 22 + # programs.fish.enable = true; 23 + 24 + # Set Git commit hash for darwin-version. 25 + system.configurationRevision = self.rev or self.dirtyRev or null; 26 + 27 + # Used for backwards compatibility, please read the changelog before changing. 28 + # $ darwin-rebuild changelog 29 + system.stateVersion = 5; 30 + 31 + # The platform the configuration will be used on. 32 + nixpkgs.hostPlatform = "aarch64-darwin"; 33 + 34 + system.defaults.finder = { 35 + FXRemoveOldTrashItems = true; 36 + ShowPathbar = true; 37 + ShowStatusBar = true; 38 + }; 39 + 40 + system.defaults.dock = { 41 + autohide = true; 42 + autohide-delay = 0.0; 43 + autohide-time-modifier = 0.6; 44 + mru-spaces = false; 45 + show-recents = false; 46 + # Disable bottom-right corner action 47 + wvous-br-corner = 1; 48 + # persistent-apps = []; 49 + }; 50 + 51 + system.defaults.NSGlobalDomain = { 52 + AppleShowAllExtensions = true; 53 + # default minimum is 15 (225ms) 54 + InitialKeyRepeat = 10; 55 + # default minimum is 2 (30ms) 56 + KeyRepeat = 1; 57 + }; 58 + 59 + # reference https://medium.com/@zmre/nix-darwin-quick-tip-activate-your-preferences-f69942a93236 60 + # for more 61 + # https://gist.github.com/ChristopherA/98628f8cd00c94f11ee6035d53b0d3c6 62 + # is also cool 63 + system.defaults.CustomUserPreferences = { 64 + # see https://apple.stackexchange.com/a/429820 65 + "com.apple.Safari.SandboxBroker" = { 66 + ShowDevelopMenu = true; 67 + }; 68 + "com.apple.Safari" = { 69 + IncludeDevelopMenu = true; 70 + IncludeInternalDebugMenu = true; 71 + SearchProviderIdentifier = "com.duckduckgo"; 72 + ShowFullURLInSmartSearchField = true; 73 + # preview url on bottom left corner when hover links 74 + ShowOverlayStatusBar = true; 75 + WebAutomaticSpellingCorrectionEnabled = false; 76 + WebContinuousSpellCheckingEnabled = true; 77 + WebKitDeveloperExtrasEnabledPreferenceKey = true; 78 + }; 79 + # Tried to set Mission Control keyboard shortcuts... but failed 80 + # "com.apple.symbolichotkeys" = { 81 + # AppleSymbolicHotKeys = { 82 + # "79" = { 83 + # enabled = 1; 84 + # value = { 85 + # parameters = [65535 123 8650752]; 86 + # type = "standard"; 87 + # }; 88 + # }; 89 + # "80" = { 90 + # enabled = 1; 91 + # value = { 92 + # parameters = [65535 123 8781824]; 93 + # type = "standard"; 94 + # }; 95 + # }; 96 + # "81" = { 97 + # enabled = 1; 98 + # value = { 99 + # parameters = [65535 124 8650752]; 100 + # type = "standard"; 101 + # }; 102 + # }; 103 + # "82" = { 104 + # enabled = 1; 105 + # value = { 106 + # parameters = [65535 124 8781824]; 107 + # type = "standard"; 108 + # }; 109 + # }; 110 + # "118" = { 111 + # enabled = 1; 112 + # value = { 113 + # parameters = [65535 18 262144]; 114 + # type = "standard"; 115 + # }; 116 + # }; 117 + # # 119 = { 118 + # # enabled = 1; 119 + # # value = { 120 + # # parameters = [65535, 19, 262144]; 121 + # # type = "standard"; 122 + # # }; 123 + # # }; 124 + # # 120 = { 125 + # # enabled = 1; 126 + # # value = { 127 + # # parameters = [65535, 20, 262144]; 128 + # # type = "standard"; 129 + # # }; 130 + # # }; 131 + # # 121 = { 132 + # # enabled = 1; 133 + # # value = { 134 + # # parameters = [65535, 21, 262144]; 135 + # # type = "standard"; 136 + # # }; 137 + # # }; 138 + # # 122 = { 139 + # # enabled = 1; 140 + # # value = { 141 + # # parameters = [65535, 23, 262144]; 142 + # # type = "standard"; 143 + # # }; 144 + # # }; 145 + # }; 146 + # }; 147 + }; 148 + 149 + # NOTE: put SaneSideButtons (installed via homebrew cask) to Login Items 150 + # reference: https://discourse.nixos.org/t/automatically-launching-macos-applications-on-login/19823/2 151 + # TODO: package this into single nix package with SaneSideButtons itself. See pkgs.sensible-side-buttons as a reference 152 + system.activationScripts.extraActivation.text = '' 153 + osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/SaneSideButtons.app", hidden:false}' 154 + ''; 155 + 156 + # # Enable Touch ID support 157 + # security.pam.enableSudoTouchIdAuth = true; 158 + 159 + homebrew = { 160 + enable = true; 161 + casks = [ 162 + "discord" 163 + "ghostty" 164 + "raycast" 165 + # there are also pkgs.sensible-side-buttons (original version) which is unfree license 166 + # this one is foked version of it: "SaneSideButtons" 167 + # NOTE: I should put this on Login Items manually. See: https://github.com/thealpa/SaneSideButtons 168 + "sanesidebuttons" 169 + ]; 170 + masApps = { 171 + Things3 = 904280696; 172 + }; 173 + }; 174 + }
+38 -41
nix/flake.nix
··· 1 1 { 2 - description = "Example nix-darwin system flake"; 2 + description = "nix-darwin system flake"; 3 3 4 4 inputs = { 5 - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 6 - nix-darwin.url = "github:LnL7/nix-darwin/master"; 5 + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.11-darwin"; 6 + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 7 + 8 + nix-darwin.url = "github:nix-darwin/nix-darwin/nix-darwin-24.11"; 7 9 nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; 8 - home-manager.url = "github:nix-community/home-manager/release-24.11"; 9 - home-manager.inputs.nixpkgs.follows = "nixpkgs"; 10 10 }; 11 11 12 - outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager }: 12 + outputs = inputs@{ 13 + self, 14 + nix-darwin, 15 + nixpkgs, 16 + nixpkgs-unstable 17 + }: 13 18 let 14 - configuration = { pkgs, ... }: { 15 - # List packages installed in system profile. To search by name, run: 16 - # $ nix-env -qaP | grep wget 17 - environment.systemPackages = 18 - with pkgs; [ 19 - vim 20 - typescript-language-server 21 - (pkgs.lua5_1.withPackages (ps: with ps; [luarocks])) 22 - ]; 23 - 24 - # Necessary for using flakes on this system. 25 - nix.settings.experimental-features = "nix-command flakes"; 26 - nix.settings.extra-platforms = "x86_64-darwin aarch64-darwin"; 27 - 28 - # Enable alternative shell support in nix-darwin. 29 - # programs.fish.enable = true; 30 - 31 - # Set Git commit hash for darwin-version. 32 - system.configurationRevision = self.rev or self.dirtyRev or null; 33 - 34 - # Used for backwards compatibility, please read the changelog before changing. 35 - # $ darwin-rebuild changelog 36 - system.stateVersion = 6; 37 - 38 - # The platform the configuration will be used on. 39 - nixpkgs.hostPlatform = "aarch64-darwin"; 40 - }; 19 + system = "aarch64-darwin"; 20 + pkgs = nixpkgs.legacyPackages.${system}; 21 + pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; 41 22 in 42 23 { 43 24 # Build darwin flake using: 44 - # $ darwin-rebuild build --flake .#simple 45 - darwinConfigurations."macbook" = nix-darwin.lib.darwinSystem { 46 - # system = "aarch64-darwin"; 25 + # $ darwin-rebuild build --flake ~/.config/nix 26 + # $ darwin-rebuild switch --flake ~/.config/nix 27 + darwinConfigurations."boltless-MacBook-Air" = nix-darwin.lib.darwinSystem { 47 28 modules = [ 48 - # home-manager.darwinModules.home-manager 49 - configuration 29 + ./darwin.nix 50 30 ]; 31 + specialArgs = { 32 + inherit self pkgs-unstable; 33 + }; 51 34 }; 52 - homeConfigurations."ubuntu" = home-manager.lib.homeManagerConfiguration { 53 - pkgs = nixpkgs.legacyPackages."aarch64-linux"; 54 - modules = [ ./home.nix ]; 35 + # based on https://zaynetro.com/post/2024-you-dont-need-home-manager-nix 36 + # $ nix profile install . 37 + # $ nix profile upgrade nix 38 + packages.${system}.default = pkgs.buildEnv { 39 + name = "my-env"; 40 + paths = [ 41 + pkgs.btop 42 + pkgs.gh 43 + pkgs.hello 44 + pkgs.janet 45 + pkgs.meld 46 + pkgs.sumneko-lua-language-server 47 + pkgs.unixtools.watch 48 + pkgs-unstable.jujutsu 49 + pkgs-unstable.neovim 50 + ]; 55 51 }; 56 52 }; 57 53 } 54 + # vim: et:ts=2
-97
nix/home.nix
··· 1 - { config, pkgs, ... }: 2 - 3 - # NOTE: I use nix as a package manager, not to make revisions for my entire dotfiles 4 - # I want nix to organize files and automate symlinking 5 - 6 - { 7 - # Home Manager needs a bit of information about you and the paths it should 8 - # manage. 9 - home.username = "ubuntu"; 10 - home.homeDirectory = "/home/ubuntu"; 11 - 12 - # This value determines the Home Manager release that your configuration is 13 - # compatible with. This helps avoid breakage when a new Home Manager release 14 - # introduces backwards incompatible changes. 15 - # 16 - # You should not change this value, even if you update Home Manager. If you do 17 - # want to update the value, then make sure to first check the Home Manager 18 - # release notes. 19 - home.stateVersion = "24.05"; # Please read the comment before changing. 20 - 21 - # The home.packages option allows you to install Nix packages into your 22 - # environment. 23 - home.packages = [ 24 - # # Adds the 'hello' command to your environment. It prints a friendly 25 - # # "Hello, world!" when run. 26 - # pkgs.hello 27 - # pkgs.neovim 28 - pkgs.sumneko-lua-language-server 29 - pkgs.janet 30 - # pkgs.jpm 31 - pkgs.cachix 32 - pkgs.helix 33 - # pkgs.emscripten 34 - # pkgs.neovim-nightly 35 - 36 - # # It is sometimes useful to fine-tune packages, for example, by applying 37 - # # overrides. You can do that directly here, just don't forget the 38 - # # parentheses. Maybe you want to install Nerd Fonts with a limited number of 39 - # # fonts? 40 - # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) 41 - 42 - # # You can also create simple shell scripts directly inside your 43 - # # configuration. For example, this adds a command 'my-hello' to your 44 - # # environment: 45 - # (pkgs.writeShellScriptBin "my-hello" '' 46 - # echo "Hello, ${config.home.username}!" 47 - # '') 48 - ]; 49 - 50 - # Home Manager is pretty good at managing dotfiles. The primary way to manage 51 - # plain files is through 'home.file'. 52 - home.file = { 53 - # # Building this configuration will create a copy of 'dotfiles/screenrc' in 54 - # # the Nix store. Activating the configuration will then make '~/.screenrc' a 55 - # # symlink to the Nix store copy. 56 - # ".screenrc".source = dotfiles/screenrc; 57 - 58 - # # You can also set the file content immediately. 59 - # ".gradle/gradle.properties".text = '' 60 - # org.gradle.console=verbose 61 - # org.gradle.daemon.idletimeout=3600000 62 - # ''; 63 - }; 64 - 65 - # Home Manager can also manage your environment variables through 66 - # 'home.sessionVariables'. These will be explicitly sourced when using a 67 - # shell provided by Home Manager. If you don't want to manage your shell 68 - # through Home Manager then you have to manually source 'hm-session-vars.sh' 69 - # located at either 70 - # 71 - # ~/.nix-profile/etc/profile.d/hm-session-vars.sh 72 - # 73 - # or 74 - # 75 - # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh 76 - # 77 - # or 78 - # 79 - # /etc/profiles/per-user/ubuntu/etc/profile.d/hm-session-vars.sh 80 - # 81 - home.sessionVariables = { 82 - # EDITOR = "nvim"; 83 - # JANET_MODPATH = "${pkgs.janet}/lib/janet"; 84 - # JANET_SYSPATH = "${pkgs.janet}/lib/janet"; 85 - # JANET_LIBPATH = "${pkgs.janet}/lib"; 86 - # JANET_HEADERPATH = "${pkgs.janet}/include/janet"; 87 - 88 - # JANET_MODPATH = "/home/ubuntu/.local/lib/janet"; 89 - # JANET_SYSPATH = "/home/ubuntu/.local/lib/janet"; 90 - # JANET_LIBPATH = "/home/ubuntu/.local/lib"; 91 - # JANET_MANPATH = "/home/ubuntu/.local/man/man1"; 92 - # JANET_HEADERPATH = "/home/ubuntu/.local/include/janet"; 93 - }; 94 - 95 - # Let Home Manager install and manage itself. 96 - programs.home-manager.enable = true; 97 - }