diff --git a/.gitignore b/.gitignore index 4541a7b..92df7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .bundle/ +result vendor/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..356a6cf --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +NIXPKGS_DIR := $(HOME)/.config/nixpkgs + +.PHONY: default install switch uninstall help + +default: help + +install: install-homebrew ## Install Homebrew and Nix and activate this configuration + @sh -c "'$(CURDIR)/scripts/install.sh'" + +install-homebrew: + @sh -c "'$(CURDIR)/scripts/install_homebrew.sh'" + +switch: ## Activate latest changes + @sh -c "./result/sw/bin/darwin-rebuild switch --flake ./nix" + +uninstall: ## Uninstall Nix + @sh -c "'$(CURDIR)/scripts/uninstall.sh'" + +uninstall-homebrew: + @sh -c "'$(CURDIR)/scripts/uninstall_homebrew.sh'" + +help: ## Display this help screen + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index cbf0987..4ff7cfd 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,20 @@ My dot-files. +I use [Rake](https://ruby.github.io/rake/) to manage my dot-files. It uses [Homebrew](https://brew.sh/) to install packages and Ruby to install dot-files and/or perform any extra customisations. + +I'm in the process of moving to a [nix-based setup](https://nixos.org/explore.html) -- using [nix-darwin](https://github.com/LnL7/nix-darwin) and [Home Manager](https://github.com/nix-community/home-manager) -- to replace this home-grown solution. + +If this setup is new to you, these resources helped me: + +* [Home Manager Manual](https://nix-community.github.io/home-manager/) +* [Migrating from Homebrew to Nix for OSX](https://discourse.nixos.org/t/migrating-from-homebrew-to-nix-for-osx/2892) +* [Declarative macOS Configuration Using nix-darwin And home-manager](https://xyno.space/post/nix-darwin-introduction) +* [Setup nix, nix-darwin and home-manager from scratch on an M1 Macbook Pro](https://gist.github.com/jmatsushita/5c50ef14b4b96cb24ae5268dab613050) +* [How to Learn Nix, Part 19 Switching from Homebrew to Nix](https://ianthehenry.com/posts/how-to-learn-nix/switching-from-homebrew-to-nix/) + +I probably should've learned how to use Nix the current way, but instead I've started using the [experimental Flake method](https://nixos.wiki/wiki/Flakes). This will no doubt get some major rewrites as I learn how nix, flakes and the different modules work together. + ## Installation Install Xcode developer tools: @@ -17,14 +31,22 @@ git clone https://github.com/shoekstra/gotfiles.git ~/git/gotfiles cd ~/git/gotfiles ``` +Setup Home Manager before running `rake install`. + +### Home Manager + +```shell +make install +``` + +### Ruby + Install required gems: ```shell bundle install --path vendor/bundle ``` -## Usage - View options: ```shell diff --git a/files/neovim/nvimrc b/files/neovim/init.vim similarity index 98% rename from files/neovim/nvimrc rename to files/neovim/init.vim index f920f68..8efdcb5 100644 --- a/files/neovim/nvimrc +++ b/files/neovim/init.vim @@ -1,6 +1,3 @@ -" Path to python3 bin -let g:python3_host_prog = '/usr/local/bin/python3' - " Plugins - install vim-plug then load them if empty(glob('~/.config/nvim/autoload/plug.vim')) silent execute '!curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' @@ -17,6 +14,7 @@ Plug 'ekalinin/Dockerfile.vim' Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } Plug 'godlygeek/tabular' Plug 'hashivim/vim-hashicorp-tools' +Plug 'lnl7/vim-nix' Plug 'mhinz/vim-startify' Plug 'raimondi/delimitmate' Plug 'sirver/ultisnips' | Plug 'honza/vim-snippets' diff --git a/files/zsh/fzf.zsh b/files/zsh/fzf.zsh new file mode 100644 index 0000000..bcae1b9 --- /dev/null +++ b/files/zsh/fzf.zsh @@ -0,0 +1,13 @@ +# Setup fzf +# --------- +if [[ ! "$PATH" == */usr/local/opt/fzf/bin* ]]; then + export PATH="${PATH:+${PATH}:}/usr/local/opt/fzf/bin" +fi + +# Auto-completion +# --------------- +[[ $- == *i* ]] && source "/usr/local/opt/fzf/shell/completion.zsh" 2> /dev/null + +# Key bindings +# ------------ +source "/usr/local/opt/fzf/shell/key-bindings.zsh" diff --git a/lib/got_files/gpg.rb b/lib/got_files/gpg.rb index 886e863..1f16e6c 100644 --- a/lib/got_files/gpg.rb +++ b/lib/got_files/gpg.rb @@ -4,11 +4,6 @@ module GotFiles class Gpg < Base - def install - brew_install_if_missing("gnupg", "GnuPG") - brew_install_if_missing("pinentry-mac", "pinentry-mac") - end - def setup(key) return unless key diff --git a/lib/got_files/terminal.rb b/lib/got_files/terminal.rb index ae4ba77..8e5cebf 100644 --- a/lib/got_files/terminal.rb +++ b/lib/got_files/terminal.rb @@ -9,12 +9,6 @@ def install brew_install_if_missing("coreutils") # required gdircolors and gls brew_install_if_missing("ccat", "ccat") - brew_install_if_missing("rename", "rename") - - # Git tools - brew_install_if_missing("hub", "hub") - brew_install_if_missing("github/gh/gh", "GitHub CLI") - brew_install_if_missing("zaquestion/tap/lab", "GitLab CLI") install_fzf install_zim diff --git a/lib/tasks/gpg.rake b/lib/tasks/gpg.rake index 96788f8..052c5eb 100644 --- a/lib/tasks/gpg.rake +++ b/lib/tasks/gpg.rake @@ -6,7 +6,6 @@ namespace "install" do require "got_files/Gpg" gpg = GotFiles::Gpg.new - gpg.install gpg.setup(args[:key_to_import]) end end diff --git a/nix/flake.lock b/nix/flake.lock new file mode 100644 index 0000000..49e83cb --- /dev/null +++ b/nix/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1680266963, + "narHash": "sha256-IW/lzbUCOcldLHWHjNSg1YoViDnZOmz0ZJL7EH9OkV8=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "99d4187d11be86b49baa3a1aec0530004072374f", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1680389554, + "narHash": "sha256-+8FUmS4GbDMynQErZGXKg+wU76rq6mI5fprxFXFWKSM=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "ddd8866c0306c48f465e7f48432e6f1ecd1da7f8", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1680213900, + "narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e3652e0735fbec227f342712f180f4f21f0594f2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "darwin": "darwin", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + }, + "utils": { + "locked": { + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..02d6228 --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,24 @@ +{ + description = "My first flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + + darwin.url = "github:lnl7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, home-manager, darwin }: { + darwinConfigurations."sbpltt6cllvdl" = darwin.lib.darwinSystem { + system = "x86_64-darwin"; + + modules = [ + home-manager.darwinModules.home-manager + ./hosts/sbpltt6cllvdl/default.nix + ]; + }; + }; +} diff --git a/nix/hosts/sbpltt6cllvdl/default.nix b/nix/hosts/sbpltt6cllvdl/default.nix new file mode 100644 index 0000000..d33dce1 --- /dev/null +++ b/nix/hosts/sbpltt6cllvdl/default.nix @@ -0,0 +1,22 @@ +{ pkgs, ... }: + +{ + # Make sure the nix daemon always runs + services.nix-daemon.enable = true; + + # If you use zsh you'll need to enable this so nix-darwin creates a zshrc sourcing needed environment changes + programs.zsh.enable = true; + + homebrew.enable = true; + homebrew.casks = [ + ]; + + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users."shoekstra" = import ./home.nix; + + # This needs to be to set for things to work (see https://github.com/LnL7/nix-darwin/issues/423) + users.users."shoekstra" = { + home = "/Users/shoekstra"; + }; +} diff --git a/nix/hosts/sbpltt6cllvdl/home.nix b/nix/hosts/sbpltt6cllvdl/home.nix new file mode 100644 index 0000000..c2a2628 --- /dev/null +++ b/nix/hosts/sbpltt6cllvdl/home.nix @@ -0,0 +1,37 @@ +{ config, pkgs, ... }: + +let + imports = [ + ./nvim.nix + ./tmux.nix + ./zsh.nix + ]; + +in { + + inherit imports; + + # You cannot install or search for an unfree package unless explicitly enabling + # it with the following: + nixpkgs.config.allowUnfree = true; + + # Home Manager needs a bit of information about you and the paths it should + # manage. + home.username = "shoekstra"; + home.homeDirectory = "/Users/shoekstra"; + + # 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 should not change this value, even if you update Home Manager. If you do + # want to update the value, then make sure to first check the Home Manager + # release notes. + home.stateVersion = "22.11"; # Please read the comment before changing. + + home.sessionVariables = { + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/nix/hosts/sbpltt6cllvdl/nvim.nix b/nix/hosts/sbpltt6cllvdl/nvim.nix new file mode 100644 index 0000000..e2b53b0 --- /dev/null +++ b/nix/hosts/sbpltt6cllvdl/nvim.nix @@ -0,0 +1,13 @@ +{ config, pkgs, ... }: + +{ + home.packages = with pkgs; [ + neovim + (python3.withPackages(ps: with ps; [ pynvim ])) + ]; + + home.file = { + ".config/nvim".source = ../../../files/neovim; + ".config/nvim".recursive = true; + }; +} diff --git a/nix/hosts/sbpltt6cllvdl/tmux.nix b/nix/hosts/sbpltt6cllvdl/tmux.nix new file mode 100644 index 0000000..b6fd91b --- /dev/null +++ b/nix/hosts/sbpltt6cllvdl/tmux.nix @@ -0,0 +1,20 @@ +{ config, pkgs, ... }: + +{ + home.packages = with pkgs; [ + reattach-to-user-namespace + tmux + ]; + + home.file = { + ".tmux".source = pkgs.fetchFromGitHub { + owner = "gpakosz"; + repo = ".tmux"; + rev = "7706ab724f3811479a358c6f9ea6aeb6decece5f"; + sha256 = "sha256-o126SathIT49Mj9EZDhlYF5i3EgRe2HFZkoGXTVQBbw="; + }; + + ".tmux.conf".source = config.lib.file.mkOutOfStoreSymlink "/Users/shoekstra/.tmux/.tmux.conf"; + ".tmux.conf.local".source = ../../../files/tmux/tmux.conf.local; + }; +} diff --git a/nix/hosts/sbpltt6cllvdl/zsh.nix b/nix/hosts/sbpltt6cllvdl/zsh.nix new file mode 100644 index 0000000..706b27c --- /dev/null +++ b/nix/hosts/sbpltt6cllvdl/zsh.nix @@ -0,0 +1,16 @@ +{ config, pkgs, ... }: + +{ + + # Use existing dotfiles until moving to a nix native way of managing zsh. + home.file = { + ".fzf.zsh".source = ../../../files/zsh/fzf.zsh; + ".p10k.zsh".source = ../../../files/zsh/p10k.zsh; + ".zaliases".source = ../../../files/zsh/zaliases; + ".zfunctions".source = ../../../files/zsh/zfunctions; + ".zimrc".source = ../../../files/zsh/zimrc; + ".zsh-dircolors.config".source = ../../../files/zsh/zsh-dircolors.config; + ".zshenv".source = ../../../files/zsh/zshenv; + ".zshrc".source = ../../../files/zsh/zshrc; + }; +} diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..bf7c658 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +echo "==> Installing Nix..." + +for file in /etc/*.backup-before-nix; do + [ -e "${file}" ] && sudo rm -v ${file} +done + +curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install + +echo "==> Running first build..." + +# Initial build +. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh +nix build "./nix#darwinConfigurations.$(hostname).system" --extra-experimental-features "nix-command flakes" + +# Manual steps for nix-darwin to work with flakes +grep -q "private/var/run" /etc/synthetic.conf || printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf +/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t + +for file in /etc/bashrc /etc/nix/nix.conf /etc/zshrc; do + [ -e "${file}" ] && sudo mv ${file} ${file}.before-nix-darwin +done + +echo "==> Running first switch..." + +./result/sw/bin/darwin-rebuild switch --flake ./nix + +grep -q "/etc/static/zshrc" /etc/zshrc || echo 'if test -e /etc/static/zshrc; then . /etc/static/zshrc; fi' | sudo tee -a /etc/zshrc + +echo "==> Setup complete!" +echo "Run \"darwin-rebuild switch --flake ./nix\" to rebuild your configuration after any changes" diff --git a/scripts/install_homebrew.sh b/scripts/install_homebrew.sh new file mode 100755 index 0000000..ef88bfc --- /dev/null +++ b/scripts/install_homebrew.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "==> Installing homebrew..." + +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh new file mode 100755 index 0000000..3af6262 --- /dev/null +++ b/scripts/uninstall.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +if [ -x "home-manager" ]; then + echo "==> Uninstalling Home Manager..." + home-manager uninstall +fi + +echo "==> Uninstalling Nix..." +/nix/nix-installer uninstall + +echo "==> Uninstall complete!" diff --git a/scripts/uninstall_homebrew.sh b/scripts/uninstall_homebrew.sh new file mode 100755 index 0000000..7bfc43d --- /dev/null +++ b/scripts/uninstall_homebrew.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "==> Uninstalling homebrew..." + +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"