From b2afed60e0abdb8834527e261e2a17957b152ba1 Mon Sep 17 00:00:00 2001 From: wyatt Date: Tue, 30 Jul 2024 00:09:42 -0400 Subject: [PATCH] initial commit --- .gitignore | 2 + README.md | 3 + flake.lock | 85 ++++++++++++++++++++ flake.nix | 61 ++++++++++++++ home/atuin.nix | 9 +++ home/core.nix | 47 +++++++++++ home/default.nix | 35 +++++++++ home/direnv.nix | 14 ++++ home/eza.nix | 10 +++ home/git.nix | 49 ++++++++++++ home/lazygit.nix | 22 ++++++ home/neovim.nix | 9 +++ home/shell.nix | 66 ++++++++++++++++ home/starship.nix | 9 +++ modules/apps.nix | 40 ++++++++++ modules/host-users.nix | 23 ++++++ modules/nix-core.nix | 31 ++++++++ modules/system.nix | 175 +++++++++++++++++++++++++++++++++++++++++ 18 files changed, 690 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 home/atuin.nix create mode 100644 home/core.nix create mode 100644 home/default.nix create mode 100644 home/direnv.nix create mode 100644 home/eza.nix create mode 100644 home/git.nix create mode 100644 home/lazygit.nix create mode 100644 home/neovim.nix create mode 100644 home/shell.nix create mode 100644 home/starship.nix 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e20408f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +result/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c15328d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Wyatt's Nix configuration + +Designed and developed by Wyatt J. Miller, 2024 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..326c10f --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs-darwin" + ] + }, + "locked": { + "lastModified": 1722082646, + "narHash": "sha256-od8dBWVP/ngg0cuoyEl/w9D+TCNDj6Kh4tr151Aax7w=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "0413754b3cdb879ba14f6e96915e5fdf06c6aab6", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs-darwin" + ] + }, + "locked": { + "lastModified": 1720042825, + "narHash": "sha256-A0vrUB6x82/jvf17qPCpxaM+ulJnD8YZwH9Ci0BsAzE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "e1391fb22e18a36f57e6999c7a9f966dc80ac073", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-24.05", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722141560, + "narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-darwin": { + "locked": { + "lastModified": 1722153173, + "narHash": "sha256-S46RmS9WkBOTLORpnWsNth4Ae6TlfJS9TKXqB55YQy4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7bba2df68503b68634e0070483ddaf6d59dc6530", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-24.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "darwin": "darwin", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "nixpkgs-darwin": "nixpkgs-darwin" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d716560 --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + description = "Wyatt's nix configuration"; + + inputs = { + nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-24.05-darwin"; + home-manager = { + url = "github:nix-community/home-manager/release-24.05"; + inputs.nixpkgs.follows = "nixpkgs-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, + home-manager, + ... + }: let + username = "wyatt"; + useremail = "wyatt@wyattjmiller.com"; + system = "aarch64-darwin"; # aarch64-darwin or x86_64-darwin + hostname = "sephiroth"; + + specialArgs = + inputs + // { + inherit username useremail 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 + + # home manager + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = specialArgs; + home-manager.users.${username} = import ./home; + } + ]; + }; + + # nix code formatter + formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra; + }; +} diff --git a/home/atuin.nix b/home/atuin.nix new file mode 100644 index 0000000..16b6302 --- /dev/null +++ b/home/atuin.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + programs.atuin = { + enable = true; + + enableFishIntegration = true; + }; +} \ No newline at end of file diff --git a/home/core.nix b/home/core.nix new file mode 100644 index 0000000..a37efb2 --- /dev/null +++ b/home/core.nix @@ -0,0 +1,47 @@ +{ pkgs, ... }: + +{ + home.packages = with pkgs; [ + nnn # terminal file manager + + # archives + zip + xz + unzip + p7zip + + # utils + ripgrep # recursively searches directories for a regex pattern + jq # A lightweight and flexible command-line JSON processor + yq-go # yaml processer https://github.com/mikefarah/yq + fzf # A command-line fuzzy finder + fh # flake hub command line interface + aria2 # A lightweight multi-protocol & multi-source command-line download utility + + # misc + cowsay + file + which + tree + gnutar + gnupg + tmux + nerdfonts + zoxide + babelfish + + # language-specific package managers + nodejs + cargo + python3 + + # productivity + iterm2 + discord + obsidian + vscode + + # games? + # prismlauncher + ]; +} diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..56bfdc8 --- /dev/null +++ b/home/default.nix @@ -0,0 +1,35 @@ +{ username, ... }: + +{ + # import sub modules + imports = [ + ./atuin.nix + ./shell.nix + ./core.nix + ./git.nix + ./starship.nix + ./eza.nix + ./neovim.nix + ./direnv.nix + ]; + + # Home Manager needs a bit of information about you and the + # paths it should manage. + home = { + username = username; + homeDirectory = "/Users/${username}"; + + # This value determines the Home Manager release that your + # configuration is compatible with. This helps avoid breakage + # when a new Home Manager release introduces backwards + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + stateVersion = "24.05"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/home/direnv.nix b/home/direnv.nix new file mode 100644 index 0000000..47cc53f --- /dev/null +++ b/home/direnv.nix @@ -0,0 +1,14 @@ +{ lib, config, ... }: + +{ + programs.direnv = { + enable = true; + nix-direnv.enable = true; + + config = { + global = { + hide_env_diff = true; + }; + }; + }; +} \ No newline at end of file diff --git a/home/eza.nix b/home/eza.nix new file mode 100644 index 0000000..5c05761 --- /dev/null +++ b/home/eza.nix @@ -0,0 +1,10 @@ +{ lib, config, ... }: + +{ + programs.eza = { + enable = true; + enableFishIntegration = true; + extraOptions = [ + ]; + }; +} \ No newline at end of file diff --git a/home/git.nix b/home/git.nix new file mode 100644 index 0000000..dc7ae73 --- /dev/null +++ b/home/git.nix @@ -0,0 +1,49 @@ +{ + lib, + username, + useremail, + ... +}: { + # `programs.git` will generate the config file: ~/.config/git/config + # to make git use this config file, `~/.gitconfig` should not exist! + # + # https://git-scm.com/docs/git-config#Documentation/git-config.txt---global + home.activation.removeExistingGitconfig = lib.hm.dag.entryBefore ["checkLinkTargets"] '' + rm -f ~/.gitconfig + ''; + + programs.git = { + enable = true; + userName = username; + userEmail = useremail; + + extraConfig = { + init.defaultBranch = "master"; + push.autoSetupRemote = true; + pull.rebase = true; + }; + + ignores = [ + ".DS_Store" + ".direnv" + ".idea" + ]; + + aliases = { + # common aliases + br = "branch"; + co = "checkout"; + st = "status"; + ls = "log --pretty=format:\"%C(yellow)%h%Cred%d\\\\ %Creset%s%Cblue\\\\ [%cn]\" --decorate"; + ll = "log --pretty=format:\"%C(yellow)%h%Cred%d\\\\ %Creset%s%Cblue\\\\ [%cn]\" --decorate --numstat"; + cm = "commit -m"; + ca = "commit -am"; + dc = "diff --cached"; + amend = "commit --amend -m"; + + # aliases for submodule + update = "submodule update --init --recursive"; + foreach = "submodule foreach"; + }; + }; +} diff --git a/home/lazygit.nix b/home/lazygit.nix new file mode 100644 index 0000000..4f24f47 --- /dev/null +++ b/home/lazygit.nix @@ -0,0 +1,22 @@ +{ ... }: + +{ + programs.lazygit = { + enable = true; + + settings = { + gui.theme = { + activeBorderColor = ["#a6e3a1" "bold"]; + inactiveBorderColor = ["#a6adc8"]; + optionsTextColor = ["#89b4fa"]; + selectedLineBgColor = ["#313244"]; + selectedRangeBgColor = ["#313244"]; + cherryPickedCommitBgColor = ["#45475a"]; + cherryPickedCommitFgColor = ["#a6e3a1"]; + unstagedChangesColor = ["#f38ba8"]; + defaultFgColor = ["#cdd6f4"]; + searchingActiveBorderColor = ["#f9e2af"]; + }; + }; + }; +} diff --git a/home/neovim.nix b/home/neovim.nix new file mode 100644 index 0000000..bcf357e --- /dev/null +++ b/home/neovim.nix @@ -0,0 +1,9 @@ +{ lib, config, ... }: + +{ + programs.neovim = { + enable = true; + defaultEditor = true; + vimAlias = true; + }; +} \ No newline at end of file diff --git a/home/shell.nix b/home/shell.nix new file mode 100644 index 0000000..8153248 --- /dev/null +++ b/home/shell.nix @@ -0,0 +1,66 @@ +{ pkgs, ... }: { + programs.fish = { + enable = true; + # initExtra = '' + # export PATH="$PATH:$HOME/bin:$HOME/.local/bin:$HOME/go/bin" + # ''; + + shellAliases = { + # ls aliases + # ls = "eza --color $argv"; + la = "eza -l -all --color $argv"; + ll = "eza -l --color $argv"; + lt = "eza -l --color --git $argv"; + + # lazygit alias + lg = "lazygit"; + + # cat, less, more alias + cat = "bat $argv"; + less = "bat $argv"; + more = "bat $argv"; + }; + + functions = { + fish_greeting = { + body = '' + set memes \ + "Crazy? I was crazy once. They locked me in a room. A rubber room. A rubber room with rats. And rats make me crazy." \ + "Daddy, chill!" \ + "What the hell is even that?!" \ + "Road work ahead? Yeah, I sure hope it does!" \ + "Look at all those chickens!" \ + "I smell like beef" \ + "Say, Coloardo - I'M A GIRAFFE" \ + "I didn't get no sleep cause of y'all, y'all not gone get any sleep cause of me!" \ + "This is the dollar store, how good can it be?" \ + "That was legitness" \ + "Deez nuts" \ + "I wanna be a cowboy baby" \ + "Can I get a waffle? Can I please get a waffle?" \ + "I'm lesbian. I thought you were American." + + set choose_meme (random)"%"(count $memes) + set choose_meme $memes[(math $choose_meme"+1")] + + printf (set_color F90)"%s\n" $choose_meme + ''; + onEvent = "fish_greeting"; + }; + }; + }; + + programs.zsh = { + enable = true; + initExtra = '' + if [[ -z "$BASH_EXECUTION_STRING" ]]; then + if [[ -n "$ZSH_VERSION" ]]; then + LOGIN_OPTION="--login" + else + LOGIN_OPTION="" + fi + exec ${pkgs.fish}/bin/fish $LOGIN_OPTION + fi + ''; + }; +} diff --git a/home/starship.nix b/home/starship.nix new file mode 100644 index 0000000..ef02d21 --- /dev/null +++ b/home/starship.nix @@ -0,0 +1,9 @@ +{ lib, config, ... }: + +{ + programs.starship = { + enable = true; + enableFishIntegration = true; + settings = { }; + }; +} diff --git a/modules/apps.nix b/modules/apps.nix new file mode 100644 index 0000000..4ccbd86 --- /dev/null +++ b/modules/apps.nix @@ -0,0 +1,40 @@ +{ pkgs, ... }: { + + environment.systemPackages = with pkgs; [ + neovim + git + ]; + + environment.variables.EDITOR = "nvim"; + + homebrew = { + enable = true; + + onActivation = { + autoUpdate = false; + # 'zap': uninstalls all formulae(and related files) not listed here. + 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 = { + Xcode = 497799835; + "Reeder 5." = 1529448980; + Wireguard = 1451685025; + Bitwarden = 1352778147; + "AdGuard for Safari" = 1440147259; + }; + + taps = [ + ]; + + brews = [ + ]; + + casks = [ + ]; + }; +} 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..c908c6e --- /dev/null +++ b/modules/nix-core.nix @@ -0,0 +1,31 @@ + +{ pkgs, lib, ... }: + +{ + # enable flakes globally + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + # Use this instead of services.nix-daemon.enable if you + # don't wan't the daemon service to be managed for you. + # nix.useDaemon = true; + + nix.package = pkgs.nix; + + # do garbage collection weekly to keep disk usage low + nix.gc = { + automatic = lib.mkDefault true; + options = lib.mkDefault "--delete-older-than 7d"; + }; + + # Disable auto-optimise-store because of this issue: + # https://github.com/NixOS/nix/issues/7273 + # "error: cannot link '/nix/store/.tmp-link-xxxxx-xxxxx' to '/nix/store/.links/xxxx': File exists" + nix.settings = { + auto-optimise-store = false; + }; +} diff --git a/modules/system.nix b/modules/system.nix new file mode 100644 index 0000000..63ca609 --- /dev/null +++ b/modules/system.nix @@ -0,0 +1,175 @@ +{ pkgs, ... }: + + ################################################################################### + # + # 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 = { + # 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 + ''; + + defaults = { + menuExtraClock.Show24Hour = true; # show 24 hour clock + + # customize dock + # dock = { + # autohide = true; + # show-recents = false; # disable recent apps + + # # customize Hot Corners + # wvous-tl-corner = 2; # top-left - Mission Control + # wvous-tr-corner = 13; # top-right - Lock Screen + # wvous-bl-corner = 3; # bottom-left - Application Windows + # wvous-br-corner = 4; # bottom-right - Desktop + # }; + + # # customize finder + # finder = { + # _FXShowPosixPathInTitle = true; # show full path in finder title + # AppleShowAllExtensions = true; # show all file extensions + # FXEnableExtensionChangeWarning = false; # disable warning when changing file extension + # QuitMenuItem = true; # enable quit menu item + # ShowPathbar = true; # show path bar + # ShowStatusBar = true; # show status bar + # }; + + # # customize trackpad + # trackpad = { + # Clicking = true; # enable tap to click + # 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; # enable natural scrolling(default to true) + # "com.apple.sound.beep.feedback" = 0; # disable beep sound when pressing volume up/down key + # AppleInterfaceStyle = "Dark"; # dark mode + # AppleKeyboardUIMode = 3; # Mode 3 enables full keyboard control. + # ApplePressAndHoldEnabled = true; # enable press and hold + + # # If you press and hold certain keyboard keys when in a text area, the key’s character begins to repeat. + # # This is very useful for vim users, they use `hjkl` to move cursor. + # # sets how long it takes before it starts repeating. + # InitialKeyRepeat = 15; # normal minimum is 15 (225 ms), maximum is 120 (1800 ms) + # # sets how fast it repeats once it starts. + # KeyRepeat = 3; # normal minimum is 2 (30 ms), maximum is 120 (1800 ms) + + # NSAutomaticCapitalizationEnabled = false; # disable auto capitalization(自动大写) + # NSAutomaticDashSubstitutionEnabled = false; # disable auto dash substitution(智能破折号替换) + # NSAutomaticPeriodSubstitutionEnabled = false; # disable auto period substitution(智能句号替换) + # NSAutomaticQuoteSubstitutionEnabled = false; # disable auto quote substitution(智能引号替换) + # NSAutomaticSpellingCorrectionEnabled = false; # disable auto spelling correction(自动拼写检查) + # NSNavPanelExpandedStateForSaveMode = true; # expand save panel by default(保存文件时的路径选择/文件名输入页) + # NSNavPanelExpandedStateForSaveMode2 = 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.spaces" = { + # "spans-displays" = 0; # Display have seperate spaces + # }; + # "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.screencapture" = { + # location = "~/Desktop"; + # type = "png"; + # }; + # "com.apple.AdLib" = { + # allowApplePersonalizedAdvertising = false; + # }; + # # Prevent Photos from opening automatically when devices are plugged in + # "com.apple.ImageCapture".disableHotPlug = true; + # }; + + # loginwindow = { + # GuestEnabled = false; # disable guest user + # SHOWFULLNAME = true; # show full name in login window + # }; + }; + + # 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 = true; # remap caps lock to escape, useful for vim users + + # # swap left command and left alt + # # so it matches common keyboard layout: `ctrl | command | alt` + # # + # # disabled, caused only problems! + # swapLeftCommandAndLeftAlt = false; + # }; + }; + + # Add ability to used TouchID for sudo authentication + security.pam.enableSudoTouchIdAuth = 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 + pkgs.fish + pkgs.bash + ]; + + # Set your time zone. + time.timeZone = "America/Detroit"; +}