thoughts/flake.nix

131 lines
4.2 KiB
Nix
Raw Permalink Normal View History

2024-08-05 16:15:16 +00:00
{
description = "cl-yag static site generator";
inputs = {
cl-nix-lite.url = "github:hraban/cl-nix-lite";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self, nixpkgs, cl-nix-lite, flake-utils
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system}.extend cl-nix-lite.overlays.default;
2024-08-05 21:31:20 +00:00
mm-sh = pkgs.writeShellScriptBin "mm-sh" ''
#!/bin/sh
2024-08-05 21:46:28 +00:00
cat $2 |perl -0pe 's/\[\^(.*?)\]\:(.*?)(\n\n)/\<span class="marginnote"\>\2\<\/span\>/gms' > $1.tmp
2024-08-05 21:31:20 +00:00
# perl -0pe 's/\[\^(.*?)\][^:]/\<label for\="\1" class\="margin-toggle"\>/gms'
multimarkdown -t html -o $1 $1.tmp && cat $1 |
perl -0pe 's/(\<h2|^)(.*?)(?=(\<h2)|\Z)/\n\<section\>\n\1\2\n<\/section\>\n/gms' |
perl -0pe 's/(\<blockquote\>.*?\<\/blockquote\>)/\<div class="epigraph"\>\n\1\n\<\/div\>/gms' |
perl -0pe 's/(\<blockquote\>.*?)\n(.*?)(\<\/blockquote\>)/\1\<footer\>\2\<\/footer\>\3/gms' > $1.new && mv $1.new $1
rm $1.tmp
'';
move-links = pkgs.writers.writePython3Bin "move-links" { libraries = [ ]; } ''
import sys
import re
lines = "".join(sys.stdin.readlines())
link = re.compile("([[^]]*]([^)]+))")
link_split = re.compile("[([^]]*)](([^)]+))")
marginnotes = re.compile("([^.*?]:.*?\n\n)", re.DOTALL | re.MULTILINE)
_lines = marginnotes.sub("", lines)
lines = _lines
links = link.findall(lines)
i = 1
for _link in links:
lines = lines.replace(_link, "[%s]" % i)
i += 1
i = 1
lines += "\n\n"
for _link in links:
ls = link_split.match(_link)
lines += "=> %s %s\n" % (ls[2], ls[1])
i += 1
sys.stdout.write(lines)
'';
2024-08-05 16:15:16 +00:00
in
{
2024-08-05 18:24:56 +00:00
packages = {
staticSite = with pkgs.lispPackagesLiteFor pkgs.ecl; lispDerivation {
2024-08-05 18:24:56 +00:00
name = "thoughts";
lispSystem = "thoughts";
lispDependencies = [
asdf
arrow-macros
];
src = pkgs.lib.cleanSource ./generator.lisp;
meta = {
license = pkgs.lib.licenses.agpl3Only;
2024-08-05 16:39:33 +00:00
};
2024-08-05 18:24:56 +00:00
buildInputs = [
pkgs.ecl
pkgs.git
pkgs.gnumake
pkgs.asdf
2024-08-05 20:21:26 +00:00
pkgs.perl
2024-08-05 18:24:56 +00:00
pkgs.multimarkdown
pkgs.sass
2024-08-05 21:31:20 +00:00
mm-sh
move-links
2024-08-05 18:24:56 +00:00
];
phases = [ "unpackPhase" "installPhase" "cleanupPhase" ];
unpackPhase = ''
mkdir -p $TMPDIR
cp ${./generator.lisp} $TMPDIR/generator.lisp
mkdir -p $TMPDIR/data
cp -r ${toString ./data}/* $TMPDIR/data/
mkdir -p $TMPDIR/templates
cp -r ${toString ./templates}/* $TMPDIR/templates/
mkdir -p $TMPDIR/static
cp -r ${toString ./static}/* $TMPDIR/static/
'';
installPhase = ''
mkdir -p $out/html/static
2024-08-05 18:24:56 +00:00
mkdir -p $out/gemini
mkdir -p $TMPDIR/output/gemini/articles
mkdir -p $TMPDIR/output/html
mkdir -p $TMPDIR/temp/data
cd $TMPDIR
sass static/css/style.scss $out/html/static/style.css
2024-08-05 18:24:56 +00:00
ecl --load $TMPDIR/generator.lisp
cp -r $TMPDIR/static/fonts $out/html/static
cp -r $TMPDIR/static/img $out/html/static
2024-08-05 18:24:56 +00:00
cp -r $TMPDIR/output/html/* $out/html/
cp -r $TMPDIR/output/gemini/* $out/gemini/
cp -r $TMPDIR $out/tmpdir
'';
cleanupPhase = ''
rm -rf $TMPDIR/temp
'';
};
2024-08-05 16:39:33 +00:00
};
2024-08-05 16:15:16 +00:00
devShell = pkgs.mkShell {
buildInputs = [
pkgs.ecl
pkgs.git
pkgs.gnumake
pkgs.asdf
2024-08-05 20:21:26 +00:00
pkgs.perl
2024-08-05 16:15:16 +00:00
pkgs.multimarkdown
pkgs.sass
2024-08-05 16:15:16 +00:00
];
shellHook = ''
echo "Welcome to the development shell for cl-yag static site generator!"
'';
};
});
}