{
"$type": "site.standard.document",
"content": {
"$type": "site.standard.content.markdown",
"text": "I've recently started exploring the [Nix](https://nixos.org/) ecosystem (I got hooked by [Vimjoyer's videos](https://www.youtube.com/@vimjoyer)) and decided to give it a try (I even installed NixOS on my laptop, but that will come in a later article).\n\n\n\n## Dotfiles\n\nFirst things first, what are dotfiles ? They are basically configuration files that are usually preceded by a `.`. or that are usually kept inside a folder called `.config` in your home directory. They are used to configure per user settings for apps that support it. For example, you could use it to change the keybindings in your i3 configuration, or pimp your neovim config or just change the color scheme for your favorite terminal. Why would you want to do that, I hear you ask? Why not, I would answer...\n\n\nOk, let's be serious for a second; if you went through the (kind of) trouble that installing Linux is (though that obviously depends on the distro you choose), then you'd probably want to customize to be more \"you\" or to better fit your needs. Here's an example: I have pretty bad eyesight and tend to prefer some specific colors for windows, text and stuff; after a while, I found out that the Catppuccin Mocha theme is not as hard on my eyes than some other (or even the Gnome or KDE default dark mode, for that matter), so I like for as many of the applciations as I daily drive to use that same theme (plus, I think it looks pretty).\n\nHere's how you would configure `rofi` to use Catppuccin Mocha:\n\n- create a `mocha.rasi` file that will contain all the theme customization rule\n- create a `config.rasi` file in `.config/rofi/` that will contain the import rule for the theme you want: `@theme \"catppuccin-mocha\"`\n You might have noticed what my problem is with these kind of configuration files; most of them are custom file formats! This might be fine if you have one or two configuration files, but it gets old really quick if you have more than that.\n\n## My Journey with Dotfiles\n\n### Step 1: files ending in dots\n\nI started playing with dotfiles when I first installed Arch (btw), and the first approach I had was to just write my files directly in the `.config` directory. That phase ended quickly once I mistakenly wiped my OS and lost all said files...\n\nHappens to the best of us, right?\n\n\n### Step 2: version control for the win\n\nOnce I got my system up and running again, I decided to version control those files (you live you learn, right?)\nHere's the problem with that approach: you either version control the whole `.config` directory, or you can create many small repos for each program because, spoiler alert, anything can write stuff in that directory.\n\n### Step 3: Stowing\n\nSo now you have a git repo containing all your dotfiles but cannot directly clone into to replace your `.config` folder, what do you do? You find out there's a tool that could fix all these problems: [GNU Stow](https://www.gnu.org/software/stow/)!\n\nThis tool allows you to create symlinks to anywhere and keep all your original files in a single folder (sound familiar?)\n\nI'd been on this step for a long time and kind of liked it, to be honest. But then I started hearing about Nix more and more often and so decided to take a look at it.\n\n### Step 4: Manage your home\n\nI'd read about Nix a while ago but had never explored it correctly. That changed when I got some time off work to tinker with some stuff. That's when I heard about [home-manager](https://github.com/nix-community/home-manager) and decided to give it a try.\n\n## Home Manager\n\nHome-manager is a tool that allows you to declare your config files and put them wherever they need to be. You can declare almost anything directly using the Nix DSL, but you can also simply copy files into their correct directory and even clone directly a repo from Github (this is the method I use to get my neovim configuration instead of rewriting it to use Nix).\n\nLet's take a look at a simple home-manager `home.nix` file:\n\n```nix\n{config, pkgs, ...}\n{\n\thome.stateVersion = \"24.05\";\n\thome.packages = [\n\t\tpkgs.fzf\n\t\tpkgs.tmuxifier\n\t];\n\thome.file = [\n\t\t\".config/waybar/mocha.css\".source= ./styles/mocha.css;\n\t];\n}\n```\n\nThis little configuration will ensure that both fzf and tmuxifier are on your user's $PATH and copies over a css file from your directory into the appropriate `.config` directory.\n\nBut this is not all we can do with home-manager (again, I highly encourage you to read the documentation); let's see how we can configure some more stuff.\nThis is how you can configure kitty, a tty:\n\n```nix\n programs.kitty = {\n enable = true;\n settings = {\n \"tab_bar_min_tabs\" = 1;\n \"tab_bar_edge\" = \"bottom\";\n \"tab_bar_style\" = \"powerline\";\n \"tab_powerline_style\" = \"slanted\";\n \"tab_title_template\"= \"{title}{' :{}:'.format(num_windows) if num_windows > 1 else ''}\";\n };\n font = {\n\tname = \"JetBrainsMono Nerd Font\";\n };\n themeFile = \"Catppuccin-Mocha\";\n };\n```\n\nThis enables kitty, sets some configuration stuff, like the topbar style title template string, but ti also sets up the font to use in the terminal and the theme the terminal will use.\n\nHow about writing configs when home-manager does not have a module for it (or you can't find it)? Well, here is how I configure tmux using home-manager:\n\n```nix\nprograms.tmux = {\n enable = true;\n plugins = with pkgs.tmuxPlugins; [\n catppuccin\n ];\n extraConfig = ''\n set -g prefix C-s\n set -g mouse on\n set-option -g status-position top\n\n set -g @plugin 'tmux-plugins/tpm'\n set -g @catppuccin_flavour 'macchiato'\n set -g @plugin 'kenos1/tmux-cht-sh'\n set -g @plugin 'jimeh/tmuxifier'\n set -g @catppuccin_window_left_separator \"\"\n set -g @catppuccin_window_right_separator \" \"\n set -g @catppuccin_window_middle_separator \" █\"\n set -g @catppuccin_window_number_position \"right\"\n\n set -g @catppuccin_window_default_fill \"number\"\n set -g @catppuccin_window_default_text \"#W\"\n\n set -g @catppuccin_window_current_fill \"number\"\n set -g @catppuccin_window_current_text \"#W\"\n\n set -g @catppuccin_status_modules_right \"directory user host session\"\n set -g @catppuccin_status_left_separator \" \"\n set -g @catppuccin_status_right_separator \"\"\n set -g @catppuccin_status_right_separator_inverse \"no\"\n set -g @catppuccin_status_fill \"icon\"\n set -g @catppuccin_status_connect_separator \"no\"\n\n set -g @catppuccin_directory_text \"#{pane_current_path}\"\n run '~/.tmux/plugins/tpm/tpm'\n '';\n };\n```\n\nThis configuration here allows you to see how you can pass \"raw\" configuration values via **extraConfig** and how to setup plugins taken directly from nixpackages.\n\nThe last example I want to show you, is how to retrieve configuration files from a github repository and copy it over to the correct `.config` folder. This goes in a bit deeper in the Nix DSL, but I think it still keeps pretty readable:\n\n```nix\nlet\n neovim_config = pkgs.fetchFromGitHub {\n owner = \"matfire\";\n repo = \"config.nvim\";\n rev = \"044cb8670307bb3195607b90229f26ffcb61d46d\";\n sha256 = \"sha256-tzWcYrRGX82kBmPc50LjQmXfNjBoT/sLNanH470NuAE=\";\n };\nin\n{\n\thome.file = {\n\t\t\".config/nvim\".source = neovim_config;\n\t};\n}\n```\n\nThis will automatically clone and verify (with the sha256 you provide) the right repository and commit, and then clone (or copy) it over to the right place.\n\n\n\n## The best of both worlds ?\n\n_Personally_, I really like doing configs like this; it lets me keep it all in one format (with the occasional exception, obviously) and be sure that whatever OS I use this on, I'll get the same programs & configs each time.\n\nBut it still requires you to learn a new language (or the basics of it, at least) and it's a functional language, which may be a blocker for some. The first experience I ever had with a functional programming language was Haskell back in university, so I can understand the animosity with this principle.\n\nStill, I believe it worthwhile if you daily drive Linux and have a lot of config files to learn and use this kind of system.",
"version": "1.0"
},
"path": "/articles/dotfiles-the-nix-way",
"publishedAt": "2024-10-30T00:00:00.000Z",
"site": "at://did:plc:dgtaz4vldacvqhvvmdvoc4ad/site.standard.publication/3mfbydibiwc7f",
"tags": [
"nix"
],
"textContent": "I've recently started exploring the Nix ecosystem (I got hooked by Vimjoyer's videos) and decided to give it a try (I even installed NixOS on my laptop, but that will come in a later article).\n\nDotfiles\n\nFirst things first, what are dotfiles ? They are basically configuration files that are usually preceded by a . or that are usually kept inside a folder called in your home directory. They are used to configure per user settings for apps that support it. For example, you could use it to change the keybindings in your i3 configuration, or pimp your neovim config or just change the color scheme for your favorite terminal. Why would you want to do that, I hear you ask? Why not, I would answer...\n\nOk, let's be serious for a second; if you went through the (kind of) trouble that installing Linux is (though that obviously depends on the distro you choose), then you'd probably want to customize to be more \"you\" or to better fit your needs. Here's an example: I have pretty bad eyesight and tend to prefer some specific colors for windows, text and stuff; after a while, I found out that the Catppuccin Mocha theme is not as hard on my eyes than some other (or even the Gnome or KDE default dark mode, for that matter), so I like for as many of the applciations as I daily drive to use that same theme (plus, I think it looks pretty).\n\nHere's how you would configure to use Catppuccin Mocha:\ncreate a file that will contain all the theme customization rule\ncreate a file in that will contain the import rule for the theme you want: \n You might have noticed what my problem is with these kind of configuration files; most of them are custom file formats! This might be fine if you have one or two configuration files, but it gets old really quick if you have more than that.\n\nMy Journey with Dotfiles\n\nStep 1: files ending in dots\n\nI started playing with dotfiles when I first installed Arch (btw), and the first approach I had was to just write my files directly in the directory. That phase ended quickly once I mistakenly wiped my OS and lost all said files...\n\nHappens to the best of us, right?\n\nStep 2: version control for the win\n\nOnce I got my system up and running again, I decided to version control those files (you live you learn, right?)\nHere's the problem with that approach: you either version control the whole directory, or you can create many small repos for each program because, spoiler alert, anything can write stuff in that directory.\n\nStep 3: Stowing\n\nSo now you have a git repo containing all your dotfiles but cannot directly clone into to replace your folder, what do you do? You find out there's a tool that could fix all these problems: GNU Stow!\n\nThis tool allows you to create symlinks to anywhere and keep all your original files in a single folder (sound familiar?)\n\nI'd been on this step for a long time and kind of liked it, to be honest. But then I started hearing about Nix more and more often and so decided to take a look at it.\n\nStep 4: Manage your home\n\nI'd read about Nix a while ago but had never explored it correctly. That changed when I got some time off work to tinker with some stuff. That's when I heard about home-manager and decided to give it a try.\n\nHome Manager\n\nHome-manager is a tool that allows you to declare your config files and put them wherever they need to be. You can declare almost anything directly using the Nix DSL, but you can also simply copy files into their correct directory and even clone directly a repo from Github (this is the method I use to get my neovim configuration instead of rewriting it to use Nix).\n\nLet's take a look at a simple home-manager file:\n\nThis little configuration will ensure that both fzf and tmuxifier are on your user's $PATH and copies over a css file from your directory into the appropriate directory.\n\nBut this is not all we can do with home-manager (again, I highly encourage you to read the documentation); let's see how we can configure some more stuff.\nThis is how you can configure kitty, a tty:\n\nThis enables kitty, sets some configuration stuff, like the topbar style title template string, but ti also sets up the font to use in the terminal and the theme the terminal will use.\n\nHow about writing configs when home-manager does not have a module for it (or you can't find it)? Well, here is how I configure tmux using home-manager:\n\nThis configuration here allows you to see how you can pass \"raw\" configuration values via extraConfig and how to setup plugins taken directly from nixpackages.\n\nThe last example I want to show you, is how to retrieve configuration files from a github repository and copy it over to the correct folder. This goes in a bit deeper in the Nix DSL, but I think it still keeps pretty readable:\n\nThis will automatically clone and verify (with the sha256 you provide) the right repository and commit, and then clone (or copy) it over to the right place.\n\nThe best of both worlds ?\n\nPersonally, I really like doing configs like this; it lets me keep it all in one format (with the occasional exception, obviously) and be sure that whatever OS I use this on, I'll get the same programs & configs each time.\n\nBut it still requires you to learn a new language (or the basics of it, at least) and it's a functional language, which may be a blocker for some. The first experience I ever had with a functional programming language was Haskell back in university, so I can understand the animosity with this principle.\n\nStill, I believe it worthwhile if you daily drive Linux and have a lot of config files to learn and use this kind of system.",
"title": "Dotfiles, the nix way",
"updatedAt": "2026-05-17T13:09:09.264Z"
}