Published on

How I manage my dotfiles?

Authors
  • avatar
    Name
    Shibi Suriya
    Twitter

I will be explaining my dotfiles setup in this blog post, if you are someone who doesn't know what dotfiles are, why would you want to manage them?, etc. read my simple tutorial on managing dotfiles.

I own two computers, a PC that has Ubuntu and Windows 11 installed (dual boot) and a M1 Macbook pro that I use for office work. I am a software engineer by profession, my work mostly revolves around backend systems, databases, infrastructure, virtual machine, Docker containers, etc. I prefer Ubuntu or macOS for software development & only boot into windows for play computer games, I haven't ported my dotfiles to windows for this reason. My dotfiles work fine in Ubuntu & macOS.

This blog post also serves as a README for my publically maintained dotfiles repo, this is intentional because it forces me to keep this blog post neat & updated so that I can refer it while setting up a new computer.

macOS

  1. I install nix (the package manager) for macOS, I do a multi user installation.

  2. I clone my dotfiles repo,

nix-shell -p git --run "git clone --recurse-submodules https://github.com/shibisuriya/.dotfiles ~/.dotfiles"
  1. I Install nix-darwin
nix run nix-darwin --extra-experimental-features 'nix-command flakes' -- switch --flake ~/.dotfiles/nix-darwin#shibi

Note: nix-darwin in the above command refers to a flake input.

Ones run, I will have access to the darwin-rebuild command.

darwin-rebuild switch --flake ~/.dotfiles/nix-darwin#shibi
  1. Install 'Apple Command Line Tools (CLT)'

Neovim Mason uses Apple CLT to build some language servers that I use from source code.

xcode-select install

CLT is a subset of Xcode, the command above will not install complete Xcode.

Note: This step can't be automated using nix and must be performed manually.

  1. Install TPM - Tmux Package Manager,
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Note: This step can be automated using nix but I haven't automated it yet.

  1. Symlink the dotfiles to their target locations using GNU Stow,
cd ~/.dotfiles
./stow.zsh # A shell script, uses GNU Stow under the hood.
  1. Update the .gitconfig file (this step needs to be automated, I am performing this step manually for now because I don't want to store my email, full name, etc. in the .gitconfig file publically).

  2. I manually install non-free software like Chrome, Obsidian, Docker desktop, etc. I maintain a list of non-free software that I need in this blog post so that I can refer it while setting up a new computer.

  3. I install homebrew (I use it to install some programs).

Formatting .nix files

Code formatters to format .nix files such as 'alejandra', 'nixfmt', etc. for Neovim are not supported in Apple Silicon, use the nix fmt command instead,

cd ~/.dotfiles/nix-darwin
nix fmt

Testing & improving the installation process

Testing & improving the installation process of the dotfiles on the host itself is not a good idea!

  1. Dotfiles might have already been installed on the host.

  2. The host will be left in an undesirable state (partially installed applications, dotfiles that are not symlinked yet, etc.) if the installation process fails for some reason.

For these reasons I prefer to test the installation process inside a Docker container or virtual machine (preferably "fresh installs").

macOS (using UTM)

  1. Download and install UTM, a super simple app for creating and managing virtual machines on macOS; it is a wrapper around QEMU.

  2. Create a macOS VM in UTM & set it up (create users, select time zone, language, keyboard layout, etc.). Do not use this VM, instead create a clone of this VM for testing & improving the installation process. If something fails, delete the clone VM & create another clone... This way you can start testing the installation process as soon as the VM boots up instead of creating users, selecting time zones, etc. again & again.

  3. Execute these steps inside the VM.

  4. Fix if something fails & repeat the steps inside a new VM.

Ubuntu (using Docker container)

I prefer Docker containers for testing the installation process of my dotfiles in Ubuntu because they are light weight (compared to QEMU VMs) and boot up quickly.

Currently I am using Ansible playbook to install programs in Ubuntu, I will migrate to nix package manager in the future.

Dev containers (for testing & improving the installation process)

To create a Ubuntu based docker image that has Ansible and Nix preinstalled,

docker build --target dev -t dotfiles:dev .

Spin up a container based on this image and volume mount/copy your dotfiles into it.

docker run -it --rm -v .:/root/.dotfiles dotfiles:dev

Run the ansible playbook,

ansible-playbook /root/.dotfiles/local.yml

Prod containers (sandbox)

To build a Ubuntu based Docker image that has most of the programs I need & my dotfiles installed,

docker build --no-cache --target prod -t dotfiles .

Since this image has my dotfiles installed & all of the programs I absolutely need, I use it as a sandbox to tinker/test/install/learn new things without worrying about mistakes that can affect my host.

I can quickly spin up a container of this image and copy or volume mount directories/files from the host,

docker run -it --rm -v .:/root/directory_1 dotfiles

I can even publish this image to Docker Hub so that I can pull and run a container based on it on any machine having Docker runtime, for example I can spin up a container on my coworker's machine for quickly debugging something, I don't have to install anything on their machine or modify their settings, the image has most of things that I need for development work.

Non-free software I need

  • Chrome
  • Obsidian
  • Docker desktop

Eternal learner/explorer

The way I manage my dotfiles currently might not be perfect... I am aware that the tools and techniques that I currently use are not the absolute best, and there are better alternatives. My current setup works for me, even if it is imperfect. I am an eternal learner, I will try hard to keep this blog post updated or rewrite it if required as I explore and adopt new tools and techniques since this blog post also serves as a README for my publically maintained dotfiles repository and as a personal reference. Feel free to share suggestions, or let me know if you’d want me to try something. Thanks for reading my blog post.