basant/output/nix-lang.html

160 lines
5.7 KiB
HTML
Raw Normal View History

2022-04-03 06:29:33 -07:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Nix the Language | Kitaab</title>
<meta property="og:title" content=" Nix the Language | Kitaab">
<meta property="og:type" content="website">
<meta property="og:description"
content="config.site_meta_description">
<meta property="og:site_name" content="Kitaab">
<meta property="og:url" content="build_url">
<meta property="og:image" content="build_urlassets/social.png">
<meta property="og:image:height" content="300">
<meta property="og:image:width" content="300">
<meta property="og:image:type" content="image/jpeg">
<link rel="stylesheet" href="asset/style.css" type="text/css"
media="screen" title="no title" charset="utf-8">
<!-- Mastodon stuff should go here
<meta name="twitter:site" content="config.twitter_name">
<meta name="twitter:title" content="page_title | config.name_of_site">
<meta name="twitter:image" content="build_urlassets/social.png">
<meta name="twitter:image:alt" content="page_title | config.name_of_site">
--!>
<link rel="apple-touch-icon" sizes="57x57" href="build_urlassets/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="build_urlassets/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="build_urlassets/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="build_urlassets/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="build_urlassets/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="build_urlassets/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="build_urlassets/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="build_urlassets/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="build_urlassets/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="build_urlassets/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="build_urlassets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="build_urlassets/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="build_urlassets/favicon-16x16.png">
<meta name="msapplication-TileColor" content="#5927e0">
<meta name="msapplication-TileImage" content="build_urlassets/ms-icon-144x144.png">
<meta name="theme-color" content="#5927e0">
<link rel="canonical" href="Raw">
<link rel="stylesheet" href="assets/main.css">
</head>
<body class="flow-large container">
<header>
<a style='display:flex;padding-top:10px' href="home.html" aria-label="Kitaab">Kitaab</a>
</header>
<main>
<div id='navigation' style="float: right;">
<nav>
<h2> <a href='tag_index.html'> Index </a> </h2>
<ul>
<li> <a href='recents.html'>recents</a></li>
<li> <a href='dev_index.html'>dev</a></li>
<li> <a href='way_index.html'>way</a></li>
<li> <a href='recipe_index.html'>recipe</a></li>
<li> <a href='ops_index.html'>ops</a></li>
<li> <a href='blog_index.html'>blog</a></li>
<li> <a href='rock_index.html'>rock</a></li>
<li> <a href='phil_index.html'>phil</a></li>
<li> <a href='story_index.html'>story</a></li>
<li> <a href='blog_index.html'>blog</a></li>
<li> <a href='untagged_index.html'>untagged</a></li>
</ul>
</nav>
</div>
<h1> Nix the Language </h1>
<div style='max-width:660px;'>
<article class="flow">
<a href="nix_index.html">
nix
</a>
<date>1970-01-01 10:00</date>
<p>%date 190921-1402</p>
<p>Trying to understand the Nix Language</p>
<p>Nix is a functional source grabber and builder. It's not really a package manager, only incidentally so.
(Nixpkgs notwithstanding?)</p>
<p><code>nix repl</code> is your friend!</p>
<h3>AttrSets</h3>
<p>The building block datastructure in Nix. Basically just a DictionarySet</p>
<pre><code class="lang-nix">{
&lt;attributes&gt; = ...;
}
</code></pre>
<h3>Functions</h3>
<pre><code>Nix functions work kinda like Haskell, but no types
</code></pre>
<pre><code class="lang-nix">&gt; double = x: x*2
&gt; double 2
&gt; 4
</code></pre>
<p>Since nix is fucking Haskell, arguments get passed through currying</p>
<pre><code class="lang-nix">&gt; add = x: y: x + y
&gt; add 2 3
&gt; 5
</code></pre>
<p>It's good practice to pass arguments as AttrSets
You can also pass default arguments
But functions take exactly what they define. Nothing more, nothing less.</p>
<pre><code class="lang-nix">&gt; add = {x, y ? 2}: x+y
&gt; add {x = 2;}
&gt; 4
&gt; add {x=2; y=3}
&gt; 5
</code></pre>
<p>If you want other thigs you can do it this way</p>
<pre><code class="lang-nix">&gt; add = s@{x, y, ...}: x + y + s.z
&gt; add {x=2;y=2;z=1;a=1;}
&gt; 5
</code></pre>
<h3>Builtins</h3>
<pre><code>Nix comes with a lot of builtin functions, but doesn't want to pollute scope. So most the functions are scoped under `builtins.`
https://nixos.org/manual/nix/stable/#ssec-builtins
</code></pre>
<h3>Derivations</h3>
<pre><code>One of the functions that Nix includes in all scopes is the `derivation` function
It takes a few arguments, does some Nix magic, and produces a `Derivation`. Kinda like a .o file in C or the .class file in Java. It's not quite a real package yet. Nix still needs to build it
builder
name
output
</code></pre>
<h3>Nixpkgs</h3>
<pre><code>nix-store
</code></pre>
<h3>Building process</h3>
<pre><code>/tmp
$PATH, $HOME
outs
</code></pre>
<h3>Flakes</h3>
<h3>NixOS</h3>
<pre><code>Modules
</code></pre>
</article>
</div>
</main>
</body>
</html>