feat(nix,docs): Build website via Nix

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2025-01-04 11:16:52 +01:00
parent 3631ca0214
commit 6772a6ea55
5 changed files with 126 additions and 3 deletions

View File

@@ -55,6 +55,7 @@ jobs:
nix-update gocov-merger
nix-update cunicu
nix-update cunicu-scripts
nix-update --subpackage yarnOfflineCache cunicu-website
git diff --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"

View File

@@ -13,7 +13,7 @@ SPDX-FileCopyrightText = "2023-2025 Steffen Vogel <post@steffenvogel.de>"
SPDX-License-Identifier = "CC0-1.0"
[[annotations]]
path = ["go.sum", "scripts/go.sum", "website/package.json", "website/yarn.lock", "nix/flake.lock", "docs/usage/**", ".renovaterc.json", "**.drawio", "**.svg", "flake.lock"]
path = ["go.sum", "scripts/go.sum", "website/package.json", "website/yarn.lock", "nix/flake.lock", "nix/modules.json", "docs/usage/**", ".renovaterc.json", "**.drawio", "**.svg", "flake.lock"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2023-2025 Steffen Vogel <post@steffenvogel.de>"
SPDX-License-Identifier = "Apache-2.0"

View File

@@ -18,14 +18,15 @@
inputs@{ self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
flake = {
nixosModules = rec {
default = cunicu;
nixosModules = {
default = self.nixosModules.cunicu;
cunicu = import ./nix/module.nix;
};
overlays = {
default = final: prev: {
cunicu = final.callPackage ./nix/cunicu.nix { };
cunicu-website = final.callPackage ./nix/website.nix { };
cunicu-scripts = final.callPackage ./nix/scripts.nix { };
gocov-merger = final.callPackage ./nix/gocov-merger.nix { };
};
@@ -67,6 +68,7 @@
inherit (pkgs) cunicu gocov-merger;
default = pkgs.cunicu;
website = pkgs.cunicu-website;
scripts = pkgs.cunicu-scripts;
};
};

14
nix/modules.json Executable file
View File

@@ -0,0 +1,14 @@
{
"cunicu.li/cunicu": "https://github.com/cunicu/cunicu.git",
"cunicu.li/go-babel": "https://github.com/cunicu/go-babel.git",
"cunicu.li/go-iso7816": "https://github.com/cunicu/go-iso7816.git",
"cunicu.li/go-openpgp-card": "https://github.com/cunicu/go-openpgp-card.git",
"cunicu.li/go-piv": "https://github.com/cunicu/go-piv.git",
"cunicu.li/go-pmtud": "https://github.com/cunicu/go-pmtud.git",
"cunicu.li/go-rosenpass": "https://github.com/cunicu/go-rosenpass.git",
"cunicu.li/go-ykoath/v2": "https://github.com/cunicu/go-ykoath.git",
"cunicu.li/gont/v2": "https://github.com/cunicu/gont.git",
"cunicu.li/hawkes": "https://github.com/cunicu/hawkes.git",
"cunicu.li/skeleton": "https://github.com/cunicu/skeleton.git",
"github.com/cloudflare/circl": "https://github.com/cunicu/circl.git"
}

106
nix/website.nix Normal file
View File

@@ -0,0 +1,106 @@
# SPDX-FileCopyrightText: 2025 Steffen Vogel <post@steffenvogel.de>
# SPDX-License-Identifier: Apache-2.0
{
lib,
stdenv,
stdenvNoCC,
yarn-berry,
cacert,
nodejs-slim,
cunicu,
cunicu-scripts,
# Options
goModules ? builtins.fromJSON (builtins.readFile ./modules.json),
...
}:
let
yarnOfflineCache = stdenvNoCC.mkDerivation {
name = "yarn-deps";
inherit (cunicu) version src;
nativeBuildInputs = [ yarn-berry ];
dontInstall = true;
NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt";
YARN_ENABLE_TELEMETRY = "0";
buildPhase = ''
runHook preBuild
cd website
export HOME=$(mktemp -d)
YARN_CACHE="$(yarn config get cacheFolder)"
yarn install --immutable --mode skip-build
mkdir -p $out
cp -r $YARN_CACHE/* $out/
runHook postBuild
'';
outputHash = "sha256-0+km0FIvC08noQOVOlrqf79Ocuq8p5DyURZFPGEaLWs=";
outputHashMode = "recursive";
};
in
stdenv.mkDerivation (finalAttrs: {
name = "cunicu-docs";
inherit (cunicu) version src;
inherit yarnOfflineCache;
nativeBuildInputs = [
nodejs-slim
yarn-berry
];
NODE_ENV = "production";
YARN_ENABLE_TELEMETRY = "0";
buildPhase = ''
runHook preBuild
shopt -s globstar
cd website
export HOME=$(mktemp -d)
export npm_config_nodedir=${nodejs-slim}
mkdir -p ~/.yarn/berry
ln -s $yarnOfflineCache ~/.yarn/berry/cache
echo "== Generate redirects"
${cunicu-scripts}/bin/vanity_redirects -static-dir static -modules-file ${builtins.toFile "modules.json" (builtins.toJSON goModules)}
echo "== Generate usage docs"
${lib.getExe cunicu} docs --with-frontmatter --output-dir docs/usage
echo "-- Fix generated docs"
substituteInPlace docs/usage/md/**/*.md \
--replace-quiet '<' '\<' \
--replace-quiet '{' '\{'
echo "== Yarn install"
yarn install --immutable --immutable-cache
patchShebangs ~/node_modules
echo "== Yarn build"
yarn build
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r build $out
runHook postInstall
'';
})