<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/syntax.css"> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1"> <meta content="#ffffff" name="theme-color"> <meta name="HandheldFriendly" content="true"> <meta property="og:title" content="NixOS"> <meta property="og:type" content="website"> <meta property="og:description" content="a static site {for, by, about} me "> <meta property="og:url" content="https://peppe.rs"> <link rel="icon" type="image/x-icon" href="/favicon.png"> <title>NixOS · peppe.rs</title> <body> <div class="posts"> <div class="post"> <a href="/" class="post-end-link">Home</a> <span>/</span> <a href="/posts" class="post-end-link">Posts</a> <span>/</span> <a class="post-end-link">NixOS</a> <a class="stats post-end-link" href="https://git.peppe.rs/web/site/plain/posts/nixOS.md ">View Raw</a> <div class="separator"></div> <div class="date"> 01/09 — 2020 <div class="stats"> <span class="stats-number"> 37.56 </span> <span class="stats-unit">cm</span>   <span class="stats-number"> 3.3 </span> <span class="stats-unit">min</span> </div> </div> <h1> NixOS </h1> <div class="post-text"> <p>I have been eyeing operating systems with functional package managers for a while now, aka, NixOS or Guix. Reproducible builds, declarative and rollback-able system configuration, system consistency, all sound pretty cool. I have been using NixOS for about a month now.</p> <h3 id="installation">Installation</h3> <p>I went with their minimal installation ISO. The installation was pretty smooth from start to end, no hitches there. The entire <a href="https://nixos.org/manual/nixos/stable/">manual</a> is available offline, and is accessible during the installation. Very handy.</p> <h3 id="setup">Setup</h3> <p>The entire system is configured via <code>/etc/nixos/configuration.nix</code>. Wifi, <code>libinput</code> gestures, audio, locale settings, there are options for literally everything. You can declaratively write down the packages you want installed too. With fresh installs of most distros, I usually fumble with getting things like screen backlight and media keys to work. If I do manage to fix it, I can’t carry it forward to future installations trivially. Getting all my hardware to work on NixOS is as easy as:</p> <pre><code>{ server.xserver.libinput.enable = true; # touchpad programs.light.enable = true; # backlight hardware.pulseaudio.enable = true; # audio networking.wireless.enable = true; # wifi }</code></pre> <h3 id="developing-with-nix">Developing with Nix</h3> <p>Nix makes it easy to enter environments that aren’t affected by your system configuration using <code>nix-shell</code>.</p> <p>Builds may be generated by specifying a <code>default.nix</code> file, and running <code>nix-build</code>. Conventional package managers require you to specify a dependency list, but there is no guarantee that this list is complete. The package will build on your machine even if you forget a dependency. However, with Nix, packages are installed to <code>/nix/store</code>, and not global paths such as <code>/usr/bin/...</code>, if your project builds, it means you have included every last one.</p> <p>Issues on most my projects have been “unable to build because <code>libxcb</code> is missing”, or “this version of <code>openssl</code> is too old”. Tools like <code>cargo</code> and <code>pip</code> are poor package managers. While they <em>can</em> guarantee that Rust or Python dependencies are met, they make assumptions about the target system.</p> <p>For example, <a href="https://github.com/nerdypepper/site">this website</a> is now built using Nix, anyone using Nix may simply, clone the repository and run <code>./generate.sh</code>, and it would <em>just work</em>, while keeping your global namespace clean™:</p> <div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">#! /usr/bin/env nix-shell</span></span> <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co">#! nix-shell -i bash -p eva pandoc esh</span></span> <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span> <span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="co"># some bash magic ;)</span></span></code></pre></div> <p>Dependencies are included with the <code>-p</code> flag, the shell script is executed with an interpreter, specified with the <code>-i</code> flag.</p> <h3 id="impressions">Impressions</h3> <p>NixOS is by no means, simple. As a newcomer, using Nix was not easy, heck, I had to learn a purely functional, lazy language to just build programs. There is a lot to be desired on the tooling front as well. A well fleshed out LSP plugin would be nice (<a href="https://github.com/nix-community/rnix-lsp">rnix-lsp looks promising</a>).</p> <p>Being able to rollback changes at a system level is cool. Package broke something? Just <code>nixos-rebuild switch --rollback</code>! Deleted <code>nix</code> by mistake? Find the binary in <code>/nix/store</code> and rollback! You aren’t punished for not thinking twice.</p> <p>I don’t see myself switching to anything else in the near future, NixOS does a lot of things right. If I ever need to reinstall NixOS, I can generate an <a href="https://github.com/nix-community/nixos-generators">image of my current system</a>.</p> <p><a href="https://u.peppe.rs/6m.png"><img src="https://u.peppe.rs/6m.png" /></a></p> </div> <div class="intro"> Hi. <div class="hot-links"> <a href="https://peppe.rs/index.xml" class="feed-button">Subscribe</a> <a href="https://liberapay.com/nerdypepper/donate" class="donate-button">Donate</a> </div> <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p> <p> I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write <a href="https://git.peppe.rs">open-source stuff</a> to pass time. I also design fonts: <a href="https://git.peppe.rs/fonts/scientifica">scientifica</a>, <a href="https://git.peppe.rs/fonts/curie">curie</a>. </p> <p>Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.</p> </div> <a href="/" class="post-end-link">Home</a> <span>/</span> <a href="/posts" class="post-end-link">Posts</a> <span>/</span> <a class="post-end-link">NixOS</a> <a class="stats post-end-link" href="https://git.peppe.rs/web/site/plain/posts/nixOS.md ">View Raw</a> </div> </div> </body> </html>