Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

declare & apply via Nix #105

Closed
wants to merge 114 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
a4798e7
Add `nix-darwin` setup
nathanshelly Jul 8, 2020
909075a
Remove unneeded initialization
nathanshelly Jul 8, 2020
b329e83
Guard `hm...` & `dr...` aliases
nathanshelly Jul 26, 2020
23cb7b4
Update setup
nathanshelly Jul 26, 2020
505d5f6
Remove `home-manager` initialization
nathanshelly Jul 26, 2020
e9c1149
Put user profile first on path
nathanshelly Jul 26, 2020
d248a8b
Remove packages from home-manager config
nathanshelly Jul 26, 2020
95082b0
nix: get `fzf` config file location via `fzf-share`
nathanshelly Aug 15, 2020
f1638eb
Fix `home.nix` symlinking
nathanshelly Aug 15, 2020
72ce636
Update default shell setting
nathanshelly Aug 22, 2020
4d404dc
Clean up `setup_zsh`
nathanshelly Aug 22, 2020
0ef357a
Fix redirection
nathanshelly Aug 29, 2020
f3d52b9
refactor
nathanshelly Oct 3, 2020
3699c24
add first draft of `nix/README.md`
nathanshelly Oct 3, 2020
3fb482d
add os-specific apply script
nathanshelly Oct 3, 2020
95665af
reword: development -> user
nathanshelly Oct 8, 2020
1044ceb
tweak
nathanshelly Oct 8, 2020
6e7865b
wip
nathanshelly Oct 8, 2020
c40b56f
refactor `misc` folder
nathanshelly Oct 9, 2020
7a7f402
rewrite
nathanshelly Oct 9, 2020
220a535
remove now-declared `fzf` config
nathanshelly Oct 9, 2020
3735560
remove unnecessary global tool-versions
nathanshelly Oct 9, 2020
08dc95d
move git{config,ignore} -> `git.nix`
nathanshelly Oct 9, 2020
794f862
add additional specific nix config blobs
nathanshelly Oct 9, 2020
a764512
remove now-declared config
nathanshelly Oct 9, 2020
2fb4499
misc
nathanshelly Oct 9, 2020
25224c2
move xvimrc -> `gui.nix`
nathanshelly Oct 9, 2020
7cd2f0c
refactor
nathanshelly Oct 9, 2020
56e6884
remove asdf
nathanshelly Oct 9, 2020
092121e
remove references to `bin/symlink`
nathanshelly Oct 9, 2020
1bdfbc9
clean up
nathanshelly Oct 9, 2020
25ab0c5
revert management of path
nathanshelly Oct 9, 2020
4b322bc
conditionally load nathan-specific config
nathanshelly Oct 9, 2020
e1d27a7
clean up zsh management
nathanshelly Oct 9, 2020
da2d945
first attempts at managing neovim
nathanshelly Oct 9, 2020
f127e4f
use matchBlocks
nathanshelly Oct 9, 2020
7c3aa0f
use `xdg.configHome`
nathanshelly Oct 17, 2020
feb24ba
refactor gui & conditionally apply
nathanshelly Oct 17, 2020
dce845b
clean up
nathanshelly Oct 17, 2020
290d9e9
add in-progress thoughts on README
nathanshelly Oct 17, 2020
c16058a
nvim: clean up plugins
nathanshelly Oct 17, 2020
b14a743
add coc.nvim TODO
nathanshelly Oct 18, 2020
45a80b5
grab bag
nathanshelly Oct 18, 2020
635e12d
interactive `nix-darwin` installer
nathanshelly Oct 18, 2020
6999afc
fix up
nathanshelly Oct 18, 2020
3629178
symlink `home.nix` manually
nathanshelly Oct 18, 2020
597aafe
factor our link_file script
nathanshelly Oct 18, 2020
67d033c
setup script improvements
nathanshelly Oct 18, 2020
1667826
clean up nix-darwin file backup
nathanshelly Oct 18, 2020
cdcd9d6
remove python dependencies in `setup_neovim`
nathanshelly Oct 18, 2020
2446e3a
small refactor
nathanshelly Oct 18, 2020
08d5aef
clean up & comment out backup
nathanshelly Oct 19, 2020
394a733
git: language-specific diff headers
nathanshelly Oct 24, 2020
674218a
git: comment character from `#` -> `;`
nathanshelly Oct 24, 2020
73733cd
ignore nix build artifacts
nathanshelly Nov 9, 2020
1c8fdeb
grab bag
nathanshelly Nov 9, 2020
014737b
add first flake draft
nathanshelly Nov 9, 2020
e93860e
fix up installation script issues
nathanshelly Nov 8, 2020
fe0758a
use `zsh` to enable `compaudit`
nathanshelly Nov 8, 2020
37edc81
install `vim-plug` outside nix
nathanshelly Nov 8, 2020
8430030
add back nix path extension
nathanshelly Nov 8, 2020
d8fd8f1
add flake install to setup
nathanshelly Nov 8, 2020
57f048a
use $USER instead of "nathan"
nathanshelly Nov 8, 2020
a4604c7
learnings from test runs on wiped laptop
nathanshelly Nov 8, 2020
819c6cd
use home-manager from flake, not global
nathanshelly Nov 8, 2020
98021f5
use flake in initial setup
nathanshelly Nov 8, 2020
b7c0b87
switch back to bash
nathanshelly Nov 8, 2020
82aa88f
fix homebrew completions permissions issue
nathanshelly Nov 8, 2020
ba3fba2
fix homebrew completions permissions issue try ii
nathanshelly Nov 9, 2020
c84eec0
silence compaudit
nathanshelly Nov 9, 2020
4cefc4b
edit nix path earlier
nathanshelly Nov 9, 2020
72eae6e
remove inaccurate sudo message
nathanshelly Nov 9, 2020
23caea2
tweaks from test runs
nathanshelly Nov 9, 2020
09bb694
refactor
nathanshelly Nov 9, 2020
8ad5a81
use non-flake `darwin-rebuild switch` to enable flakes
nathanshelly Nov 9, 2020
07ec635
add back import for first generation
nathanshelly Nov 9, 2020
c311111
fix `vim-plug` installation
nathanshelly Nov 9, 2020
b9d922a
attempt to source nix setup script
nathanshelly Nov 9, 2020
3d9b117
add default darwin config
nathanshelly Nov 9, 2020
773d300
whoops fixups
nathanshelly Nov 9, 2020
7dc2f22
add TODO
nathanshelly Nov 9, 2020
f508896
fix lint
nathanshelly Nov 9, 2020
c7c8efc
try a few setup script tweaks
nathanshelly Nov 10, 2020
2956535
source file suggested by installer
nathanshelly Nov 12, 2020
2429fc1
remove alfred shortcut change
nathanshelly Nov 14, 2020
02e3fd8
add todo
nathanshelly Nov 14, 2020
31479c8
remove vscode settings changes
nathanshelly Nov 14, 2020
bbfb131
miscellaneous cleanup
nathanshelly Nov 14, 2020
8250502
actually undo alfred shortcut change
nathanshelly Nov 14, 2020
0f4ac41
fix flake inputs
nathanshelly Nov 15, 2020
515b2b6
use `nix-index` over `command-not-found`
nathanshelly Nov 15, 2020
fd59c2e
temporarily add back home-manager import
nathanshelly Nov 16, 2020
4349054
add work config
nathanshelly Nov 16, 2020
276806b
add back initial non-flake rebuild
nathanshelly Nov 16, 2020
c5bad68
enable flake support for `nix-direnv`
nathanshelly Nov 15, 2020
fea1cb3
update to 20.09
nathanshelly Nov 28, 2020
88d114e
remove impure nixpkgs import
nathanshelly Nov 29, 2020
6d7254b
configure delta via home-manager
nathanshelly Nov 29, 2020
761fb29
clean up git.nix
nathanshelly Nov 29, 2020
b230b56
misc cleanup
nathanshelly Nov 29, 2020
5995d59
remove no longer needed symlink setup
nathanshelly Dec 1, 2020
d54a513
respect headless mode in `link_file`
nathanshelly Dec 1, 2020
52bc2e7
add back asdf sourcing
nathanshelly Dec 2, 2020
2289a79
use flake w/ home-manager on od mac
nathanshelly Dec 2, 2020
7fb4e0f
misc: remove and ignore Nix `result` artifact
nathanshelly Dec 6, 2020
5214608
zsh: define `$PAGER` & use it in `smat`
nathanshelly Dec 6, 2020
030928f
zsh: add `fzf-tab` plugin
nathanshelly Dec 11, 2020
33597bd
misc: add TODOs & aliases
nathanshelly Dec 11, 2020
16e4c77
Clean up `setup_zsh`
nathanshelly Aug 22, 2020
da6498d
setup script improvements
nathanshelly Oct 18, 2020
c52212d
remove unneeded path manipulations
nathanshelly Dec 11, 2020
6317180
tweaks
nathanshelly Dec 11, 2020
e367231
add back node version
nathanshelly Dec 11, 2020
fa8acfd
remove unneeded asdf
nathanshelly Dec 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
factor our link_file script
  • Loading branch information
