Nix Flakes configuration for MacOS, NixOS and WSL
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: nix darwin (#2)

authored by

cosmeak and committed by
GitHub
0fcf3bda aadc3e11

+416 -3
+21
flake.lock
··· 1 1 { 2 2 "nodes": { 3 + "darwin": { 4 + "inputs": { 5 + "nixpkgs": [ 6 + "nixpkgs" 7 + ] 8 + }, 9 + "locked": { 10 + "lastModified": 1727999297, 11 + "narHash": "sha256-LTJuQPCsSItZ/8TieFeP30iY+uaLoD0mT0tAj1gLeyQ=", 12 + "owner": "LnL7", 13 + "repo": "nix-darwin", 14 + "rev": "8c8388ade72e58efdeae71b4cbb79e872c23a56b", 15 + "type": "github" 16 + }, 17 + "original": { 18 + "owner": "LnL7", 19 + "repo": "nix-darwin", 20 + "type": "github" 21 + } 22 + }, 3 23 "nixpkgs": { 4 24 "locked": { 5 25 "lastModified": 1728018373, ··· 18 38 }, 19 39 "root": { 20 40 "inputs": { 41 + "darwin": "darwin", 21 42 "nixpkgs": "nixpkgs" 22 43 } 23 44 }
+15 -3
flake.nix
··· 4 4 inputs = { 5 5 # nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; 6 6 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 7 + 8 + darwin = { 9 + url = "github:LnL7/nix-darwin"; 10 + inputs.nixpkgs.follows= "nixpkgs"; 11 + }; 7 12 }; 8 13 9 - outputs = inputs@{ self, nixpkgs, ... }: 14 + outputs = inputs@{ self, nixpkgs, darwin, ... }: 10 15 let 11 16 inherit (self) outputs; 12 17 # Currently supported systems ··· 17 22 18 23 # Function to generate an attribute for all systems 19 24 forAllSystems = nixpkgs.lib.genAttrs systems; 20 - in 25 + in 21 26 { 22 27 # Enable formatter 23 28 formatter = forAllSystems (system: nixpkgs.legagyPackages.${system}.alejandra); ··· 28 33 modules = [ ./hosts/loki/configuration.nix ]; 29 34 }; 30 35 }; 36 + 37 + darwinConfigurations = { 38 + njord = darwin.lib.darwinSystem { 39 + specialArgs = { inherit inputs outputs; }; 40 + modules = [ ./hosts/njord/configuration.nix ]; 41 + }; 42 + }; 31 43 }; 32 - } 44 + }
+172
hosts/njord/configuration.nix
··· 1 + { self, inputs, outputs, pkgs, ... }: 2 + { 3 + # imports = [ 4 + # ./../../modules/darwin/gc.nix 5 + # ]; 6 + 7 + # Nixpkgs config 8 + nixpkgs.config = { 9 + allowUnfree = true; 10 + allowUnsecure = false; 11 + allowBroken = true; 12 + allowUnsupportedSystem = true; 13 + }; 14 + # The platform the configuration will be used on. 15 + nixpkgs.hostPlatform = "aarch64-darwin"; 16 + 17 + # Use nix as a daemon 18 + services.nix-daemon.enable = true; 19 + 20 + # Enable sudo via TouchID 21 + security.pam.enableSudoTouchIdAuth = true; 22 + 23 + # Config Macos with preference 24 + # Disable startup sound 25 + system.nvram.variables = { 26 + "StartupMute" = "%01"; 27 + }; 28 + system.defaults = { 29 + # Dock 30 + dock = { 31 + autohide = true; 32 + orientation = "bottom"; # Set dock to bottom 33 + mru-spaces = false; # Auto arrange space based on the most recent use 34 + launchanim = false; # Remove animation when opening an app 35 + mineffect = "scale"; # Change animation from minimize/maximize app 36 + magnification = false; 37 + minimize-to-application = true; # Minimize app in app icon 38 + show-recents = false; # Don't show recent open apps 39 + tilesize = 32; # Set dock size 40 + # Set dock apps 41 + persistent-apps = [ 42 + "/Applications/Thunderbird.app" 43 + "/Applications/Brave Browser.app" 44 + "/Applications/Discord.app" 45 + "/Applications/Spotify.app" 46 + "/Applications/Obsidian.app" 47 + "/Applications/Nix Apps/kitty.app" 48 + "/Applications/Zed.app" 49 + "/Applications/Beekeeper Studio.app" 50 + ]; 51 + }; 52 + 53 + # Finder 54 + finder = { 55 + AppleShowAllExtensions = true; # Show file extension 56 + AppleShowAllFiles = true; # Show hidden files 57 + FXPreferredViewStyle = "clmv"; # Set default view to column 58 + CreateDesktop = false; # Disable show icon on desktop 59 + FXDefaultSearchScope = "SCcf"; # Set default search scope to current folder 60 + }; 61 + 62 + # Screenshot 63 + screencapture.location = "~/Pictures/screenshots"; 64 + 65 + NSGlobalDomain = { 66 + # Switch between dark and light mode automatically 67 + AppleInterfaceStyleSwitchesAutomatically = true; 68 + # Disable saving new documents to icloud 69 + NSDocumentSaveNewDocumentsToCloud = false; 70 + }; 71 + }; 72 + 73 + # List packages installed in system profile. To search by name, run: 74 + # $ nix-env -qaP | grep wget 75 + environment.systemPackages = with pkgs; [ 76 + # Dev environment most used 77 + php83 78 + php83Packages.composer 79 + nodejs_20 80 + 81 + # CLI 82 + neovim 83 + starship 84 + zoxide 85 + tree 86 + btop 87 + lazygit 88 + ngrok 89 + fastfetch 90 + 91 + # Utilities 92 + kitty 93 + alt-tab-macos 94 + raycast 95 + ]; 96 + 97 + # Homebrew - Using only for gui app because macos app do not existe un nixpkgs repository 98 + homebrew.enable = true; 99 + homebrew.onActivation = { 100 + autoUpdate = true; 101 + cleanup = "zap"; # uninstall all elements not listed below 102 + }; 103 + homebrew.taps = [ 104 + "homebrew/cask-versions" 105 + "homebrew/cask-fonts" 106 + "FelixKratz/formulae" 107 + ]; 108 + 109 + homebrew.brews = [ 110 + "cocoapods" 111 + "yarn" 112 + ]; 113 + 114 + homebrew.casks = [ 115 + # Dev 116 + "zed" 117 + "beekeeper-studio" 118 + "insomnia" 119 + "orbstack" 120 + "figma" 121 + "dbngin" 122 + "github" 123 + "mongodb-compass" 124 + "cyberduck" 125 + 126 + # Apps 127 + "spotify" 128 + "discord" 129 + "thunderbird" 130 + "obs" 131 + "obsidian" 132 + "modrinth" 133 + "zen-browser" 134 + "brave-browser" 135 + "balenaetcher" 136 + 137 + # Utilities 138 + "amethyst" 139 + # "sketchybar" 140 + "stats" 141 + "logi-options-plus" 142 + 143 + # Fonts 144 + "sf-symbols" 145 + "font-hack-nerd-font" 146 + ]; 147 + 148 + # Apps from App Store 149 + homebrew.masApps = { 150 + # Xcode = 497799835; 151 + Slack = 803453959; 152 + }; 153 + 154 + programs.zsh = { 155 + enable = true; 156 + enableBashCompletion = true; 157 + enableCompletion = true; 158 + enableSyntaxHighlighting = true; 159 + loginShellInit = '' 160 + eval "$(zoxide init zsh)" 161 + eval "$(/opt/homebrew/bin/brew shellenv)" 162 + alias rebuild="darwin-rebuild switch --flake ~/.dotfiles" 163 + ''; 164 + }; 165 + 166 + # Set Git commit hash for darwin-version. 167 + system.configurationRevision = outputs.rev or outputs.dirtyRev or null; 168 + 169 + # Used for backwards compatibility, please read the changelog before changing. 170 + # $ darwin-rebuild changelog 171 + system.stateVersion = 5; 172 + }
+208
hosts/njord/old-flake.nix
··· 1 + { 2 + description = "Nix config for MacOS"; 3 + 4 + inputs = { 5 + # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 6 + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin"; 7 + 8 + darwin = { 9 + url = "github:LnL7/nix-darwin"; 10 + inputs.nixpkgs.follows= "nixpkgs"; 11 + }; 12 + }; 13 + 14 + outputs = inputs @ { self, nixpkgs, darwin, home-manager, ... }: 15 + let 16 + system = "aarch64-darwin"; 17 + hostname = "njord"; 18 + 19 + specialArgs = inputs // { inherit hostname; }; 20 + 21 + configuration = { pkgs, ... }: { nixpkgs.config = { 22 + allowUnfree = true; 23 + allowInsecure = false; 24 + allowBroken = true; 25 + allowUnsupportedSystem = true; 26 + }; 27 + # List packages installed in system profile. To search by name, run: 28 + # $ nix-env -qaP | grep wget 29 + environment.systemPackages = 30 + [ 31 + # Dev 32 + pkgs.neovim 33 + pkgs.kitty 34 + pkgs.vscode 35 + 36 + pkgs.php 37 + pkgs.phpPackages.composer 38 + pkgs.nodejs 39 + 40 + # CLI 41 + pkgs.starship 42 + pkgs.zoxide 43 + pkgs.tree 44 + pkgs.btop 45 + pkgs.lazygit 46 + pkgs.ngrok 47 + pkgs.fastfetch 48 + 49 + # Apps 50 + pkgs.spicetify-cli 51 + 52 + # Utilities 53 + pkgs.alt-tab-macos 54 + pkgs.raycast 55 + ]; # Auto upgrade nix package and the daemon service. services.nix-daemon.enable = true; # nix.package = pkgs.nix; 56 + # Create /etc/zshrc that loads the darwin environment. 57 + programs.zsh = { 58 + enable = true; 59 + enableBashCompletion = true; 60 + enableCompletion = true; 61 + enableSyntaxHighlighting = true; 62 + loginShellInit = '' 63 + eval "$(zoxide init zsh)" 64 + eval "$(/opt/homebrew/bin/brew shellenv)" 65 + alias switch="darwin-rebuild switch --flake ~/.config/nix-darwin" 66 + ''; 67 + }; 68 + 69 + # Set Git commit hash for darwin-version. 70 + system.configurationRevision = self.rev or self.dirtyRev or null; 71 + 72 + # Used for backwards compatibility, please read the changelog before changing. 73 + # $ darwin-rebuild changelog 74 + system.stateVersion = 4; 75 + 76 + # The platform the configuration will be used on. 77 + nixpkgs.hostPlatform = "aarch64-darwin"; 78 + 79 + # Enable sudo via TouchID 80 + security.pam.enableSudoTouchIdAuth = true; 81 + 82 + # Config Macos with preference 83 + # Disable startup sound 84 + system.nvram.variables = { 85 + "StartupMute" = "%01"; 86 + }; 87 + system.defaults = { 88 + # Dock 89 + dock = { 90 + autohide = true; 91 + orientation = "bottom"; # Set dock to bottom 92 + mru-spaces = false; # Auto arrange space based on the most recent use 93 + launchanim = false; # Remove animation when opening an app 94 + mineffect = "scale"; # Change animation from minimize/maximize app 95 + magnification = false; 96 + minimize-to-application = true; # Minimize app in app icon 97 + show-recents = false; # Don't show recent open apps 98 + tilesize = 32; # Set dock size 99 + # Set dock apps 100 + persistent-apps = [ 101 + "/Applications/Thunderbird.app" 102 + "/Applications/Brave Browser.app" 103 + "/Applications/Discord.app" 104 + "/Applications/Spotify.app" 105 + "/Applications/Obsidian.app" 106 + "/Applications/Nix Apps/kitty.app" 107 + "/Applications/Zed.app" 108 + "/Applications/Beekeeper Studio.app" 109 + ]; 110 + }; 111 + 112 + # Finder 113 + finder = { 114 + AppleShowAllExtensions = true; # Show file extension 115 + AppleShowAllFiles = true; # Show hidden files 116 + FXPreferredViewStyle = "clmv"; # Set default view to column 117 + CreateDesktop = false; # Disable show icon on desktop 118 + FXDefaultSearchScope = "SCcf"; # Set default search scope to current folder 119 + }; 120 + 121 + # Screenshot 122 + screencapture.location = "~/Pictures/screenshots"; 123 + 124 + NSGlobalDomain = { 125 + # Switch between dark and light mode automatically 126 + AppleInterfaceStyleSwitchesAutomatically = true; 127 + # Disable saving new documents to icloud 128 + NSDocumentSaveNewDocumentsToCloud = false; 129 + }; 130 + 131 + }; 132 + 133 + # Homebrew - Using only for gui app because macos app do not existe un nixpkgs repository 134 + homebrew.enable = true; 135 + homebrew.onActivation = { 136 + autoUpdate = true; 137 + cleanup = "zap"; # uninstall all elements not listed below 138 + }; 139 + homebrew.taps = [ 140 + "homebrew/cask-versions" 141 + "homebrew/cask-fonts" 142 + "FelixKratz/formulae" 143 + ]; 144 + 145 + homebrew.brews = [ 146 + "cocoapods" 147 + "yarn" 148 + ]; 149 + 150 + homebrew.casks = [ 151 + # Dev 152 + "zed" 153 + "beekeeper-studio" 154 + "insomnia" 155 + "orbstack" 156 + "figma" 157 + "dbngin" 158 + "github" 159 + "mongodb-compass" 160 + "cyberduck" 161 + 162 + # Apps 163 + "spotify" 164 + "discord" 165 + "thunderbird" 166 + "obs" 167 + "obsidian" 168 + "modrinth" 169 + "zen-browser" 170 + "brave-browser" 171 + "balenaetcher" 172 + 173 + # Utilities 174 + "amethyst" 175 + # "sketchybar" 176 + "stats" 177 + "logi-options-plus" 178 + 179 + # Fonts 180 + "sf-symbols" 181 + "font-hack-nerd-font" 182 + ]; 183 + 184 + # Apps from App Store@ 185 + homebrew.masApps = { 186 + # Xcode = 497799835; 187 + Slack = 803453959; 188 + }; 189 + }; 190 + in 191 + { 192 + darwinConfigurations."${hostname}" = darwin.lib.darwinSystem { 193 + inherit system specialArgs; 194 + modules = [ configuration ]; 195 + }; 196 + 197 + # Nix code formatter 198 + formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra; 199 + 200 + # Expose the package set, including overlays, for convenience. 201 + darwinPackages = self.darwinConfigurations."${hostname}".pkgs; 202 + }; 203 + } 204 + 205 + # Rebuild system with 206 + # darwin-rebuild switch --flake . 207 + # Relaunch dock 208 + # killall Dock