/nixture

Nix for the web mixture

Primary LanguageNixMIT LicenseMIT

Nixture

Nix for the web mixture

Nixture helps you build websites without getting in your way.

It adds:

  • Templating (Jinja2)
  • Markup (Org-mode)
  • Backend compilers (GHC)
  • Frontend compilers (GHCJS)

Example

client/index.html.j2

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>example</title>
    <style>{% include "style.css" %}</style>
  </head>

  <body>
    <h2>HTML</h2>
    <pre><code>{% filter escape %}{% include "html-content.html" %}{% endfilter %}</code></pre>
    {% include "html-content.html" %}

    <h2>Org-mode</h2>
    <pre><code>{% filter escape %}{% include "org-content.org.html" %}{% endfilter %}</code></pre>
    {% include "org-content.org.html" %}

    <h2>JavaScript</h2>
    <pre><code>{% filter escape %}{% include "js-script.js" %}{% endfilter %}</code></pre>
    <div id="js-output"></div>
    <script>{% include "js-script.js" %}</script>

    <h2>Haskell</h2>
    <pre><code>{% filter escape %}{% include "hs-script/app/Main.hs" %}{% endfilter %}</code></pre>
    <div id="hs-output"></div>
    <script defer src="hs-script.js"></script>
  </body>
</html>

default.nix

let
  inherit (import <nixpkgs> { }) symlinkJoin;
  inherit
    (import
      (builtins.fetchTarball
        "https://github.com/willmcpherson2/nixture/archive/main.tar.gz"))
    ghc ghcjs optimiseHaskellJs compileNixture;
in
symlinkJoin {
  name = "example";
  paths = [
    (ghc.callCabal2nix "server" ./server { })
    (optimiseHaskellJs (ghcjs.callCabal2nix "hs-script" ./client/hs-script { }))
    (compileNixture ./client)
  ];
}
  • server will be compiled to bin/server
  • hs-script will be compiled to static/hs-script.js
  • org-content.org will be compiled to static/org-content.org.html
  • index.html.j2 will be compiled to static/index.html

Build:

nix-build

Run server:

./result/bin/server result/static/

./example/rendered.png