mirror of
https://github.com/davegallant/davegallant.github.io.git
synced 2025-08-06 00:33:39 +00:00
119 lines
41 KiB
HTML
119 lines
41 KiB
HTML
<!doctype html><html lang=en data-theme=light><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=preload as=font type=font/woff2 href=/fonts/roboto-slab-latin-400.woff2 crossorigin=anonymous><link rel=preload as=font type=font/woff2 href=/fonts/roboto-slab-latin-700.woff2 crossorigin=anonymous><link rel=preload as=font type=font/woff2 href=/fonts/fira-code-latin-300.woff2 crossorigin=anonymous><link rel=preload as=font type=font/woff2 href=/fonts/fira-code-latin-400.woff2 crossorigin=anonymous><link rel=preload as=font type=font/woff2 href=/fonts/fira-code-latin-700.woff2 crossorigin=anonymous><meta name=robots content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"><title>Why I threw out my dotfiles</title>
|
|
<meta name=description content="Over the years I have collected a number of dotfiles that I have shared across both Linux and macOS machines (~/.zshrc, ~/.config/git/config, ~/.config/tmux/tmux.conf, etc). I have tried several different ways to manage them, including bare git repos and utilities such as GNU Stow. These solutions work well enough, but I have since found what I would consider a much better solution for organizing user configuration: home-manager.
|
|
"><link rel=canonical href=https://davegallant.ca/blog/2021/09/08/why-i-threw-out-my-dotfiles/><meta name=twitter:card content="summary"><meta name=twitter:title content="Why I threw out my dotfiles"><meta name=twitter:description content="Over the years I have collected a number of dotfiles that I have shared across both Linux and macOS machines (~/.zshrc, ~/.config/git/config, ~/.config/tmux/tmux.conf, etc). I have tried several different ways to manage them, including bare git repos and utilities such as GNU Stow. These solutions work well enough, but I have since found what I would consider a much better solution for organizing user configuration: home-manager."><meta property="og:title" content="Why I threw out my dotfiles"><meta property="og:description" content="Over the years I have collected a number of dotfiles that I have shared across both Linux and macOS machines (~/.zshrc, ~/.config/git/config, ~/.config/tmux/tmux.conf, etc). I have tried several different ways to manage them, including bare git repos and utilities such as GNU Stow. These solutions work well enough, but I have since found what I would consider a much better solution for organizing user configuration: home-manager."><meta property="og:type" content="article"><meta property="og:url" content="https://davegallant.ca/blog/2021/09/08/why-i-threw-out-my-dotfiles/"><meta property="article:section" content="post"><meta property="article:published_time" content="2021-09-08T00:42:33-04:00"><meta property="article:modified_time" content="2021-09-08T00:42:33-04:00"><meta itemprop=name content="Why I threw out my dotfiles"><meta itemprop=description content="Over the years I have collected a number of dotfiles that I have shared across both Linux and macOS machines (~/.zshrc, ~/.config/git/config, ~/.config/tmux/tmux.conf, etc). I have tried several different ways to manage them, including bare git repos and utilities such as GNU Stow. These solutions work well enough, but I have since found what I would consider a much better solution for organizing user configuration: home-manager."><meta itemprop=datePublished content="2021-09-08T00:42:33-04:00"><meta itemprop=dateModified content="2021-09-08T00:42:33-04:00"><meta itemprop=wordCount content="1056"><meta itemprop=keywords content="nix,dotfiles,home-manager,"><style>@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:100;src:local("Roboto Slab Thin "),local("Roboto Slab-Thin"),url(/fonts/roboto-slab-latin-100.woff2) format("woff2"),url(/fonts/roboto-slab-latin-100.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:200;src:local("Roboto Slab Extra Light "),local("Roboto Slab-Extra Light"),url(/fonts/roboto-slab-latin-200.woff2) format("woff2"),url(/fonts/roboto-slab-latin-200.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:300;src:local("Roboto Slab Light "),local("Roboto Slab-Light"),url(/fonts/roboto-slab-latin-300.woff2) format("woff2"),url(/fonts/roboto-slab-latin-300.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:400;src:local("Roboto Slab Regular "),local("Roboto Slab-Regular"),url(/fonts/roboto-slab-latin-400.woff2) format("woff2"),url(/fonts/roboto-slab-latin-400.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:500;src:local("Roboto Slab Medium "),local("Roboto Slab-Medium"),url(/fonts/roboto-slab-latin-500.woff2) format("woff2"),url(/fonts/roboto-slab-latin-500.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:600;src:local("Roboto Slab SemiBold "),local("Roboto Slab-SemiBold"),url(/fonts/roboto-slab-latin-600.woff2) format("woff2"),url(/fonts/roboto-slab-latin-600.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:700;src:local("Roboto Slab Bold "),local("Roboto Slab-Bold"),url(/fonts/roboto-slab-latin-700.woff2) format("woff2"),url(/fonts/roboto-slab-latin-700.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:800;src:local("Roboto Slab ExtraBold "),local("Roboto Slab-ExtraBold"),url(/fonts/roboto-slab-latin-800.woff2) format("woff2"),url(/fonts/roboto-slab-latin-800.woff) format("woff")}@font-face{font-display:swap;font-family:Roboto Slab;font-style:normal;font-weight:900;src:local("Roboto Slab Black "),local("Roboto Slab-Black"),url(/fonts/roboto-slab-latin-900.woff2) format("woff2"),url(/fonts/roboto-slab-latin-900.woff) format("woff")}@font-face{font-display:swap;font-family:Fira Code;font-style:normal;font-weight:300;src:local("Fira Code Light "),local("Fira Code-Light"),url(/fonts/fira-code-latin-300.woff2) format("woff2"),url(/fonts/fira-code-latin-300.woff) format("woff")}@font-face{font-display:swap;font-family:Fira Code;font-style:normal;font-weight:400;src:local("Fira Code Regular "),local("Fira Code-Regular"),url(/fonts/fira-code-latin-400.woff2) format("woff2"),url(/fonts/fira-code-latin-400.woff) format("woff")}@font-face{font-display:swap;font-family:Fira Code;font-style:normal;font-weight:500;src:local("Fira Code Medium "),local("Fira Code-Medium"),url(/fonts/fira-code-latin-500.woff2) format("woff2"),url(/fonts/fira-code-latin-500.woff) format("woff")}@font-face{font-display:swap;font-family:Fira Code;font-style:normal;font-weight:600;src:local("Fira Code SemiBold "),local("Fira Code-SemiBold"),url(/fonts/fira-code-latin-600.woff2) format("woff2"),url(/fonts/fira-code-latin-600.woff) format("woff")}@font-face{font-display:swap;font-family:Fira Code;font-style:normal;font-weight:700;src:local("Fira Code Bold "),local("Fira Code-Bold"),url(/fonts/fira-code-latin-700.woff2) format("woff2"),url(/fonts/fira-code-latin-700.woff) format("woff")}
|
|
|
|
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;-webkit-text-decoration:underline;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}[hidden],template{display:none}
|
|
|
|
/*! CC BY-SA 3.0 License | https://stackoverflow.com/a/36118384/1154965 */@keyframes blink{50%{opacity:0}to{opacity:1}}
|
|
|
|
/*! MIT License | github.com/schnerring/hugo-theme-gruvbox */:root[data-theme=light]{--bg:var(--bg0);--bg0:#fbf1c7;--bg0_h:#f9f5d7;--bg0_s:#f2e5bc;--bg1:#ebdbb2;--bg2:#d5c4a1;--bg3:#bdae93;--bg4:#a89984;--fg:var(--fg1);--fg0:#282828;--fg1:#3c3836;--fg2:#504945;--fg3:#665c54;--fg4:#7c6f64;--gray1:var(--fg4);--gray2:#928374;--red1:#cc241d;--red2:#9d0006;--green1:#98971a;--green2:#797403;--yellow1:#d79921;--yellow2:#b57614;--blue1:#458588;--blue2:#076678;--purple1:#b16286;--purple2:#8f3f71;--aqua1:#689d6a;--aqua2:#427b58;--orange1:#d65d0e;--orange2:#af3a03}:root[data-theme=dark]{--bg:var(--bg0);--bg0:#282828;--bg0_h:#1d2021;--bg0_s:#32302f;--bg1:#3c3836;--bg2:#504945;--bg3:#665c54;--bg4:#7c6f64;--fg:var(--fg1);--fg0:#fbf1c7;--fg1:#ebdbb2;--fg2:#d5c4a1;--fg3:#bdae93;--fg4:#a89984;--gray1:var(--fg4);--gray2:#928374;--red1:#cc241d;--red2:#fb4934;--green1:#98971a;--green2:#b8bb26;--yellow1:#d79921;--yellow2:#fabd2f;--blue1:#458588;--blue2:#83a598;--purple1:#b16286;--purple2:#d3869b;--aqua1:#689d6a;--aqua2:#8ec07c;--orange1:#d65d0e;--orange2:#fe8019}:root{--primary:var(--blue1);--primary-alt:var(--blue2);--font-monospace:"Fira Code","Lucida Console",Monaco,monospace;--font-sans-serif:Verdana,Helvetica,sans-serif;--font-serif:"Roboto Slab",Georgia,serif}::-moz-selection{background:var(--bg4);color:var(--fg0)}::selection{background:var(--bg4);color:var(--fg0)}.search{display:flex;grid-area:search;margin:0 1rem}#search__text{background:var(--bg2);border:1px solid var(--bg2);border-radius:.2rem;caret-color:var(--fg);color:var(--fg);outline:none;padding:0 .5rem;width:100%}#search__text:hover{border-color:var(--bg3)}#search__text:focus{border-color:var(--bg4)}#search__text::-moz-placeholder{color:var(--fg3)}#search__text::placeholder{color:var(--fg3)}#search__text[type=search]::-webkit-search-cancel-button{-webkit-appearance:none;appearance:none}#search__suggestions{background:var(--bg);border-radius:.2rem;box-shadow:0 .5rem 1rem var(--bg1);font-family:Roboto Slab,Georgia,serif;font-family:var(--font-serif);left:0;margin-top:2rem;position:absolute;width:95vw;z-index:1000}@media (min-width:768px){.search{position:relative}#search__suggestions{width:60vw}}.search__suggestions--hidden{display:none}.search__suggestion-item{border-bottom:1px dashed var(--bg2);display:grid;grid-template-columns:1fr 2fr}.search__suggestion-item:focus,.search__suggestion-item:focus-visible,.search__suggestion-item:hover{background:var(--bg1);cursor:pointer;outline:none}.search__suggestion-item:last-child{border:none}.search__suggestion-description,.search__suggestion-title{margin:1rem 0;padding:0 1rem}.search__suggestion-title{font-weight:700}.search__suggestion-description{border-left:1px solid var(--bg2)}.search__no-results{padding:.75rem}</style><link rel=preload href="/css/non-critical.10bf652274d1149570c93631c19d9e068c317875079471d2fda62260a2d40136a468ceb49a9b091ce868ae2db84cbfdb5e4eab1b465fb9710247eb86f36275a0.css" as=style onload='this.onload=null,this.rel="stylesheet"' integrity="sha512-EL9lInTRFJVwyTYxwZ2eBowxeHUHlHHS/aYiYKLUATakaM60mpsJHOhori24TL/bXk6rG0ZfuXECR+uG82J1oA=="><link id=prism-dark rel=preload href=/prism-themes/prism-gruvbox-dark.min.54aecc64074623a4f9898544dcbdab9e804f1560ef0b38f4cf8e10fcaaf72264e798cb407c601aca6ecd833ec4eb93d66535581f18d45ba202cf848b70dbc332.css as=style onload='this.onload=null,this.rel="stylesheet"' integrity="sha512-VK7MZAdGI6T5iYVE3L2rnoBPFWDvCzj0z44Q/Kr3ImTnmMtAfGAaym7Ngz7E65PWZTVYHxjUW6ICz4SLcNvDMg==" disabled><link id=prism-light rel=preload href=/prism-themes/prism-gruvbox-light.min.42a221741efe997fcc94187c39d63c555560678789ac9ca856c74a5f0ddb2aa6c50d38b2ffbecc7a99038cbbd2efa99746e862267f781c559e0cfec10b88a5fc.css as=style onload='this.onload=null,this.rel="stylesheet"' integrity="sha512-QqIhdB7+mX/MlBh8OdY8VVVgZ4eJrJyoVsdKXw3bKqbFDTiy/77MepkDjLvS76mXRuhiJn94HFWeDP7BC4il/A=="><noscript><link rel=stylesheet href=/prism-themes/prism-gruvbox-light.min.42a221741efe997fcc94187c39d63c555560678789ac9ca856c74a5f0ddb2aa6c50d38b2ffbecc7a99038cbbd2efa99746e862267f781c559e0cfec10b88a5fc.css integrity="sha512-QqIhdB7+mX/MlBh8OdY8VVVgZ4eJrJyoVsdKXw3bKqbFDTiy/77MepkDjLvS76mXRuhiJn94HFWeDP7BC4il/A=="><link rel=stylesheet href="/css/non-critical.10bf652274d1149570c93631c19d9e068c317875079471d2fda62260a2d40136a468ceb49a9b091ce868ae2db84cbfdb5e4eab1b465fb9710247eb86f36275a0.css" integrity="sha512-EL9lInTRFJVwyTYxwZ2eBowxeHUHlHHS/aYiYKLUATakaM60mpsJHOhori24TL/bXk6rG0ZfuXECR+uG82J1oA=="></noscript><script>(()=>{function n(){if(localStorage&&localStorage.getItem("theme"))return localStorage.getItem("theme");if(window.matchMedia)return window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function e(e){document.documentElement.setAttribute("data-theme",e);let t=document.getElementById("prism-dark"),n=document.getElementById("prism-light");t.toggleAttribute("disabled",e==="light"),n.toggleAttribute("disabled",e==="dark"),localStorage.setItem("theme",e)}var t=n();t&&e(t);function s(t){let n=t.currentTarget.classList.contains("light--hidden")?"light":"dark";e(n)}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".theme__toggle").forEach(e=>{e.addEventListener("click",s)})})})()</script><link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png><link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png><link rel=manifest href=/site.webmanifest><link rel=mask-icon href=/safari-pinned-tab.svg color=#282828><meta name=msapplication-TileColor content="#282828"><meta name=theme-color content="#282828"></head><body><div class=layout><header><a class=logo href=/><div class=logo__text>davegallant.ca</div><div class=logo__chevron>></div><div class=logo__cursor>█</div></a><div class=search><input id=search__text type=search placeholder=Search... aria-label=Search autocomplete=off><div id=search__suggestions class=search__suggestions--hidden></div></div><nav id=menu><ul class=menu--horizontal><li class=menu__item><a href=/index.xml>RSS</a></li></ul><div class=menu__burger><input class=menu__item type=checkbox aria-label="Open main menu"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-menu-2" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentcolor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 6h16"/><path d="M4 12h16"/><path d="M4 18h16"/></svg><ul class=menu--vertical><li><a class=menu__item href=/index.xml>RSS</a></li></ul></div></nav><button class="theme__toggle light--hidden" aria-label="Toggle light mode">
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sun" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentcolor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 12m-4 0a4 4 0 108 0 4 4 0 10-8 0"/><path d="M3 12h1m8-9v1m8 8h1m-9 8v1M5.6 5.6l.7.7m12.1-.7-.7.7m0 11.4.7.7m-12.1-.7-.7.7"/></svg></button>
|
|
<button class="theme__toggle dark--hidden" aria-label="Toggle dark mode"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-moon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentcolor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 3c.132.0.263.0.393.0a7.5 7.5.0 007.92 12.446A9 9 0 1112 2.992z"/></svg></button></header><main><div class=content><article class=post><div class=post-header><h1>Why I threw out my dotfiles</h1><div class=post-meta><span>2021-09-08</span><div class=post-tags><a class=post-tag href=https://davegallant.ca/tags/nix>nix</a><a class=post-tag href=https://davegallant.ca/tags/dotfiles>dotfiles</a><a class=post-tag href=https://davegallant.ca/tags/home-manager>home‑manager</a></div></div></div><div class=post-content><p>Over the years I have collected a number of dotfiles that I have shared across both Linux and macOS machines (<code>~/.zshrc</code>, <code>~/.config/git/config</code>, <code>~/.config/tmux/tmux.conf</code>, etc). I have tried several different ways to manage them, including <a href=https://www.atlassian.com/git/tutorials/dotfiles class=link--external target=_blank rel=noreferrer>bare git repos</a> and utilities such as <a href=https://www.gnu.org/software/stow/ class=link--external target=_blank rel=noreferrer>GNU Stow</a>. These solutions work well enough, but I have since found what I would consider a much better solution for organizing user configuration: <a href=https://github.com/nix-community/home-manager class=link--external target=_blank rel=noreferrer>home-manager</a>.</p><h2 id=what-is-home-manager>What is home-manager?<a href=#what-is-home-manager class=post-heading__anchor aria-hidden=true>#</a></h2><p>Before understanding home-manager, it is worth briefly discussing what nix is. <a href=https://nixos.org/ class=link--external target=_blank rel=noreferrer>nix</a> is a package manager that originally spawned from a <a href=https://edolstra.github.io/pubs/phd-thesis.pdf class=link--external target=_blank rel=noreferrer>PhD thesis</a>. Unlike other package managers, it uses symbolic links to keep track of the currently installed packages, keeping around the old ones in case you may want to rollback.</p><p>For example, I have used nix to install the package <a href="https://search.nixos.org/packages?channel=unstable&show=bind&from=0&size=50&sort=relevance&type=packages&query=bind" class=link--external target=_blank rel=noreferrer>bind</a> which includes <code>dig</code>. You can see that it is available on multiple platforms. The absolute path of <code>dig</code> can be found by running:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ ls -lh <span style=color:#66d9ef>$(</span>which dig<span style=color:#66d9ef>)</span>
|
|
</span></span><span style=display:flex><span>lrwxr-xr-x 73 root 31 Dec 1969 /run/current-system/sw/bin/dig -> /nix/store/0r4qdyprljd3dki57jn6c6a8dh2rbg9g-bind-9.16.16-dnsutils/bin/dig
|
|
</span></span></code></pre></div><p>Notice that there is a hash included in the file path? This is a nix store path and is computed by the nix package manager. This <a href=https://nixos.org/guides/nix-pills/nix-store-paths.html class=link--external target=_blank rel=noreferrer>nix pill</a> does a good job explaining how this hash is computed. All of the nix pills are worth a read, if you are interested in learning more about nix itself. However, using home-manager does not require extensive knowledge of nix.</p><p>Part of the nix ecosystem includes <a href=https://github.com/NixOS/nixpkgs class=link--external target=_blank rel=noreferrer>nixpkgs</a>. Many popular tools can be found already packaged in this repository. As you can see with these <a href=https://repology.org/repositories/statistics/total class=link--external target=_blank rel=noreferrer>stats</a>, there is a large number of existing packages that are being maintained by the community. Contributing a new package is easy, and anyone can do it!</p><p>home-manager leverages the nix package manager (and nixpkgs), as well the nix language so that you can declaratively define your system configuration. I store my <a href=https://github.com/davegallant/nix-config class=link--external target=_blank rel=noreferrer>nix-config</a> in git so that I can keep track of my packages and configurations, and retain a clean and informative git commit history so that I can understand what changed and why.</p><h2 id=setting-up-home-manager>Setting up home-manager<a href=#setting-up-home-manager class=post-heading__anchor aria-hidden=true>#</a></h2><blockquote><p>⚠️ If you run this on your main machine, make sure you backup your configuration files first. home-manager is pretty good about not overwriting existing configuration, but it is better to have a backup! Alternatively, you could test this out on a VM or cloud instance.</p></blockquote><p>The first thing you should do is <a href=https://nixos.org/guides/install-nix.html class=link--external target=_blank rel=noreferrer>install nix</a>:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>curl -L https://nixos.org/nix/install | sh
|
|
</span></span></code></pre></div><p>It’s generally not a good idea to curl and execute files from the internet (without verifying integrity), so you might want to download the install script first and take a look before executing it!</p><p>Open up a new shell in your terminal and running <code>nix</code> <em>should</em> work. If not, run <code>. ~/.nix-profile/etc/profile.d/nix.sh</code></p><p>Now, <a href=https://github.com/nix-community/home-manager#installation class=link--external target=_blank rel=noreferrer>install home-manager</a>:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
</span></span><span style=display:flex><span>nix-channel --update
|
|
</span></span><span style=display:flex><span>nix-shell <span style=color:#e6db74>'<home-manager>'</span> -A install
|
|
</span></span></code></pre></div><p>You should see a wave of <code>/nix/store/*</code> paths being displayed on your screen.</p><p>Now, to start off with a basic configuration, open up <code>~/.config/nixpkgs/home.nix</code> in the editor of your choice and paste this in (you will want to change <code>userName</code> and <code>homeDirectory</code>):</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-nix data-lang=nix><span style=display:flex><span>{ config<span style=color:#f92672>,</span> pkgs<span style=color:#f92672>,</span> <span style=color:#f92672>...</span> }:
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span>{
|
|
</span></span><span style=display:flex><span> programs<span style=color:#f92672>.</span>home-manager<span style=color:#f92672>.</span>enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> home <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> username <span style=color:#f92672>=</span> <span style=color:#e6db74>"dave"</span>;
|
|
</span></span><span style=display:flex><span> homeDirectory <span style=color:#f92672>=</span> <span style=color:#e6db74>"/home/dave"</span>;
|
|
</span></span><span style=display:flex><span> stateVersion <span style=color:#f92672>=</span> <span style=color:#e6db74>"21.11"</span>;
|
|
</span></span><span style=display:flex><span> packages <span style=color:#f92672>=</span> <span style=color:#66d9ef>with</span> pkgs; [
|
|
</span></span><span style=display:flex><span> bind
|
|
</span></span><span style=display:flex><span> exa
|
|
</span></span><span style=display:flex><span> fd
|
|
</span></span><span style=display:flex><span> ripgrep
|
|
</span></span><span style=display:flex><span> ];
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> programs <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> git <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> aliases <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> aa <span style=color:#f92672>=</span> <span style=color:#e6db74>"add -A ."</span>;
|
|
</span></span><span style=display:flex><span> br <span style=color:#f92672>=</span> <span style=color:#e6db74>"branch"</span>;
|
|
</span></span><span style=display:flex><span> c <span style=color:#f92672>=</span> <span style=color:#e6db74>"commit -S"</span>;
|
|
</span></span><span style=display:flex><span> ca <span style=color:#f92672>=</span> <span style=color:#e6db74>"commit -S --amend"</span>;
|
|
</span></span><span style=display:flex><span> cb <span style=color:#f92672>=</span> <span style=color:#e6db74>"checkout -b"</span>;
|
|
</span></span><span style=display:flex><span> co <span style=color:#f92672>=</span> <span style=color:#e6db74>"checkout"</span>;
|
|
</span></span><span style=display:flex><span> d <span style=color:#f92672>=</span> <span style=color:#e6db74>"diff"</span>;
|
|
</span></span><span style=display:flex><span> l <span style=color:#f92672>=</span>
|
|
</span></span><span style=display:flex><span> <span style=color:#e6db74>"log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"</span>;
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> delta <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> options <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> features <span style=color:#f92672>=</span> <span style=color:#e6db74>"line-numbers decorations"</span>;
|
|
</span></span><span style=display:flex><span> whitespace-error-style <span style=color:#f92672>=</span> <span style=color:#e6db74>"22 reverse"</span>;
|
|
</span></span><span style=display:flex><span> plus-style <span style=color:#f92672>=</span> <span style=color:#e6db74>"green bold ul '#198214'"</span>;
|
|
</span></span><span style=display:flex><span> decorations <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> commit-decoration-style <span style=color:#f92672>=</span> <span style=color:#e6db74>"bold yellow box ul"</span>;
|
|
</span></span><span style=display:flex><span> file-style <span style=color:#f92672>=</span> <span style=color:#e6db74>"bold yellow ul"</span>;
|
|
</span></span><span style=display:flex><span> file-decoration-style <span style=color:#f92672>=</span> <span style=color:#e6db74>"none"</span>;
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> extraConfig <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> push <span style=color:#f92672>=</span> { default <span style=color:#f92672>=</span> <span style=color:#e6db74>"current"</span>; };
|
|
</span></span><span style=display:flex><span> pull <span style=color:#f92672>=</span> { rebase <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>; };
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> starship <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> enableZshIntegration <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> settings <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> add_newline <span style=color:#f92672>=</span> <span style=color:#66d9ef>false</span>;
|
|
</span></span><span style=display:flex><span> scan_timeout <span style=color:#f92672>=</span> <span style=color:#ae81ff>10</span>;
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> zsh <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> enableAutosuggestions <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> enableSyntaxHighlighting <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> history<span style=color:#f92672>.</span>size <span style=color:#f92672>=</span> <span style=color:#ae81ff>1000000</span>;
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> localVariables <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> CASE_SENSITIVE <span style=color:#f92672>=</span> <span style=color:#e6db74>"true"</span>;
|
|
</span></span><span style=display:flex><span> DISABLE_UNTRACKED_FILES_DIRTY <span style=color:#f92672>=</span> <span style=color:#e6db74>"true"</span>;
|
|
</span></span><span style=display:flex><span> RPROMPT <span style=color:#f92672>=</span> <span style=color:#e6db74>""</span>; <span style=color:#75715e># override because macOS defaults to filepath</span>
|
|
</span></span><span style=display:flex><span> ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE <span style=color:#f92672>=</span> <span style=color:#e6db74>"fg=#838383,underline"</span>;
|
|
</span></span><span style=display:flex><span> ZSH_DISABLE_COMPFIX <span style=color:#f92672>=</span> <span style=color:#e6db74>"true"</span>;
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> initExtra <span style=color:#f92672>=</span> <span style=color:#e6db74>''
|
|
</span></span></span><span style=display:flex><span><span style=color:#e6db74> export PAGER=less
|
|
</span></span></span><span style=display:flex><span><span style=color:#e6db74> ''</span>;
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> shellAliases <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> <span style=color:#e6db74>".."</span> <span style=color:#f92672>=</span> <span style=color:#e6db74>"cd .."</span>;
|
|
</span></span><span style=display:flex><span> grep <span style=color:#f92672>=</span> <span style=color:#e6db74>"rg --smart-case"</span>;
|
|
</span></span><span style=display:flex><span> ls <span style=color:#f92672>=</span> <span style=color:#e6db74>"exa -la --git"</span>;
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> <span style=color:#e6db74>"oh-my-zsh"</span> <span style=color:#f92672>=</span> {
|
|
</span></span><span style=display:flex><span> enable <span style=color:#f92672>=</span> <span style=color:#66d9ef>true</span>;
|
|
</span></span><span style=display:flex><span> plugins <span style=color:#f92672>=</span> [
|
|
</span></span><span style=display:flex><span> <span style=color:#e6db74>"gitfast"</span>
|
|
</span></span><span style=display:flex><span> <span style=color:#e6db74>"last-working-dir"</span>
|
|
</span></span><span style=display:flex><span> ];
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>
|
|
</span></span><span style=display:flex><span> };
|
|
</span></span><span style=display:flex><span>}
|
|
</span></span></code></pre></div><p>Save the file and run:</p><pre tabindex=0><code>home-manager switch
|
|
</code></pre><p>You should see another wave of <code>/nix/store/*</code> paths. The new configuration should now be active.</p><p>If you run <code>zsh</code>, you should see that you have <a href=https://starship.rs/ class=link--external target=_blank rel=noreferrer>starship</a> and access to several other utils such as <code>rg</code>, <code>fd</code>, and <code>exa</code>.</p><p>This basic configuration above is also defining your <code>~/.config/git/config</code> and <code>.zshrc</code>. If you already have either of these files, home-manager will complain about them already existing.</p><p>If you run <code>cat ~/.zshrc</code>, you will see the way these configuration files are generated.</p><p>You can extend this configuration for programs such as (neo)vim, emacs, alacritty, ssh, etc. To see other programs, take a look at <a href=https://github.com/nix-community/home-manager/tree/master/modules/programs class=link--external target=_blank rel=noreferrer>home-manager/modules/programs</a>.</p><h2 id=gateway-to-nix>Gateway To Nix<a href=#gateway-to-nix class=post-heading__anchor aria-hidden=true>#</a></h2><p>In ways, home-manager can be seen as a gateway to the nix ecosystem. If you have enjoyed the way you can declare user configuration with home-manager, you may be interested in expanding your configuration to include other system dependencies and configuration. For example, in Linux you can define your entire system’s configuration (including the kernel, kernel modules, networking, filesystems, etc) in nix. For macOS, there is <a href=https://github.com/LnL7/nix-darwin class=link--external target=_blank rel=noreferrer>nix-darwin</a> that includes nix modules for configuring launchd, dock, and other preferences and services. You may also want to check out <a href=https://nixos.wiki/wiki/Flakes class=link--external target=_blank rel=noreferrer>Nix Flakes</a>: a more recent feature that allows you declare dependencies, and have them automatically pinned and hashed in <code>flake.lock</code>, similar to that of many modern package managers.</p><h2 id=wrapping-up>Wrapping up<a href=#wrapping-up class=post-heading__anchor aria-hidden=true>#</a></h2><p>The title of this post is slightly misleading, since it’s possible to retain some of your dotfiles and have them intermingle with home-manager by including them alongside nix. The idea of defining user configuration using nix can provide a clean way to maintain your configuration, and allow it to be portable across platforms. Is it worth the effort to migrate away from shell scripts and dotfiles? I’d say so.</p></div><script type=text/javascript src=https://storage.ko-fi.com/cdn/widget/Widget_2.js></script><script type=text/javascript>kofiwidget2.init("Buy me a coffee","#458588","F1F2S4LWI"),kofiwidget2.draw()</script><section id=comments class=comments><div class='container sep-before'><div class=comments><script>var getTheme=window.localStorage&&window.localStorage.getItem("theme-storage"),getTheme=getTheme??"light";let theme=getTheme==="dark"?"github-dark":"github-light",s=document.createElement("script");s.src="https://utteranc.es/client.js",s.setAttribute("repo","davegallant/davegallant.github.io"),s.setAttribute("issue-term","pathname"),s.setAttribute("theme",theme),s.setAttribute("crossorigin","anonymous"),s.setAttribute("async",""),document.querySelector("div.comments").innerHTML="",document.querySelector("div.comments").appendChild(s)</script></div></div></section></article></div><div class=sidebar><aside class=bio><div class="jr__item jr-basics__item"><div class=jr-basics__name>Dave Gallant</div><div class=jr-basics__label>Software Engineer</div><div class=jr-basics__email>me@davegallant.ca</div><div class=jr-basics__summary>I'm a software tinkerer passionate about infra, security and self-hosting 👋.</div><hr><div class="jr-basics__profile jr-basics__profile--row"><a href=https://linktr.ee/davegallant target=_blank rel="noreferrer me"><div class=jr-basics__profile-item><div class=jr-basics__profile-icon><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Linktree</title><path d="m13.73635 5.85251 4.00467-4.11665 2.3248 2.3808-4.20064 4.00466h5.9085v3.30473h-5.9365l4.22865 4.10766-2.3248 2.3338L12.0005 12.099l-5.74052 5.76852-2.3248-2.3248 4.22864-4.10766h-5.9375V8.12132h5.9085L3.93417 4.11666l2.3248-2.3808 4.00468 4.11665V0h3.4727zm-3.4727 10.30614h3.4727V24h-3.4727z"/></svg></div></div></a><a href=https://github.com/davegallant target=_blank rel="noreferrer me"><div class=jr-basics__profile-item><div class=jr-basics__profile-icon><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63.0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577.0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93.0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176.0.0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22.0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22.0 1.606-.015 2.896-.015 3.286.0.315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></div></div></a><a href=https://mastodon.social/@davegallant target=_blank rel="noreferrer me"><div class=jr-basics__profile-item><div class=jr-basics__profile-icon><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Mastodon</title><path d="M23.268 5.313c-.35-2.578-2.617-4.61-5.304-5.004C17.51.242 15.792.0 11.813.0h-.03c-3.98.0-4.835.242-5.288.309C3.882.692 1.496 2.518.917 5.127.64 6.412.61 7.837.661 9.143c.074 1.874.088 3.745.26 5.611.118 1.24.325 2.47.62 3.68.55 2.237 2.777 4.098 4.96 4.857 2.336.792 4.849.923 7.256.38.265-.061.527-.132.786-.213.585-.184 1.27-.39 1.774-.753a.057.057.0 00.023-.043v-1.809a.052.052.0 00-.02-.041.053.053.0 00-.046-.01 20.282 20.282.0 01-4.709.545c-2.73.0-3.463-1.284-3.674-1.818a5.593 5.593.0 01-.319-1.433.053.053.0 01.066-.054c1.517.363 3.072.546 4.632.546.376.0.75.0 1.125-.01 1.57-.044 3.224-.124 4.768-.422.038-.008.077-.015.11-.024 2.435-.464 4.753-1.92 4.989-5.604.008-.145.03-1.52.03-1.67.002-.512.167-3.63-.024-5.545zm-3.748 9.195h-2.561V8.29c0-1.309-.55-1.976-1.67-1.976-1.23.0-1.846.79-1.846 2.35v3.403h-2.546V8.663c0-1.56-.617-2.35-1.848-2.35-1.112.0-1.668.668-1.67 1.977v6.218H4.822V8.102c0-1.31.337-2.35 1.011-3.12.696-.77 1.608-1.164 2.74-1.164 1.311.0 2.302.5 2.962 1.498l.638 1.06.638-1.06c.66-.999 1.65-1.498 2.96-1.498 1.13.0 2.043.395 2.74 1.164.675.77 1.012 1.81 1.012 3.12z"/></svg></div></div></a><a href=https://www.linkedin.com/in/dave-gallant target=_blank rel="noreferrer me"><div class=jr-basics__profile-item><div class=jr-basics__profile-icon><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>LinkedIn</title><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853.0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601.0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144.0-2.063-.926-2.063-2.065.0-1.138.92-2.063 2.063-2.063 1.14.0 2.064.925 2.064 2.063.0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225.0H1.771C.792.0.0.774.0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2.0 22.222.0h.003z"/></svg></div></div></a></div></div></aside></div></main><footer><div class=copyright>Dave Gallant</div></footer><script src=/js/main.27c23e9259a01acff79c2e4d6c0e56713673c603840d96e8a252b6167e3108706294f823212428068f89451f34415ed350980671eacda0cb92f5fd6291d1ff4a.js integrity="sha512-J8I+klmgGs/3nC5NbA5WcTZzxgOEDZboolK2Fn4xCHBilPgjISQoBo+JRR80QV7TUJgGcerNoMuS9f1ikdH/Sg=="></script><script src=/js/flexsearch.6008453bea2c3113a5612f78b88f04db99ba8fb4ce62b8ee2facd2970062f3f2cf949bebc2b610a40366d44598c9a453b7c6d502e4089844ce707f118ae649db.js integrity="sha512-YAhFO+osMROlYS94uI8E25m6j7TOYrjuL6zSlwBi8/LPlJvrwrYQpANm1EWYyaRTt8bVAuQImETOcH8RiuZJ2w=="></script></div></body></html> |