nathanshelly committed Dec 2, 2020
commit 597aafe25f60d22e98788adf839a200a9807b7d3
98 changes: 98 additions & 0 deletions infra/setup/bin/link_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#! /usr/bin/env bash

# check that DOTFILES variable is defined
# shellcheck disable=SC1090
source "${BASH_SOURCE%/*}/../check_dotfiles_variable.sh"

source "$DOTFILES/infra/scripts/prompts.sh"

# link single file between `src` & `dst`
#
# takes user input (potentially modified by `<option>_all` flags defined in
# calling scope)
#
# Args:
# - {string} src - source path
# - {string} dst - target path
link_file() {
# parameters
local src="$1" dst="$2"

# flags set by user interaction
local overwrite='' backup='' skip='' action=''
local overwrite_all=false backup_all=false skip_all=false

if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ]; then
if [ "$overwrite_all" == "false" ] \
&& [ "$backup_all" == "false" ] \
&& [ "$skip_all" == "false" ]; then
local current_src
current_src="$(readlink "$dst")"

if [ "$current_src" == "$src" ]; then
skip=true
else
user "file exists: $dst ($(basename "$src")), what do you want to do? \
[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?"
read -r -s -n 1 action < /dev/tty

case "$action" in
o)
overwrite=true
;;
O)
overwrite_all=true
;;
b)
backup=true
;;
B)
backup_all=true
;;
s)
skip=true
;;
S)
skip_all=true
;;
*) ;;

