Compare commits
4 Commits
master
...
configurin
Author | SHA1 | Date | |
---|---|---|---|
afcfc7bb07 | |||
4c8df0c5df | |||
58209a2c6e | |||
9d18db19a2 |
@ -111,7 +111,7 @@ article .header {
|
|||||||
|
|
||||||
@media (min-width: 640px) {
|
@media (min-width: 640px) {
|
||||||
body {
|
body {
|
||||||
width: 60rem;
|
width: 85rem;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
/* Generated by pandoc. */
|
/* Generated by pandoc. */
|
||||||
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre
|
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre.sourceCode
|
||||||
{ margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
|
{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
/* border: 0; */
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
pre.sourceCode
|
||||||
|
{
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
background-color: rgb(238,238,255);
|
||||||
|
padding: 10px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
|
td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
|
||||||
td.sourceCode { padding-left: 5px; }
|
td.sourceCode { padding-left: 5px; }
|
||||||
.sourceCode span.kw { color: #007020; font-weight: bold; }
|
.sourceCode span.kw { color: #007020; font-weight: bold; }
|
||||||
|
78
posts/configs.md
Normal file
78
posts/configs.md
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
title: Extensible configuration Pt. 1
|
||||||
|
date: 2019-03-27
|
||||||
|
---
|
||||||
|
|
||||||
|
This is the first part of a series where I'm going through how to make
|
||||||
|
extensible configuration. There is nothing groundbreaking or new in this
|
||||||
|
series, it's just me going through different implementations and trying to
|
||||||
|
understand them.
|
||||||
|
|
||||||
|
The source material for this post is [the fixed point implementation](https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix) for nix.
|
||||||
|
|
||||||
|
By extensible configuration, I'm talking about nix style extensible
|
||||||
|
configuration, like overlays, overrides and extensions. Let's see an example of
|
||||||
|
an extensible configuration.
|
||||||
|
|
||||||
|
``` nix
|
||||||
|
{ haskellPackages, fetchFromGitHub }:
|
||||||
|
|
||||||
|
let
|
||||||
|
purescript = fetchFromGitHub {
|
||||||
|
owner = "purescript";
|
||||||
|
repo = "purescript";
|
||||||
|
rev = "2cb4a6496052db726e099539be682b87585af494";
|
||||||
|
sha256 = "1v4gs08xnqgym6jj3drkzbic7ln3hfmflpbpij3qzwxsmqd2abr7";
|
||||||
|
}
|
||||||
|
hp = haskellPackages.extend (self: super: {
|
||||||
|
purescript = super.callCabal2nix "purescript" purescript {};
|
||||||
|
});
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
hp.purescript;
|
||||||
|
```
|
||||||
|
|
||||||
|
On a high level we are augmenting the `haskellPackages` attrset by replacing
|
||||||
|
the existing purescript package with a different one. The extension is a
|
||||||
|
function that takes two arguments, `self` and `super`. `super` is the original
|
||||||
|
non-lazy value and `self` is the lazy value that corresponds to the value at
|
||||||
|
end.
|
||||||
|
|
||||||
|
The first step on this journey is done by getting to know `fix`. Fix is
|
||||||
|
described being the least fixed point of a function. In practice it's a
|
||||||
|
function allowing declaring recursive functions without explicit recursion.
|
||||||
|
|
||||||
|
``` nix
|
||||||
|
fix = f: let x = f x; in x
|
||||||
|
```
|
||||||
|
|
||||||
|
With fix you can have access to the lazy `self` value. It's value is whatever
|
||||||
|
would have been computed in the end. As it is lazy, it is possible to end up in
|
||||||
|
a recursive loop if there is a cyclic dependency.
|
||||||
|
|
||||||
|
``` nix
|
||||||
|
let recursive = fix (self: {
|
||||||
|
foo = 3;
|
||||||
|
bar = self.foo + 1;
|
||||||
|
});
|
||||||
|
infinite = fix (self: {
|
||||||
|
foo = self.bar + 1;
|
||||||
|
bar = self.foo + 1;
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can try those yourself. The first version is fine and returns an attrset
|
||||||
|
like you would expect. The second one has a cyclic dependency and nix helpfully
|
||||||
|
errors out.
|
||||||
|
|
||||||
|
The next step is making a function that has access to the unmodified original
|
||||||
|
values. This is managed through the `extends` function. It took a while for me to understand what's happening in there, but luckily nix has [good documentation](https://github.com/NixOS/nixpkgs/blob/67b1265fb3d38ead5a57fee838405a2d997777c2/lib/fixed-points.nix#L37-L65) for it.
|
||||||
|
|
||||||
|
``` nix
|
||||||
|
extends = f: rattrs: self: let super = rattrs self; in super // f self super
|
||||||
|
```
|
||||||
|
|
||||||
|
- https://elvishjerricco.github.io/2017/04/01/nix-style-configs-in-haskell.html
|
||||||
|
- https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix
|
||||||
|
- https://chshersh.github.io/posts/2019-03-25-comonadic-builders
|
34
site.hs
34
site.hs
@ -1,9 +1,7 @@
|
|||||||
--------------------------------------------------------------------------------
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Data.Monoid (mappend)
|
import Data.List (sortOn)
|
||||||
|
import Data.Time (defaultTimeLocale, formatTime)
|
||||||
import Hakyll
|
import Hakyll
|
||||||
import Data.List (sortBy, sortOn)
|
|
||||||
import Data.Time (formatTime, defaultTimeLocale)
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -31,34 +29,20 @@ main = hakyllWith defaultConfiguration{ deployCommand = "ipfs add -Q -r _site" }
|
|||||||
>>= loadAndApplyTemplate "templates/default.html" defaultContext
|
>>= loadAndApplyTemplate "templates/default.html" defaultContext
|
||||||
>>= relativizeUrls
|
>>= relativizeUrls
|
||||||
|
|
||||||
match "posts/incomplete/*" $ do
|
match "posts/*" $ do
|
||||||
route $ setExtension "html"
|
route $ setExtension "html"
|
||||||
compile $ pandocCompiler
|
compile $ pandocCompiler
|
||||||
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
||||||
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
||||||
>>= relativizeUrls
|
>>= relativizeUrls
|
||||||
|
|
||||||
match "posts/guides/*" $ do
|
create ["posts.html"] $ do
|
||||||
route $ setExtension "html"
|
|
||||||
compile $ pandocCompiler
|
|
||||||
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
|
||||||
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
|
||||||
>>= relativizeUrls
|
|
||||||
|
|
||||||
match "posts/brainstorming/*" $ do
|
|
||||||
route $ setExtension "html"
|
|
||||||
compile $ pandocCompiler
|
|
||||||
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
|
||||||
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
|
||||||
>>= relativizeUrls
|
|
||||||
|
|
||||||
create ["guides.html"] $ do
|
|
||||||
route idRoute
|
route idRoute
|
||||||
compile $ do
|
compile $ do
|
||||||
posts <- modFirst =<< loadAll "posts/guides/*"
|
posts <- modFirst =<< loadAll "posts/*"
|
||||||
let archiveCtx =
|
let archiveCtx =
|
||||||
listField "posts" postCtx (return posts) `mappend`
|
listField "posts" postCtx (return posts) <>
|
||||||
constField "title" "Guides" `mappend`
|
constField "title" "Posts" <>
|
||||||
defaultContext
|
defaultContext
|
||||||
|
|
||||||
makeItem ""
|
makeItem ""
|
||||||
@ -78,8 +62,8 @@ modFirst = fmap reverse . modified
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
postCtx :: Context String
|
postCtx :: Context String
|
||||||
postCtx =
|
postCtx =
|
||||||
dateField "date" "%B %e, %Y" `mappend`
|
dateField "date" "%B %e, %Y" <>
|
||||||
modifiedField "modified" "%B %e, %Y" `mappend`
|
modifiedField "modified" "%B %e, %Y" <>
|
||||||
defaultContext
|
defaultContext
|
||||||
where
|
where
|
||||||
modifiedField key format = field key $ \i -> do
|
modifiedField key format = field key $ \i -> do
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<!-- Logo by Jason Long -->
|
<!-- Logo by Jason Long -->
|
||||||
<a href="https://git.rauhala.info"><img src="/images/git_16.png" alt="git" /></a>
|
<a href="https://git.rauhala.info"><img src="/images/git_16.png" alt="git" /></a>
|
||||||
<a href="/contact.html">Contact</a>
|
<a href="/contact.html">Contact</a>
|
||||||
|
<a href="/posts.html">Posts</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@ -29,7 +30,7 @@
|
|||||||
<footer>
|
<footer>
|
||||||
Site proudly generated by
|
Site proudly generated by
|
||||||
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
|
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
|
||||||
<span id="ipfs">and found on IPFS as <em></em></ipfs>
|
<span id="ipfs">and found on IPFS as <em></em></ipfs>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
<script type="application/javascript" src="/js/jquery-3.3.1.min.js"></script>
|
<script type="application/javascript" src="/js/jquery-3.3.1.min.js"></script>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
A list of small and big guides.
|
Me writing out interesting ideas and experiments.
|
||||||
|
|
||||||
$partial("templates/post-list.html")$
|
$partial("templates/post-list.html")$
|
||||||
|
Loading…
Reference in New Issue
Block a user