Several changes

- Add blogpost about nix arrows
- Change header background
- Add RSS link
This commit is contained in:
Oystein Kristoffer Tveit 2022-10-16 06:10:38 +02:00
parent 3d9fd63cf9
commit 312b05250a
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
8 changed files with 82 additions and 22 deletions

View File

@ -2,11 +2,11 @@
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
@ -17,16 +17,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1646933238,
"narHash": "sha256-RZJnLN0o4B35eTnUc2tEAD12X5TNeeJhhvH3Fd6Pmdo=",
"lastModified": 1665613119,
"narHash": "sha256-VTutbv5YKeBGWou6ladtgfx11h6et+Wlkdyh4jPJ3p0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bacbfd713b4781a4a82c1f390f8fe21ae3b8b95b",
"rev": "e06bd4b64bbfda91d74f13cb5eca89485d47528f",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-21.11",
"ref": "nixos-22.05",
"type": "indirect"
}
},

View File

@ -4,12 +4,8 @@
nixConfig.bash-prompt = "[nix]λ ";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.11";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "nixpkgs/nixos-22.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { flake-utils, nixpkgs, self }:

View File

@ -65,6 +65,9 @@ The content `<div>` is where all your content goes.
padding: 2.5em 2em 0;
border-bottom: 1px solid #00000088;
margin-bottom: 2.5em;
background-image: url(./images/background.jpg);
background-size: cover;
height: 25vh;
}
/* .header h1 {
margin: 0.2em 0;
@ -390,4 +393,4 @@ Hides the menu at `48em`, but modify this based on your app's needs.
left: 0;
width: 100%;
height: 100%;
}
}

BIN
src/images/background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

BIN
src/images/nix_banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -7,13 +7,15 @@ title: "Nani"
---
<header class="header">
<h1 class="display-1">Welcome to nani.wtf</h1>
<img
alt="A woman sitting on a bench amongst trees at the end of a boardwalk leading to a pond with mountains in the background"
src="./images/robert-pearce-UwHN0jU_YqQ-unsplash-800w.jpg"
style="max-width:500px;"
class="mb-4"
/>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-8 col-centered">
<h1 class="display-1 text-white">
Welcome to nani.wtf
</h1>
</div>
</div>
</div>
</header>
<main>
<section class="content">
@ -30,7 +32,9 @@ title: "Nani"
<div class="card-body">
<h5 class="card-title">$title$</h5>
<small class="card-text ">$date$</small>
<p class="card-text">$desc$</p>
$if(desc)$
<p class="card-text">$desc$</p>
$endif$
</div>
<a href="$url$" class="stretched-link"></a>
</div>

View File

@ -0,0 +1,56 @@
---
title: "The nix arrow operator"
keywords: nix, language, programming-language
image: './images/nix_banner.png'
series: "Nix shorts"
---
There is a specal operator in nix, written as `->`. It is not a c dereference struct pointer operator, nor is it a haskell function type definition. It is a boolean operator, which represents the "implies arrow" from [propositional logic][prop-log]. This is especially useful in nix, because of its usage in modules.
## The `myService` module
Let's say you have made a module for `myService` with two options called `myService.enable`, and `myService.address`. `myService` needs an address in order to work properly. If `myService` is not enabled, the value of `myService.address` doesn't really matter. Set or `null`, the result will be the same either way. If `myService` is enabled however, it is crucial that we report an error if `myService.address` is not set. `myService` can not work without it.
In order to make sure that this never happens, we need to assert that this is not the case. This could be done by asserting that this boolean expression is true.
`((!myService.enable) || myService.address != null)`
or in plain english: "Either myService is not enabled, or the address has to not be null"
This is equivalent to this boolean expression:
`myService.enable -> myService.address != null`
or in plain english: "myService being enabled implies that the address is not null".
Asserting these kinds of inter-setting dependencies are common enough in nix modules to provide grounds for having `->` as its own boolean operator.
## Full example
```nix
# modules/myService.nix
{ lib, config }: let
cfg = config.myService;
in {
options = {
enable = lib.mkEnableOption "myService";
address = lib.mkOption {
example = "127.0.0.1";
description = "The address of myService";
type = lib.types.string;
};
};
config = {
# ...
assertions = [
{
assertion = cfg.enable -> cfg.address != null;
message = "myService needs an address";
}
];
};
}
```
[prop-log]: https://iep.utm.edu/prop-log/

View File

@ -74,6 +74,7 @@
<li class="pure-menu-item"><a href="#contact" class="pure-menu-link">Contact</a></li>
<li class="pure-menu-item menu-item-divided"><a href="https://git.nani.wtf" class="pure-menu-link">Git</a></li>
<li class="pure-menu-item"><a href="https://git.nani.wtf/h7x4/nani.wtf" class="pure-menu-link">Site source</a></li>
<li class="pure-menu-item"><a href="public/rss.xml" class="pure-menu-link">RSS</a></li>
</ul>
</div>