esac
fi
fi

overwrite=${overwrite:-$overwrite_all}
backup=${backup:-$backup_all}
skip=${skip:-$skip_all}

[ "$overwrite" == true ] && {
if /bin/rm -r "$dst"; then
success "removed $dst"
else
fail "failed to remove $dst"
fi
}

[ "$backup" == true ] && {
if mv "$dst" "${dst}.backup"; then
success "moved $dst to ${dst}.backup"
else
fail "failed to move $dst to ${dst}.backup"
fi
}

[ "$skip" == true ] && info "skipped $src"
fi

# "false" or empty
[ "$skip" != true ] && {
# `-s` for symbolic link
if ln -s "$src" "$dst"; then
success "linked $src to $dst"
else
fail "failed to link $src to $dst"
fi
}
}

link_file "$@"
7 changes: 7 additions & 0 deletions infra/setup/bin/setup_nix
Original file line number Diff line number Diff line change
@@ -110,6 +110,13 @@ maybe_install_home_manager() {
# make home-manager available (also done on each shell load in zshrc)
export NIX_PATH=$HOME/.nix-defexpr/channels${NIX_PATH:+:}$NIX_PATH

# symlink $DOTfiLES/nix/home.nix config in place before first generation
# TODO: see if I can declaratively manage this in Nix
mkdir -p "$HOME/.config/nix"
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/nix/home.nix" \
"$HOME/.config/nix/home.nix"

# install & create first generation
nix-shell '<home-manager>' -A install

100 changes: 6 additions & 94 deletions infra/setup/bin/symlink
Original file line number Diff line number Diff line change
@@ -34,124 +34,36 @@ link_gui_files() {

# terminal emulator
mkdir -p "$XDG_CONFIG_HOME/alacritty"
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/alacritty/alacritty.yml" \
"$XDG_CONFIG_HOME/alacritty/alacritty.yml"

# window organization/resizing
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/rectangle/com.knollsoft.Rectangle.plist" \
"$HOME/Library/Preferences/com.knollsoft.Rectangle.plist"

# window switcher
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/alt-tab/com.lwouis.alt-tab-macos.plist" \
"$HOME/Library/Preferences/com.lwouis.alt-tab-macos.plist"

# launcher (Alfred, Spotlight, Windows search, etc.)
mkdir -p "$HOME/Library/Application Support/ueli"
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/ueli/config.json" \
"$HOME/Library/Application Support/ueli/config.json"

# VSCode - text editor
mkdir -p "$HOME/Library/Application Support/Code/User"
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/vscode/keybindings.json" \
"$HOME/Library/Application Support/Code/User/keybindings.json"
link_file \
"$DOTFILES/infra/setup/bin/link_file" \
"$DOTFILES/gui/apps/vscode/settings.json" \
"$HOME/Library/Application Support/Code/User/settings.json"
}

# link single file between `src` & `dst`
#
# takes user input (potentially modified by `<option>_all` flags defined in
# calling scope)
#
# Args:
# - {string} src - source path
# - {string} dst - target path
link_file() {
# parameters
local src="$1" dst="$2"

# flags set by user interaction
local overwrite='' backup='' skip='' action=''

if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ]; then
if [ "$overwrite_all" == "false" ] \
&& [ "$backup_all" == "false" ] \
&& [ "$skip_all" == "false" ]; then
local current_src
current_src="$(readlink "$dst")"

if [ "$current_src" == "$src" ]; then
skip=true
else
user "file exists: $dst ($(basename "$src")), what do you want to do? \
[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?"
read -r -s -n 1 action < /dev/tty

case "$action" in
o)
overwrite=true
;;
O)
overwrite_all=true
;;
b)
backup=true
;;
B)
backup_all=true
;;
s)
skip=true
;;
S)
skip_all=true
;;
*) ;;

esac
fi
fi

overwrite=${overwrite:-$overwrite_all}
backup=${backup:-$backup_all}
skip=${skip:-$skip_all}

[ "$overwrite" == true ] && {
if /bin/rm -r "$dst"; then
success "removed $dst"
else
fail "failed to remove $dst"
fi
}

[ "$backup" == true ] && {
if mv "$dst" "${dst}.backup"; then
success "moved $dst to ${dst}.backup"
else
fail "failed to move $dst to ${dst}.backup"
fi
}

[ "$skip" == true ] && info "skipped $src"
fi

# "false" or empty
[ "$skip" != true ] && {
# `-s` for symbolic link
if ln -s "$src" "$dst"; then
success "linked $src to $dst"
else
fail "failed to link $src to $dst"
fi
}
}

parse_input() {
for opt in "$@"; do
case $opt in