diff --git a/README.md b/README.md index 66724c6..da9b1e1 100644 --- a/README.md +++ b/README.md @@ -2,37 +2,46 @@ My macOS configuration files. +> [!NOTE] +> Nix support is in beta. If I'm happy with Nix after a while, I'll migrate everything else to Nix, and installation instructions will become simpler. + ## Setting up a new MacOS machine 🚀 -1. Install Homebrew: +1. Install [Nix](https://nix.dev/install-nix): + + ```sh + curl -L https://nixos.org/nix/install | sh + ``` -```sh -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -``` +2. Clone the repo -1. Install requirements: + ```sh + git clone --recurse-submodules https://github.com/legomb/dotfiles.git + ``` -```sh -brew install git stow go-task -``` +3. Switch to the nix flake: -3. Clone the repo. + ```sh + cd config/nix/.config/nix-darwin + nix run nix-darwin --extra-experimental-features "nix-command flakes" -- switch --flake .#macbook + ``` + This will configure macOS settings and install basic dependencies (go-task, etc.) -4. Initialize submodules: +4. Install Homebrew: -```sh -task git:submodules:update -``` + ```sh + task brew:install + ``` 5. Stow dotfiles: -```sh -task stow:stow -``` + ```sh + task stow:stow + ``` -6. Install everything: +6. Install everything using brew: -```sh -task brew:bundle:install -``` + ```sh + task brew:bundle:install + ``` diff --git a/config/brew/Brewfile b/config/brew/Brewfile index a147f68..c70f8e3 100644 --- a/config/brew/Brewfile +++ b/config/brew/Brewfile @@ -105,6 +105,7 @@ cask "alt-tab" # cask "font-lilex-nerd-font" # cask "font-martian-mono-nerd-font" cask "font-meslo-lg-nerd-font" +cask "font-meslo-for-powerlevel10k" # cask "font-monaspace-nerd-font" # cask "font-monocraft-nerd-font" # cask "font-monofur-nerd-font" diff --git a/config/nix/.config/nix-darwin/.gitignore b/config/nix/.config/nix-darwin/.gitignore new file mode 100644 index 0000000..1cd791b --- /dev/null +++ b/config/nix/.config/nix-darwin/.gitignore @@ -0,0 +1 @@ +result/ diff --git a/config/nix/.config/nix-darwin/configuration.nix b/config/nix/.config/nix-darwin/configuration.nix new file mode 100644 index 0000000..04ea266 --- /dev/null +++ b/config/nix/.config/nix-darwin/configuration.nix @@ -0,0 +1,53 @@ +{ self, pkgs, ... }: +{ + + # The default Nix build user group ID was changed from 30000 to 350. You can set the configured group ID to match the actual value with `ids.gids.nixbld = 30000;` + # We do not recommend trying to change the group ID with macOS user management tools without a complete uninstallation and reinstallation of Nix. + ids.gids.nixbld = 30000; + + nixpkgs.config.allowUnfree = true; + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "aarch64-darwin"; + + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + environment.systemPackages = with pkgs; [ + coreutils + git + go-task + neovim + stow + nixfmt-rfc-style + ]; + + nix.settings = { + keep-outputs = true; + keep-derivations = true; + + # Necessary for using flakes on this system. + experimental-features = "nix-command flakes"; + }; + + # Set Git commit hash for darwin-version. + # system.configurationRevision = self.rev or self.dirtyRev or null; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 5; + + security.pam.services.sudo_local.touchIdAuth = true; + + system.defaults = { + dock.autohide = true; + finder.FXPreferredViewStyle = "clmv"; + finder.AppleShowAllExtensions = true; + NSGlobalDomain.AppleInterfaceStyle = "Dark"; + }; + + # Garbage collection + nix.gc = { + automatic = true; + options = "--delete-generations +5"; + }; + nix.optimise.automatic = true; +} diff --git a/config/nix/.config/nix-darwin/flake.lock b/config/nix/.config/nix-darwin/flake.lock new file mode 100644 index 0000000..3d8ca1f --- /dev/null +++ b/config/nix/.config/nix-darwin/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742869675, + "narHash": "sha256-rgwUZJZVztaNYPTsf6MIqirPL5r2JTMMyHuzk1ezyYk=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "bb81755a3674951724d79b8cba6bbff01409d44d", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1742923925, + "narHash": "sha256-biPjLws6FiBVUUDHEMFq5pUQL84Wf7PntPYdo3oKkFw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "25d1b84f5c90632a623c48d83a2faf156451e6b1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/config/nix/.config/nix-darwin/flake.nix b/config/nix/.config/nix-darwin/flake.nix new file mode 100644 index 0000000..03f86a6 --- /dev/null +++ b/config/nix/.config/nix-darwin/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Custom nix-darwin system flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nix-darwin.url = "github:LnL7/nix-darwin"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + inputs@{ + self, + nix-darwin, + nixpkgs, + }: + { + # Build darwin flake using: + # $ darwin-rebuild build --flake .#macbook + darwinConfigurations."macbook" = nix-darwin.lib.darwinSystem { + modules = [ ./configuration.nix ]; + }; + }; +} diff --git a/config/nix/.config/nix-darwin/modules/.gitkeep b/config/nix/.config/nix-darwin/modules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/taskfile.yml b/taskfile.yml index af82117..dd5f03c 100644 --- a/taskfile.yml +++ b/taskfile.yml @@ -3,6 +3,7 @@ version: '3' env: CONFIG_PATH: '{{.PWD}}/config' BREWFILE_PATH: '{{.CONFIG_PATH}}/brew/Brewfile' + NIX_DARWIN_FLAKE_PATH: '{{.CONFIG_PATH}}/nix/.config/nix-darwin' dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env'] @@ -64,6 +65,7 @@ tasks: - git - alacritty - ghostty + - nix cmd: stow {{.CLI_ARGS}} --dir={{.CONFIG_PATH}} --target=$HOME {{ .ITEM }} stow:simulate: @@ -83,3 +85,45 @@ tasks: cmds: - git submodule update --init --recursive - task: zsh:create-powerlevel10k-symlink + + nix:install: + desc: Installs Nix + cmds: + - curl -L https://nixos.org/nix/install | sh + + nix:flake:init:nix-darwin: + desc: Initializes nix-darwin flake, as per https://youtu.be/Z8BL8mdzWHI?si=azkz7EwYHTEUBCz3 + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - nix flake init -t nix-darwin --extra-experimental-features "nix-command flakes" + - sed -i '' "s/simple/$(scutil --get LocalHostName)/" flake.nix + + nix:flake:switch:nix-darwin: + desc: Switches to the MacOS flake + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - nix run nix-darwin --extra-experimental-features "nix-command flakes" -- switch --flake .#macbook + + nix:flake:rebuild:nix-darwin: + desc: Rebuilds the MacOS flake + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - darwin-rebuild switch --flake .#macbook + + nix:flake:rebuild:nix-darwin:dry-run: + desc: Rebuilds the MacOS flake + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - darwin-rebuild switch --flake .#macbook --dry-run + + nix:flake:update:nix-darwin: + desc: Updates the MacOS flake lock file + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - nix flake update + + nix:flake:format: + desc: Formats MacOS flake file + dir: '{{.NIX_DARWIN_FLAKE_PATH}}' + cmds: + - nixfmt flake.nix