uncle bob

This commit is contained in:
Valentin Gagarin 2024-10-11 13:38:14 +02:00
parent e2416403a3
commit aeb2b1990d
2 changed files with 48 additions and 36 deletions

View file

@ -10,23 +10,10 @@
}: }:
let let
lib' = pkgs.callPackage ./lib.nix { }; lib' = pkgs.callPackage ./lib.nix { };
join = lib.concatStringsSep;
in in
{ {
site = pkgs.stdenv.mkDerivation { site = lib'.site "fediversity.eu" ./content;
name = "fediversity.eu";
src = ./content;
buildPhase = ''
true
'';
installPhase = ''
mkdir $out
'' + join "\n" (lib.mapAttrsToList
(name: value: ''
cp ${value} $out/${name}
'')
(lib'.files ./content));
};
shell = pkgs.mkShellNoCC { shell = pkgs.mkShellNoCC {
packages = with pkgs; [ packages = with pkgs; [
cmark cmark

67
lib.nix
View file

@ -1,5 +1,51 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let
join = lib.concatStringsSep;
in
rec { rec {
/**
Build the web site
*/
site = name: dir:
let
script = ''
mkdir $out
'' + join "\n" copy;
copy = lib.mapAttrsToList
(
path: document: ''
mkdir -p $out/$(dirname ${path})
cp ${document} $out/${path}
''
)
(files (sources dir));
in
pkgs.runCommand name { } script;
/**
Get source files from a flat directory
*/
sources = dir: lib.mapAttrs'
(
attrname: value: {
name = lib.removeSuffix ".nix" attrname;
value = import (dir + "/${attrname}");
}
)
(builtins.readDir dir);
/**
Create a mapping from output file path to document contents
*/
files = documents: lib.mapAttrs'
(
name: document: {
name = document.outPath;
value = html document "${name}.html";
}
)
documents;
/** /**
Convert a Nix document to HTML Convert a Nix document to HTML
*/ */
@ -22,25 +68,4 @@ rec {
pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } '' pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } ''
cmark ${builtins.toFile "${name}.md" markdown} > $out cmark ${builtins.toFile "${name}.md" markdown} > $out
''; '';
/**
Get documents from a flat directory of files
*/
documents = dir: lib.mapAttrs'
(
attrname: value: {
name = lib.removeSuffix ".nix" attrname;
value = import (dir + "/${attrname}");
}
)
(builtins.readDir dir);
files = dir: lib.mapAttrs'
(
name: document: {
name = document.outPath;
value = html document "${name}.html";
}
)
(documents dir);
} }