Skip to content

Commit

Permalink
Start using home-manager and nix-darwin
Browse files Browse the repository at this point in the history
* Created Makefile to manage install/uninstall
* Created my first flake containing basics

Installed the basics from Nix pkgs and linked their configs out of
the `files` directory, one day to be replaced with something more
Nix-native:

* zsh
* tmux
* neovim

Signed-off-by: Stephen Hoekstra <[email protected]>
  • Loading branch information
shoekstra committed May 7, 2023
1 parent 094f546 commit 4c7ae7f
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.bundle/
result
vendor/
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}'
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions files/neovim/nvimrc → files/neovim/init.vim
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions files/zsh/fzf.zsh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 0 additions & 5 deletions lib/got_files/gpg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions lib/got_files/terminal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/gpg.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
85 changes: 85 additions & 0 deletions nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions nix/flake.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
};
}
22 changes: 22 additions & 0 deletions nix/hosts/sbpltt6cllvdl/default.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}
37 changes: 37 additions & 0 deletions nix/hosts/sbpltt6cllvdl/home.nix
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions nix/hosts/sbpltt6cllvdl/nvim.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
20 changes: 20 additions & 0 deletions nix/hosts/sbpltt6cllvdl/tmux.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
16 changes: 16 additions & 0 deletions nix/hosts/sbpltt6cllvdl/zsh.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
32 changes: 32 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions scripts/install_homebrew.sh
Original file line number Diff line number Diff line change
@@ -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)"
Loading

0 comments on commit 4c7ae7f

Please sign in to comment.