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

What's your workflow for changing neovim config? #72

Closed
WilliamHsieh opened this issue Feb 6, 2023 · 3 comments
Closed

What's your workflow for changing neovim config? #72

WilliamHsieh opened this issue Feb 6, 2023 · 3 comments

Comments

@WilliamHsieh
Copy link

Hi, I just came across your nyx setup, and I am super interested in your workflow of nix.
Currently, I'm using stow to manage my dotfiles, so modifying my neovim config is as easy as saving quit and reopening.
But from my understanding of home manager, isn't home-manager switch required after each config modification?
It seems like extra overhead for me. Is it how you do it, or is there another way to do it?
Just curious about the whole nix idea. I would like to switch to nix, but I'm not sure what problem it solves for me besides the declarative package manager provided by home-manger.
It would be great if you are willing to share some of your experiments in nix.
Not sure where to contact you though, feel free to delete the issue if it bothers you :)
Thank's for the inspiration BTW.

@EdenEast
Copy link
Owner

EdenEast commented Feb 8, 2023

Glad that you can get some inspiration from my config. To provide a wider context for my config in general, I use many machines / systems that span across windows, mac, and linux. My previous config was an overly complicated ansible setup and then migrated to salt for better windows support. Now I use nix to handle mostly my mac, nixos, and wsl setup. Nix is great for handling your system configuration but one issue is that it is an all or nothing kind of approach. So my config mainly uses nix but not all of it.

Because I use systems that nix does not support (*cough* windows) and some configuration like my neovim constantly change I keep some of my configurations in my config folder at the root of my configuration. You can think of that folder as the root of my $HOME folder on a system.

So with that out of the way, to your actual question about neovim. I use nix to install neovim and the tools that I use with it (like lsp, linters, etc). My neovim config lives at config/.config/nvim. I use nix to link ~/.config/nvim to config/.config/nvim.

The relevant section would be:

xdg.configFile."nvim".source = ../../../config/.config/nvim;

Note that this does not create a link to where ever I have my config checkout locally. It still links to a section in the /nix/store.

When I want to make changes to my neovim configuration I use a shell script also called nyx to create a symlink from ~/.config/nvim to where ever I have nyx cloned locally. I just call nyx link nvim. You can see the link command here:

nyx/bin/nyx

Lines 294 to 416 in dc87aef

function cmd_link() {
set +e
local help_msg
IFS='' read -r -d '' help_msg <<EOF
USAGE:
nyx link [OPTIONS] [target...]
Create a symlink to config file. If no application is given all will be provided.
TARGETS:
alacritty
awesome
git
nu
nvim
wezterm
OPTIONS:
-h, --help Show help message
-l, --list Show status of current links
- Green: Linked to local 'config/'
- Cyan: Linked to the nix store
- Yellow: Linked to somewhere other then /nix/store
- Red: Target points to a non linked directory
- Blue: Target does not exist on system
EOF
local -a args
while [[ $# -gt 0 ]]; do
case "$1" in
-l | --list)
do_list=true
;;
*)
args+=("$1")
;;
esac
shift
done
[ -n "$CMD_HELP" ] && {
printf "%s\n" "$help_msg"
exit 1
}
[ -n "$do_list" ] && {
for key in "${!SOURCES[@]}"; do
src="${SOURCES[$key]}"
tar="${TARGETS[$key]}"
if [ -L "$tar" ]; then
output=$(readlink "$tar")
if [[ $output == "$src" ]]; then
color="$GRN"
else
[[ $output =~ ^/nix/store/.* ]] && color="$CYN" || color="$YLO"
fi
else
if [ -d "$tar" ] || [ -f "$tar" ]; then
output="$tar"
color="$RED"
else
color="$BLU"
output="---"
fi
fi
printf "${color}%*s${RST}: %s\n" 10 "$key" " $output"
done
exit 0
}
function create_link() {
if [[ -L $1 ]]; then
if [[ "$(readlink "$1")" == "$2" ]]; then
debug "link: $1 already points to $2. Skipping"
return
else
debug "Found link: \`$1\` removing"
rm "$1"
fi
fi
if [[ -d $1 ]]; then
if [[ $1 =~ (git|nushell)$ ]]; then
rm -r "$1"
else
warn "path: \`$1\` is a directory. Skipping"
return
fi
fi
ln -s "$2" "$1"
if [[ "$(readlink "$1")" == "$2" ]]; then
debug "created link $1 to $2"
else
failure "created link $1 does not point to $2. Points to $(readlink "$1")"
fi
}
(
cd "$NYX_ROOT"
if [[ ${#args[@]} -gt 0 ]]; then
for index in "${!args[@]}"; do
key="${args[$index]}"
target="${TARGETS[$key]}"
source="${SOURCES[$key]}"
if [[ -z $target ]] || [[ -z $source ]]; then
failure "unknown target $key"
fi
create_link "$target" "$source"
done
else
for key in "${!TARGETS[@]}"; do
create_link "${TARGETS[$key]}" "${SOURCES[$key]}"
done
fi
)
set -e
}

Now you dont have to over engineer something like this but hope this has helped explain some of my current setup. Please let me know if you have any follow up questions. Happy to help, nix is something that is not easy to learn (it is getting better) so it helps if you are able to ask someone.

@WilliamHsieh
Copy link
Author

After doing some research, the solution from this issue nix-community/home-manager#2085 seems to solve my problem.
Thanks for your sharing, I'll definitely try to migrate my dotfiles to a flake in the future!

@EdenEast
Copy link
Owner

Thanks @WilliamHsieh for letting me know that mkOutOfStorageSymlink exists will look into that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants