summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-08-11 14:11:28 +0000
committerAlyssa Ross <hi@alyssa.is>2022-08-11 15:05:59 +0000
commit842cfd3a79a88e5fcfdf5bbaae898a14bb0df874 (patch)
tree517751d716d79d069ab256598f2d24e1fcdcd24a
parent3a776f26de605cba13b421fc8ad68c46b13670aa (diff)
downloadspectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar.gz
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar.bz2
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar.lz
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar.xz
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.tar.zst
spectrum-842cfd3a79a88e5fcfdf5bbaae898a14bb0df874.zip
Documentation: add a build script
Having two commands that need to be run to build the documentation
isn't very nice, because it means that the only way to confidently
perform a full site build is with nix-build.  And with nix-build, it's
annoying to view the generated site, because there's no analog to
jekyll serve.

So let's extract the build script from Nix, to a shell script.  This
way it can be run by nix-build, or in a nix-shell.  This way, it's
possible to do most work on the site with jekyll serve, and do a full
scripts/build.sh when it's necessary to do things outside of jekyll's
remit, like regenerating the diagram SVGs.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--Documentation/default.nix19
-rwxr-xr-xDocumentation/scripts/build.sh14
2 files changed, 27 insertions, 6 deletions
diff --git a/Documentation/default.nix b/Documentation/default.nix
index ae391ae..d94a8cd 100644
--- a/Documentation/default.nix
+++ b/Documentation/default.nix
@@ -1,11 +1,14 @@
 # SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie
 # SPDX-License-Identifier: MIT
 
 { pkgs ? import <nixpkgs> {} }: pkgs.callPackage (
 
-{ lib, runCommand, jekyll, drawio-headless }:
+{ lib, stdenvNoCC, jekyll, drawio-headless }:
+
+stdenvNoCC.mkDerivation {
+  name = "spectrum-docs";
 
-runCommand "spectrum-docs" {
   src = with lib; cleanSourceWith {
     src = cleanSource ./.;
     filter = name: _type:
@@ -15,14 +18,18 @@ runCommand "spectrum-docs" {
       !(hasSuffix ".svg" name);
   };
 
+  buildPhase = ''
+    runHook preBuild
+    scripts/build.sh $out
+    runHook postBuild
+  '';
+
+  dontInstall = true;
+
   nativeBuildInputs = [ jekyll drawio-headless ];
 
   passthru = { inherit jekyll; };
 }
-  ''
-  jekyll build --disable-disk-cache -b /doc -s $src -d $out
-  drawio --recursive $out/diagrams/ --export -f svg $out/assets/images/
-''
 ) {
   jekyll = import ./jekyll.nix { inherit pkgs; };
 }
diff --git a/Documentation/scripts/build.sh b/Documentation/scripts/build.sh
new file mode 100755
index 0000000..85bd5a5
--- /dev/null
+++ b/Documentation/scripts/build.sh
@@ -0,0 +1,14 @@
+#!/bin/sh -e
+# SPDX-FileCopyrightText: 2022 Unikie
+# SPDX-License-Identifier: EUPL-1.2+
+
+cd "$(dirname "$0")/.."
+
+if [ ! -w . -a ! -w .jekyll-cache ]; then
+	JEKYLLFLAGS=--disable-disk-cache
+fi
+
+find . '(' '!' -path ./_site -o -prune ')' \
+	-a -name '*.drawio' \
+	-exec drawio -xf svg '{}' ';'
+jekyll build $JEKYLLFLAGS -b /doc -d "${1:-_site}"