Sharing Configuration Across Systems With Nix
In a previous blog post I’ve described how to set up and customize Vim on NixOS. One of the open questions was, whether one can use the same configuration also on OS X. Turns out that one can. Later I also found a way to share my zsh configuration across my NixOS server and my MacBook.
Vim
In the previous post I’ve already described how one can set up and customize Vim on NixOS. As I’d like to have the Vim configuration on my NixOS server and my MacBook, my new goal was to replace my local .vimrc
with the nix based Vim version I was already using on my NixOS server.
The nix configuration on the NixOS server is described in a vim.nix
file, it basically looks like this:
This file describes my whole Vim configuration, including .vimrc
and plugins. Turns out there are no further changes required to this vim.nix
file to use it on OS X instead of just my NixOS server. I just had to run nix-env -f vim.nix -i vim
on OS X. This installs Vim, configures my custom vimrc and installs the specified plugins.
Now I could remove my ~/.vimrc
and uninstall the old vim, previously managed by homebrew.
Zsh and Oh My Zsh
Next I also wanted to manage my zsh and zsh configuration with nix.
Installing zsh is pretty easy: nix-env -i zsh
. Then I added /Users/marc/.nix-profile/bin/zsh
to /etc/shells
. Now I could change the default shell to the nix managed shell by running chsh -s /Users/marc/.nix-profile/bin/zsh
.
Like with Vim I’d also like to have a single .zshrc
for OS X and my NixOS server. First I created a zsh-config.nix
containing my zsh configuration:
As you can see, this zsh-config.nix
has a dependency to the oh-my-zsh
package. The ${pkgs.oh-my-zsh}
will be resolved to the path where oh-my-zsh
is installed (somewhere in /nix/store
). As you can see there are also some OS specific things, e.g. I use a different theme on OS X than on the NixOS server.
To install this zsh-config.nix
, I just had to run nix-env -f zsh-config.nix -i
. Then I just had to symlink this configuration to ~/.zshrc
by running ln -s "$(nix-env -q zshrc --out-path --no-name)" "~/.zshrc"
.
On NixOS I use this zsh-config.nix
like this:
It’s pretty awesome to have the same shell configuration on all your hosts, and nix makes it pretty easy to manage.
Thanks for reading :) Follow me on twitter if you’re interested in more of this stuff!
Hey! I’m Marc, founder of digitally induced. I love playing with exciting new technology. Feel free to contact me.
If you liked this post feel free to subscribe to my mailing list.