├── .gitignore ├── README.md ├── flake.nix └── module.nix /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .vscode/ 4 | .idea/ 5 | 6 | result* 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nix-darwin-custom-icons 2 | 3 | Set custom icons for your applications! A module for [nix-darwin](https://daiderd.com/nix-darwin/) 4 | 5 | ## Usage 6 | 7 | Add this repository to your flake's inputs: 8 | 9 | ```nix 10 | { 11 | inputs = { 12 | darwin-custom-icons.url = "github:ryanccn/nix-darwin-custom-icons"; 13 | }; 14 | } 15 | ``` 16 | 17 | Add the module provided by the flake: 18 | 19 | ```nix 20 | { 21 | darwinConfigurations.some-mac-device = nix-darwin.lib.darwinSystem { 22 | modules = [ 23 | darwin-custom-icons.darwinModules.default 24 | ]; 25 | }; 26 | } 27 | ``` 28 | 29 | And then in your system configuration: 30 | 31 | ```nix 32 | { 33 | environment.customIcons = { 34 | enable = true; 35 | icons = [ 36 | { 37 | path = "/Applications/Notion.app"; 38 | icon = ./icons/notion.icns; 39 | } 40 | ]; 41 | }; 42 | } 43 | ``` 44 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | outputs = _: { 3 | darwinModules = { 4 | default = import ./module.nix; 5 | }; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /module.nix: -------------------------------------------------------------------------------- 1 | { lib, config, ... }: 2 | let 3 | cfg = config.environment.customIcons; 4 | inherit (lib) 5 | mkEnableOption 6 | mkIf 7 | mkMerge 8 | mkOption 9 | types 10 | ; 11 | in 12 | { 13 | options.environment.customIcons = { 14 | enable = mkEnableOption "environment.customIcons"; 15 | clearCacheOnActivation = mkEnableOption "environment.customIcons.clearCacheOnActivation"; 16 | 17 | icons = mkOption { 18 | type = types.listOf ( 19 | types.submodule { 20 | options = { 21 | path = mkOption { type = types.path; }; 22 | icon = mkOption { type = types.path; }; 23 | }; 24 | } 25 | ); 26 | }; 27 | }; 28 | 29 | config = mkMerge [ 30 | (mkIf cfg.enable { 31 | system.activationScripts.extraActivation.text = '' 32 | echo -e "applying custom icons..." 33 | 34 | ${ 35 | (builtins.concatStringsSep "\n\n" ( 36 | builtins.map (iconCfg: '' 37 | osascript </dev/null 38 | use framework "Cocoa" 39 | 40 | set iconPath to "${iconCfg.icon}" 41 | set destPath to "${iconCfg.path}" 42 | 43 | set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:iconPath) 44 | (current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2) 45 | EOF 46 | '') cfg.icons 47 | )) 48 | } 49 | 50 | ${lib.optionalString cfg.clearCacheOnActivation '' 51 | sudo rm -rf /Library/Caches/com.apple.iconservices.store 52 | sudo find /private/var/folders/ -name com.apple.dock.iconcache -or -name com.apple.iconservices -or -name com.apple.iconservicesagent -exec rm -rf {} \; || true 53 | killall Dock 54 | ''}''; 55 | }) 56 | ]; 57 | } 58 | --------------------------------------------------------------------------------