From 6c503c465b7b5f0a51b7cd11ec0300d856a76310 Mon Sep 17 00:00:00 2001 From: Poby Date: Fri, 4 Apr 2025 05:25:20 +0900 Subject: [PATCH] Initial commit --- .DS_Store | Bin 0 -> 6148 bytes flake.lock | 63 ++++++++++++ flake.nix | 56 +++++++++++ modules/.DS_Store | Bin 0 -> 6148 bytes modules/apps.nix | 109 ++++++++++++++++++++ modules/host-users.nix | 23 +++++ modules/nix-core.nix | 20 ++++ modules/system.nix | 221 +++++++++++++++++++++++++++++++++++++++++ result | 1 + 9 files changed, 493 insertions(+) create mode 100644 .DS_Store create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 modules/.DS_Store create mode 100644 modules/apps.nix create mode 100644 modules/host-users.nix create mode 100644 modules/nix-core.nix create mode 100644 modules/system.nix create mode 120000 result diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..29d63c76efe089fad48c536e80e79c78124ec02e GIT binary patch literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8zEL;p&0Z1N%F(jFwBAg)ez-FW}=rQCmWHMBE=0N2} zsnHM^4S~TM0-(Ih$&kj7!;r|3&484D^OKWu@{^!N!+Hh=2EG4a0QL$yLoP!;LkdGF zLk>eKLvd1haRF5Ij--N|%;FLQgKLaT%q*;I?ChNE-0ZQz8TsYGC5a`a#ZHMu(I8$( zetu38jGdSimYG@}FCgNapI4HYnU`7wQWBh*lA4rQ6ce7Amy%!ZlwX>cQViA$mEh#$ z;EWfLsIE3Kw9rv7H#ex&QK+^wGSE>lu{5f!<>U}m*0&Cd&(6us%kKian}LxLLNo9} zX&BYbz`%g!tCZs8oTU7Ga7l(Hm6L85oSdIq0Mm`BIXBM!k>%}C z-;RdBXb2Dy0-*9i0a~RvKw=SYXC6g8KmsAUTj$5Dn4_qCr|2 z7(pzs8DOmpj8LtN;BE*=AE-+LqQTl37#YCY85kMB+Tj&ABSbp`Bh+R_Xb*)EqMd;e zqMd;eq8;YEQF=54MneD^0?ZIv0960GGBDuk|3g%blA|Fo8Un*I1Q=Odf?b@zl`?k! zf$CaNeVPE32G#zc>X;E!Peb&9lz?TKAOngLU=BnMq!m={gR5dj21rdl+7N(+&?r3` I0`w070QpRe&Hw-a literal 0 HcmV?d00001 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3a3c9db --- /dev/null +++ b/flake.lock @@ -0,0 +1,63 @@ +{ + "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs-darwin" + ] + }, + "locked": { + "lastModified": 1743496612, + "narHash": "sha256-emPWa5lmKbnyuj8c1mSJUkzJNT+iJoU9GMcXwjp2oVM=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "73d59580d01e9b9f957ba749f336a272869c42dd", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743568003, + "narHash": "sha256-ZID5T65E8ruHqWRcdvZLsczWDOAWIE7om+vQOREwiX0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b7ba7f9f45c5cd0d8625e9e217c28f8eb6a19a76", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-darwin": { + "locked": { + "lastModified": 1743568003, + "narHash": "sha256-ZID5T65E8ruHqWRcdvZLsczWDOAWIE7om+vQOREwiX0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b7ba7f9f45c5cd0d8625e9e217c28f8eb6a19a76", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "darwin": "darwin", + "nixpkgs": "nixpkgs", + "nixpkgs-darwin": "nixpkgs-darwin" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8746f11 --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + description = "Nix for macOS configuration"; + + ################################################################################################################## + # + # Want to know Nix in details? Looking for a beginner-friendly tutorial? + # Check out https://github.com/ryan4yin/nixos-and-flakes-book ! + # + ################################################################################################################## + + # This is the standard format for flake.nix. `inputs` are the dependencies of the flake, + # Each item in `inputs` will be passed as a parameter to the `outputs` function after being pulled and built. + inputs = { + nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + # nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-24.05-darwin"; + darwin = { + url = "github:lnl7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs-darwin"; + }; + }; + + # The `outputs` function will return all the build results of the flake. + # A flake can have many use cases and different types of outputs, + # parameters in `outputs` are defined in `inputs` and can be referenced by their names. + # However, `self` is an exception, this special parameter points to the `outputs` itself (self-reference) + # The `@` syntax here is used to alias the attribute set of the inputs's parameter, making it convenient to use inside the function. + outputs = inputs @ { + self, + nixpkgs, + darwin, + ... + }: let + # TODO replace with your own username, system and hostname + username = "poby"; + system = "aarch64-darwin"; + hostname = "pobys-macbook-pro"; + + specialArgs = + inputs + // { + inherit username hostname; + }; + in { + darwinConfigurations."${hostname}" = darwin.lib.darwinSystem { + inherit system specialArgs; + modules = [ + ./modules/nix-core.nix + ./modules/system.nix + ./modules/apps.nix + ./modules/host-users.nix + ]; + }; + # nix code formatter + formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra; + }; +} \ No newline at end of file diff --git a/modules/.DS_Store b/modules/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8z45|!R0Z1N%F(jFgL>QrFAPJ2!M?+vV1V%$(Gz3ON zU^D~25V%SxcdJP zRior+2#kinunYl47MEZbCs3t{!+W4QHvuXKVuPw;Mo^s$(F3lEVT}ML$bg~*R5_@+ b2Uo?6kTwK}57Iu`5P${HC_Nei0}uiLNUI8I literal 0 HcmV?d00001 diff --git a/modules/apps.nix b/modules/apps.nix new file mode 100644 index 0000000..681cd62 --- /dev/null +++ b/modules/apps.nix @@ -0,0 +1,109 @@ +{ pkgs, ... }: { + + ########################################################################## + # + # Install all apps and packages here. + # + # TODO Fell free to modify this file to fit your needs. + # + ########################################################################## + + # Install packages from nix's official package repository. + # + # The packages installed here are available to all users, and are reproducible across machines, and are rollbackable. + # But on macOS, it's less stable than homebrew. + # + # Related Discussion: https://discourse.nixos.org/t/darwin-again/29331 + environment.systemPackages = with pkgs; [ + # CLI + neovim + git + just # use Justfile to simplify nix-darwin's commands + nodejs-slim + ffmpeg + fzf + bat + fastfetch + gh + lsd + jdk + jdk17 + jdk11 + mkalias + python310 + tldr + tmux + tree + zoxide + + # GUI + alt-tab-macos + bitwarden-desktop + bruno + discord + pretendard + google-chrome + iina + jetbrains.idea-ultimate + ice-bar + keka + postman + raycast + rectangle + slack + stats + telegram-desktop + vscode + zoom-us + ]; + environment.variables.EDITOR = "nvim"; + + # TODO To make this work, homebrew need to be installed manually, see https://brew.sh + # + # The apps installed by homebrew are not managed by nix, and not reproducible! + # But on macOS, homebrew has a much larger selection of apps than nixpkgs, especially for GUI apps! + homebrew = { + enable = true; + + onActivation = { + autoUpdate = true; # Fetch the newest stable branch of Homebrew's git repo + upgrade = true; # Upgrade outdated casks, formulae, and App Store apps + # 'zap': uninstalls all formulae(and related files) not listed in the generated Brewfile + cleanup = "zap"; + }; + + # Applications to install from Mac App Store using mas. + # You need to install all these Apps manually first so that your apple account have records for them. + # otherwise Apple Store will refuse to install them. + # For details, see https://github.com/mas-cli/mas + masApps = { + KakaoTalk = 869223134; + Across = 6444851827; + Flighty = 1358823008; + }; + + taps = [ ]; + + # `brew install` + brews = [ + "wget" + "curl" # do not install curl via nixpkgs, it's not working well on macOS! + ]; + + # `brew install --cask` + casks = [ + "claude" + "docker" + "daisydisk" + "ghostty" + "hammerspoon" + "hancom-docs" + "logi-options+" + "notion" + "onyx" + "readdle-spark" + "shottr" + "zen-browser" + ]; + }; +} diff --git a/modules/host-users.nix b/modules/host-users.nix new file mode 100644 index 0000000..079befd --- /dev/null +++ b/modules/host-users.nix @@ -0,0 +1,23 @@ +{ + username, + hostname, + ... +} @ args: +############################################################# +# +# Host & Users configuration +# +############################################################# +{ + networking.hostName = hostname; + networking.computerName = hostname; + system.defaults.smb.NetBIOSName = hostname; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users."${username}" = { + home = "/Users/${username}"; + description = username; + }; + + nix.settings.trusted-users = [username]; +} diff --git a/modules/nix-core.nix b/modules/nix-core.nix new file mode 100644 index 0000000..721ee99 --- /dev/null +++ b/modules/nix-core.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: + +{ + nix.settings = { + # enable flakes globally + experimental-features = ["nix-command" "flakes"]; + }; + + # Allow unfree packages + nixpkgs.config = { + allowUnfree = true; + allowBroken = true; + }; + + # Auto upgrade nix package and the daemon service. + nix.package = pkgs.nix; + + # Enable Determinate + nix.enable = false; +} diff --git a/modules/system.nix b/modules/system.nix new file mode 100644 index 0000000..e2e37a1 --- /dev/null +++ b/modules/system.nix @@ -0,0 +1,221 @@ +{ pkgs, config, ... }: + + ################################################################################### + # + # macOS's System configuration + # + # All the configuration options are documented here: + # https://daiderd.com/nix-darwin/manual/index.html#sec-options + # Incomplete list of macOS `defaults` commands : + # https://github.com/yannbertrand/macos-defaults + # + ################################################################################### +{ + system = { + stateVersion = 5; + # activationScripts are executed every time you boot the system or run `nixos-rebuild` / `darwin-rebuild`. + activationScripts.postUserActivation.text = '' + # activateSettings -u will reload the settings from the database and apply them to the current session, + # so we do not need to logout and login again to make the changes take effect. + /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u + ''; + + activationScripts.applications.text = let + env = pkgs.buildEnv { + name = "system-applications"; + paths = config.environment.systemPackages; + pathsToLink = "/Applications"; + }; + in + pkgs.lib.mkForce '' + # Set up applications. + echo "setting up /Applications..." >&2 + rm -rf /Applications/Nix\ Apps + mkdir -p /Applications/Nix\ Apps + find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + | + while read -r src; do + app_name=$(basename "$src") + echo "copying $src" >&2 + ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name" + done + ''; + + defaults = { + # login window + loginwindow = { + GuestEnabled = false; # disable guest user + SHOWFULLNAME = true; # show full name in login window + }; + + # control center + controlcenter = { + Sound = false; + Bluetooth = false; + AirDrop = false; + Display = false; + NowPlaying = false; + }; + + # clock + menuExtraClock = { + Show24Hour = true; + ShowAMPM = false; + ShowDayOfWeek = false; + }; + + # dock + dock = { + autohide = true; + autohide-delay = 0.01; + autohide-time-modifier = 0.1; + mineffect = "suck"; + show-recents = false; + tilesize = 50; + magnification = true; + largesize = 70; + wvous-bl-corner = 11; + }; + + # finder + finder = { + AppleShowAllFiles = true; + ShowStatusBar = true; + ShowPathbar = true; + FXPreferredViewStyle = "Nlsv"; + AppleShowAllExtensions = true; + QuitMenuItem = true; + _FXShowPosixPathInTitle = true; + _FXSortFoldersFirst = true; + FXEnableExtensionChangeWarning = false; + NewWindowTarget = "Home"; + }; + + # trackpad + trackpad = { + Clicking = true; + TrackpadRightClick = true; # enable two finger right click + TrackpadThreeFingerDrag = true; # enable three finger drag + }; + + # customize settings that not supported by nix-darwin directly + # Incomplete list of macOS `defaults` commands : + # https://github.com/yannbertrand/macos-defaults + NSGlobalDomain = { + # `defaults read NSGlobalDomain "xxx"` + "com.apple.swipescrolldirection" = true; + AppleInterfaceStyle = "Dark"; + AppleKeyboardUIMode = 3; + ApplePressAndHoldEnabled = false; + InitialKeyRepeat = 15; + KeyRepeat = 2; + + AppleShowScrollBars = "WhenScrolling"; + AppleScrollerPagingBehavior = true; + + NSAutomaticCapitalizationEnabled = false; + NSAutomaticDashSubstitutionEnabled = false; + NSAutomaticPeriodSubstitutionEnabled = false; + NSAutomaticQuoteSubstitutionEnabled = false; + NSAutomaticSpellingCorrectionEnabled = false; + NSNavPanelExpandedStateForSaveMode = true; + NSNavPanelExpandedStateForSaveMode2 = true; + NSTableViewDefaultSizeMode = 2; + + "com.apple.keyboard.fnState" = true; + }; + + # Customize settings that not supported by nix-darwin directly + # see the source code of this project to get more undocumented options: + # https://github.com/rgcr/m-cli + # + # All custom entries can be found by running `defaults read` command. + # or `defaults read xxx` to read a specific domain. + CustomUserPreferences = { + ".GlobalPreferences" = { + # automatically switch to a new space when switching to the application + AppleSpacesSwitchOnActivate = true; + }; + NSGlobalDomain = { + # Add a context menu item for showing the Web Inspector in web views + WebKitDeveloperExtras = true; + }; + "com.apple.finder" = { + ShowExternalHardDrivesOnDesktop = true; + ShowHardDrivesOnDesktop = true; + ShowMountedServersOnDesktop = true; + ShowRemovableMediaOnDesktop = true; + _FXSortFoldersFirst = true; + # When performing a search, search the current folder by default + FXDefaultSearchScope = "SCcf"; + }; + "com.apple.desktopservices" = { + # Avoid creating .DS_Store files on network or USB volumes + DSDontWriteNetworkStores = true; + DSDontWriteUSBStores = true; + }; + "com.apple.WindowManager" = { + EnableStandardClickToShowDesktop = 0; # Click wallpaper to reveal desktop + StandardHideDesktopIcons = 0; # Show items on desktop + HideDesktop = 0; # Do not hide items on desktop & stage manager + StageManagerHideWidgets = 0; + StandardHideWidgets = 0; + }; + "com.apple.screensaver" = { + # Require password immediately after sleep or screen saver begins + askForPassword = 1; + askForPasswordDelay = 0; + }; + "com.apple.AdLib" = { + allowApplePersonalizedAdvertising = false; + }; + # Prevent Photos from opening automatically when devices are plugged in + "com.apple.ImageCapture".disableHotPlug = true; + "com.apple.dock" = { + springboard-columns = 10; + springboard-rows = 10; + ResetLaunchPad = true; + }; + }; + }; + + # keyboard settings is not very useful on macOS + # the most important thing is to remap option key to alt key globally, + # but it's not supported by macOS yet. + keyboard = { + enableKeyMapping = true; # enable key mapping so that we can use `option` as `control` + + # NOTE: do NOT support remap capslock to both control and escape at the same time + remapCapsLockToControl = false; # remap caps lock to control, useful for emac users + remapCapsLockToEscape = false; # remap caps lock to escape, useful for vim users + }; + }; + + # Add ability to used TouchID for sudo authentication + security.pam.services.sudo_local.touchIdAuth = true; + + # Create /etc/zshrc that loads the nix-darwin environment. + # this is required if you want to use darwin's default shell - zsh + programs.zsh.enable = true; + environment.shells = [ + pkgs.zsh + ]; + + # Set your time zone. + time.timeZone = "Asia/Seoul"; + + # Fonts + fonts = { + packages = with pkgs; [ + # icon fonts + material-design-icons + font-awesome + + # nerdfonts + nerd-fonts.symbols-only + nerd-fonts.meslo-lg + nerd-fonts.d2coding + nerd-fonts.fira-code + nerd-fonts.jetbrains-mono + ]; + }; +} diff --git a/result b/result new file mode 120000 index 0000000..6007f38 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/wqavdqq4f3j9gwymsj724hz9jkjwa3gf-darwin-system-25.05.73d5958 \ No newline at end of file