diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index eb84220f..ca605bba 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -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" diff --git a/REUSE.toml b/REUSE.toml index 03dfbe74..3636d854 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -13,7 +13,7 @@ SPDX-FileCopyrightText = "2023-2025 Steffen Vogel " 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 " SPDX-License-Identifier = "Apache-2.0" diff --git a/flake.nix b/flake.nix index f62df5c3..f09f2bfe 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; }; diff --git a/nix/modules.json b/nix/modules.json new file mode 100755 index 00000000..c8e9314b --- /dev/null +++ b/nix/modules.json @@ -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" +} \ No newline at end of file diff --git a/nix/website.nix b/nix/website.nix new file mode 100644 index 00000000..c8c14729 --- /dev/null +++ b/nix/website.nix @@ -0,0 +1,106 @@ +# SPDX-FileCopyrightText: 2025 Steffen Vogel +# 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 + ''; +})