the ugly shellscript powering https://oppi.li
at main 140 lines 6.9 kB view raw
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <link rel="stylesheet" href="/style.css"> 5 <link rel="stylesheet" href="/syntax.css"> 6 <meta charset="UTF-8"> 7 <meta name="viewport" content="initial-scale=1"> 8 <meta content="#ffffff" name="theme-color"> 9 <meta name="HandheldFriendly" content="true"> 10 <meta property="og:title" content="NixOS"> 11 <meta property="og:type" content="website"> 12 <meta property="og:description" content="a static site {for, by, about} me "> 13 <meta property="og:url" content="https://oppi.li/posts/nixOS"> 14 <link rel="icon" type="image/x-icon" href="/favicon.png"> 15 <title>NixOS · oppi.li</title> 16 <body> 17 <div class="posts"> 18 <div class="post"> 19 <a href="/" class="post-end-link">Home</a> 20 <span>/</span> 21 <a href="/posts" class="post-end-link">Posts</a> 22 <span>/</span> 23 <a class="post-end-link">NixOS</a> 24 <a class="stats post-end-link" href="https://tangled.sh/@oppi.li/site/raw/main/posts/nixOS.md 25">View Raw</a> 26 <div class="separator"></div> 27 <div class="date"> 28 01/09 — 2020 29 <div class="stats"> 30 <span class="stats-number"> 31 37.56 32 </span> 33 <span class="stats-unit">cm</span> 34 &nbsp 35 <span class="stats-number"> 36 3.4 37 </span> 38 <span class="stats-unit">min</span> 39 </div> 40 </div> 41 <h1> 42 NixOS 43 </h1> 44 <div class="post-text"> 45 <p>I have been eyeing operating systems with functional package managers 46for a while now, aka, NixOS or Guix. Reproducible builds, declarative 47and rollback-able system configuration, system consistency, all sound 48pretty cool. I have been using NixOS for about a month now.</p> 49<h3 id="installation">Installation</h3> 50<p>I went with their minimal installation ISO. The installation was 51pretty smooth from start to end, no hitches there. The entire <a 52href="https://nixos.org/manual/nixos/stable/">manual</a> is available 53offline, and is accessible during the installation. Very handy.</p> 54<h3 id="setup">Setup</h3> 55<p>The entire system is configured via 56<code>/etc/nixos/configuration.nix</code>. Wifi, <code>libinput</code> 57gestures, audio, locale settings, there are options for literally 58everything. You can declaratively write down the packages you want 59installed too. With fresh installs of most distros, I usually fumble 60with getting things like screen backlight and media keys to work. If I 61do manage to fix it, I can’t carry it forward to future installations 62trivially. Getting all my hardware to work on NixOS is as easy as:</p> 63<pre><code>{ 64 server.xserver.libinput.enable = true; # touchpad 65 programs.light.enable = true; # backlight 66 hardware.pulseaudio.enable = true; # audio 67 networking.wireless.enable = true; # wifi 68}</code></pre> 69<h3 id="developing-with-nix">Developing with Nix</h3> 70<p>Nix makes it easy to enter environments that aren’t affected by your 71system configuration using <code>nix-shell</code>.</p> 72<p>Builds may be generated by specifying a <code>default.nix</code> 73file, and running <code>nix-build</code>. Conventional package managers 74require you to specify a dependency list, but there is no guarantee that 75this list is complete. The package will build on your machine even if 76you forget a dependency. However, with Nix, packages are installed to 77<code>/nix/store</code>, and not global paths such as 78<code>/usr/bin/...</code>, if your project builds, it means you have 79included every last one.</p> 80<p>Issues on most my projects have been “unable to build because 81<code>libxcb</code> is missing”, or “this version of 82<code>openssl</code> is too old”. Tools like <code>cargo</code> and 83<code>pip</code> are poor package managers. While they <em>can</em> 84guarantee that Rust or Python dependencies are met, they make 85assumptions about the target system.</p> 86<p>For example, <a href="https://github.com/nerdypepper/site">this 87website</a> is now built using Nix, anyone using Nix may simply, clone 88the repository and run <code>./generate.sh</code>, and it would <em>just 89work</em>, while keeping your global namespace clean™:</p> 90<div class="sourceCode" id="cb2"><pre 91class="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> 92<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> 93<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span> 94<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> 95<p>Dependencies are included with the <code>-p</code> flag, the shell 96script is executed with an interpreter, specified with the 97<code>-i</code> flag.</p> 98<h3 id="impressions">Impressions</h3> 99<p>NixOS is by no means, simple. As a newcomer, using Nix was not easy, 100heck, I had to learn a purely functional, lazy language to just build 101programs. There is a lot to be desired on the tooling front as well. A 102well fleshed out LSP plugin would be nice (<a 103href="https://github.com/nix-community/rnix-lsp">rnix-lsp looks 104promising</a>).</p> 105<p>Being able to rollback changes at a system level is cool. Package 106broke something? Just <code>nixos-rebuild switch --rollback</code>! 107Deleted <code>nix</code> by mistake? Find the binary in 108<code>/nix/store</code> and rollback! You aren’t punished for not 109thinking twice.</p> 110<p>I don’t see myself switching to anything else in the near future, 111NixOS does a lot of things right. If I ever need to reinstall NixOS, I 112can generate an <a 113href="https://github.com/nix-community/nixos-generators">image of my 114current system</a>.</p> 115<p><a href="https://u.peppe.rs/6m.png"><img 116src="https://u.peppe.rs/6m.png" /></a></p> 117 118 </div> 119 120 <div class="intro"> 121 Hi. 122 <div class="hot-links"> 123 <a href="/index.xml" class="feed-button">Subscribe</a> 124 </div> 125 <p>I'm Akshay, programmer, pixel-artist & programming-language enthusiast.</p> 126 <p>I am currently building <a href="https://tangled.sh">tangled.sh</a> — a new social-enabled code-collaboration platform.</p> 127 <p>Reach out at oppili@libera.chat.</p> 128 </div> 129 130 <a href="/" class="post-end-link">Home</a> 131 <span>/</span> 132 <a href="/posts" class="post-end-link">Posts</a> 133 <span>/</span> 134 <a class="post-end-link">NixOS</a> 135 <a class="stats post-end-link" href="https://tangled.sh/@oppi.li/site/raw/main/posts/nixOS.md 136">View Raw</a> 137 </div> 138 </div> 139 </body> 140</html>