diff --git a/.files-settings b/.files-settings index cbb1e54e8..66a5f80c2 100644 --- a/.files-settings +++ b/.files-settings @@ -1,5 +1,4 @@ { - "asdf": false, "editor": "nvim", "fzf": true, "git-aliases": true, diff --git a/.gitignore b/.gitignore index 84cebab6a..65c4f4872 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,22 @@ # scratch files temp.* + # tokens, credentials, etc. secrets.* + # any built targets (e.g. rust analyzer language server) target + # `brew bundle` "lock" file - not actually for reproducible installs, mostly a # debugging tool # ref - https://github.com/Homebrew/homebrew-bundle/pull/552 Brewfile.lock.json + # local overrides zsh/local.zsh + # ignore unused Alfred settings **/Alfred.alfredpreferences/remote + +# build artifacts from nix +result diff --git a/Makefile b/Makefile index 6c3338944..c9a0e99fb 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # - http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ # targets without immediate file dependencies -.PHONY: all check fix format gui help lint nix setup headless-setup symlink +.PHONY: all check fix format gui help lint nix headless-setup setup .DEFAULT_GOAL := help lint: @@ -28,30 +28,25 @@ setup: nix: ./infra/setup/bin/setup_nix -symlink: - ./infra/setup/bin/symlink - gui: ./gui/setup/setup_gui -# config specific to my use cases -nathan: - ./infra/setup/bin/symlink --nathan - ./infra/setup/bin/setup_macos_settings - all: ./infra/setup/setup_dotfiles ./gui/setup/setup_gui +apply: + ./nix/apply + help: @echo 'make help' @echo ' show this help message' @echo 'make setup' @echo ' set up dotfiles' + @echo 'make apply' + @echo ' apply latest config' @echo 'make nix' @echo ' set up nix' - @echo 'make symlink' - @echo ' symlink config files (like .zshrc) to their appropriate locations' @echo 'make gui' @echo ' set up gui parts of config' @echo 'make all' diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..216a72d92 --- /dev/null +++ b/flake.lock @@ -0,0 +1,71 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1605395522, + "narHash": "sha256-s1T94x5wnY3TqStT6d9IUA8sLYO76/ZV6HOckovVjmY=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "b04aa56503c59d07a72361dfe9845c3ab2faac1b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1604840733, + "narHash": "sha256-cJd1LRPfKbYVbj/kAhWvwGm7K1E+e5rmqgPVEYVhlWs=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "56f01699fbe462ae9f361ff08d2dbb9e898b9439", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1606571096, + "narHash": "sha256-Vi9b+jFGj6/HpLhHt5lA6l2WnOt2agSXPVfQL3/lINo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7d71d3dc80c3f42600d3ff21ba0029ad0c217067", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-20.09-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..113ade50e --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + description = ".files"; + + inputs = { + # TODO: switch to unstable once macOS Big Sur support has landed + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-20.09-darwin"; + + home-manager.url = "github:nix-community/home-manager/master"; + # set home-manager's nipxkgs input to the nixpkgs specified in this flake + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + + nix-darwin.url = "github:lnl7/nix-darwin/master"; + # set nix-darwin's nipxkgs input to the nixpkgs specified in this flake + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nix-darwin, nixpkgs, home-manager }: { + darwinConfigurations."smino" = nix-darwin.lib.darwinSystem { + modules = [ home-manager.darwinModules.home-manager ./nix/darwin.nix ]; + }; + darwinConfigurations."nathan-shelly-od-mac" = nix-darwin.lib.darwinSystem { + modules = [ home-manager.darwinModules.home-manager ./nix/darwin.nix ]; + }; + # technically `nix-darwin` looks for a config specified by hostname + # (not sure when, if ever, that's different from $HOST) + # TODO: figure out how to actually make generic/universal config + darwinConfigurations."${builtins.getEnv "HOST"}" = nix-darwin.lib.darwinSystem { + modules = [ home-manager.darwinModules.home-manager ./nix/darwin.nix ]; + }; + }; +} diff --git a/functions/smat b/functions/smat index f08e93531..06c1a32df 100755 --- a/functions/smat +++ b/functions/smat @@ -3,11 +3,11 @@ # render given args with best available command render_args() { # use `mdcat` when passed a single markdown file + # TODO: use `mdcat` w/ multiple files all are `*.md` [[ -z $2 ]] && [[ $1 =~ \.md$ ]] && command -v mdcat > /dev/null && { - # display markdown file using `mdcat` w/ a pager - # TODO: use `--paginate` flag once released - # ref - https://github.com/lunaryorn/mdcat/issues/152 - mdcat "$1" | less --no-init --quit-if-one-screen --raw-control-chars + # `--paginate` applies the pager defined in $PAGER (or $MDCAT_PAGER w/ a + # default of `less --raw-control-characters`) + mdcat --paginate "$1" return } diff --git a/gui/apps/karabiner/README.md b/gui/apps/karabiner/README.md index 1f4f84ffc..b2def7f0d 100644 --- a/gui/apps/karabiner/README.md +++ b/gui/apps/karabiner/README.md @@ -31,7 +31,6 @@ brew install "yqrashawn/goku/goku" Finally run the following command from anywhere to apply the config: ```console -~/.files on goku ❯ GOKU_EDN_CONFIG_FILE="$DOTFILES/gui/apps/karabiner/karabiner.edn" goku Done! ``` diff --git a/gui/apps/vscode/settings.json b/gui/apps/vscode/settings.json index f7aaf7fe7..c4ecf9ff3 100644 --- a/gui/apps/vscode/settings.json +++ b/gui/apps/vscode/settings.json @@ -205,8 +205,5 @@ "trailing-spaces.highlightCurrentLine": false, // <<<<<< vs icons >>>>>> "vsicons.dontShowNewVersionMessage": true, - "python.defaultInterpreterPath": "/Users/nathan/.nix-profile/bin/python", - // ######### rust-analyzer ########## - "rust-analyzer.updates.channel": "nightly", - "rust-analyzer.serverPath": "rust-analyzer" + "python.defaultInterpreterPath": "/Users/nathan/.nix-profile/bin/python" } diff --git a/gui/setup/setup_brew b/gui/setup/setup_brew index 091093203..f85008948 100755 --- a/gui/setup/setup_brew +++ b/gui/setup/setup_brew @@ -7,8 +7,7 @@ source "${BASH_SOURCE%/*}/../../infra/setup/check_dotfiles_variable.sh" source "$DOTFILES/infra/scripts/prompts.sh" "$DOTFILES/infra/scripts/is_macos.sh" || { - info "these dotfiles don't use \`brew\` in Linux environments" - info 'skipping install' + info "these dotfiles don't use \`brew\` in Linux environments - skipping" return } @@ -25,11 +24,23 @@ info '`brew` not installed, installing now...' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" # fix permissions issues for `compinit` caused by Homebrew messing with things -# -# ref - https://stackoverflow.com/a/43544733 -# # TODO: run conditionally -compaudit | xargs chown -R "$(whoami)" -compaudit | xargs chmod go-w +fix_permissions_issue() { + local fix_permissions_commands + + # fix permissions on `/user/local/share/*` folder that Homebrew's installer + # messes with + # + # refs + # - https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh + # - https://stackoverflow.com/a/43544733 + fix_permissions_commands="chmod -R go-w \"$(brew --prefix)/share\";" + + info "Fixing completions permission issue" + # `--no-rcs` to avoid running `compinit` and triggering warnings that we're + # about to fix + zsh --no-rcs -c "$fix_permissions_commands" > /dev/null +} +fix_permissions_issue brew analytics off # disable analytics diff --git a/gui/setup/setup_desktop_apps b/gui/setup/setup_desktop_apps index 3ee1072fa..5797e1afa 100755 --- a/gui/setup/setup_desktop_apps +++ b/gui/setup/setup_desktop_apps @@ -59,13 +59,13 @@ you have previously installed them. (y/any other key)" # Xcode - https://apps.apple.com/us/app/xcode/id497799835 mas install 497799835 + # accept license so that installed components are usable + sudo xcodebuild -license accept + # Super Easy Timer (paid, $5) - https://apps.apple.com/us/app/super-easy-timer/id1353137878 mas install 1353137878 # Time Out (in-app purchases) - https://apps.apple.com/us/app/time-out-break-reminders/id402592703 mas install 402592703 - - # TODO: verify fixes Xcode installation issue - sudo xcodebuild -license accept } # handle any arguments/flags diff --git a/gui/xvimrc b/gui/xvimrc deleted file mode 100644 index 2a2590e64..000000000 --- a/gui/xvimrc +++ /dev/null @@ -1,33 +0,0 @@ -" Options - -set wrap -set number - -set incsearch -set hlsearch - -set ignorecase -set smartcase - -" Mappings - -inoremap jk - -nnoremap J } -vnoremap J } -nnoremap K { -vnoremap K { - -nnoremap z $ -vnoremap z $h -nnoremap Z ^ -vnoremap Z ^ - -nmap == :xcmenucmd Re-Indent -vmap = :xcmenucmd Re-Indent - -nmap :xcmenucmd Go Forward -nmap :xcmenucmd Go Back - -nmap :xcmenucmd Open in Next Editor -nmap :xcmenucmd Close Editor:xcmenucmd Move Focus to Next Editor diff --git a/infra/README.md b/infra/README.md index e550d4959..33113533b 100644 --- a/infra/README.md +++ b/infra/README.md @@ -6,5 +6,6 @@ Various configuration and tooling supporting these dotfiles. - [`actions`](./actions) - CI checks using GitHub actions - [`docs`](./docs) - documentation for these dotfiles +- [`docker`](./docker) - play with these dotfiles in a docker sandbox - [`scripts`](./scripts) - various scripts used throughout these dotfiles - [`setup`](./setup) - code to set up and configure these dotfiles diff --git a/misc/docker/dotfiles/Dockerfile b/infra/docker/Dockerfile similarity index 100% rename from misc/docker/dotfiles/Dockerfile rename to infra/docker/Dockerfile diff --git a/misc/docker/dotfiles/README.md b/infra/docker/README.md similarity index 100% rename from misc/docker/dotfiles/README.md rename to infra/docker/README.md diff --git a/infra/docs/settings.md b/infra/docs/settings.md index 7256fe5b7..7a527e352 100644 --- a/infra/docs/settings.md +++ b/infra/docs/settings.md @@ -8,7 +8,6 @@ Currently these options are primarily booleans enabling or disabling a specific ```jsonc { - "asdf": boolean, // enable/disable versions via `asdf` // value of $EDITOR - "nvim", "emacs", "code", etc. "editor": "", "fzf": boolean, // enable/disable `fzf` including keybindings & completions diff --git a/infra/scripts/component_enabled.sh b/infra/scripts/component_enabled.sh index 25bfa6e99..e3cdfbc32 100755 --- a/infra/scripts/component_enabled.sh +++ b/infra/scripts/component_enabled.sh @@ -1,6 +1,10 @@ #! /usr/bin/env bash -command -v jq > /dev/null || exit 1 +main() { + local enabled + enabled="$("$DOTFILES/infra/scripts/get_local_setting.sh" "$1")" -ENABLED="$("$DOTFILES/infra/scripts/get_local_setting.sh" "$1")" -[[ $ENABLED == true ]] + [[ $enabled == true ]] +} + +main "$@" diff --git a/infra/setup/bin/README.md b/infra/setup/bin/README.md index 4e887f5df..1b3063953 100644 --- a/infra/setup/bin/README.md +++ b/infra/setup/bin/README.md @@ -3,10 +3,10 @@ Various setup scripts - [`setup_git_config`](./setup_git_config) - fill in [`gitconfig.template`](../../../utilities/git/gitconfig.template) template -- [`setup_asdf`](./setup_asdf) - add [`asdf`](https://github.com/asdf-vm/asdf) [plugins](https://github.com/asdf-vm/asdf-plugins) then run `asdf install` to install global versions of packages - [`setup_bits_and_pieces`](./setup_bits_and_pieces) - set up various bits and pieces - [`setup_macos_settings`](./setup_macos_settings) - set macOS configuration (currently unimplemented) - [`setup_neovim`](./setup_neovim) - set up [`neovim`](https://neovim.io/) text editor +- [`setup_nix`](./setup_nix) - set up [Nix](https://nixos.org/) - [`setup_work`](./setup_work) - add work-specific configuration (currently just a work-specific gitconfig (name & email)) - [`symlink`](./symlink) - symlink all necessary config files to their respective locations (e.g. `$DOTFILES/neovim/init.vim` -> "\$HOME/.config/nvim/init.vim") - [`setup_zsh`](./setup_zsh) - adds [`zsh`](http://zsh.sourceforge.net/) to `/etc/shells`, sets it to the default shell, and loads `zsh` to install plugins & finish installation diff --git a/infra/setup/bin/backup_file b/infra/setup/bin/backup_file new file mode 100755 index 000000000..051dd4d6c --- /dev/null +++ b/infra/setup/bin/backup_file @@ -0,0 +1,24 @@ +#! /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" + +# backup single file +# +# Args: +# - {string} target - file to backup +# - {string} [extension = bak] - extension of created file, default of bak +backup_file() { + # parameters + local src="$1" ext="${2:-bak}" + + [ -f "$src" ] && { + # TODO: conditionally use sudo here + sudo mv "$src" "$src.$ext" + } +} + +backup_file "$@" diff --git a/infra/setup/bin/link_file b/infra/setup/bin/link_file new file mode 100755 index 000000000..d43dafa2b --- /dev/null +++ b/infra/setup/bin/link_file @@ -0,0 +1,101 @@ +#! /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 `