Debian Codegraph @

default.nix

raw
1 {
2 pkgs ? import <nixpkgs> {},
3 doc2go ? pkgs.doc2go,
4 lib ? pkgs.lib,
5 go ? pkgs.go,
6 pandoc ? pkgs.pandoc,
7 stdenv ? pkgs.stdenv,
8 }:
9
10 let
11 index_template = pkgs.writeText "doc_template.html" ''
12 <!doctype html>
13 <html lang="en">
14 <head>
15 <meta charset="utf-8">
16 </head>
17 <body>
18 $body$
19
20 <script>
21 function replaceWithLink(packageName) {
22 const id = '#package-' + packageName
23 const selector = id + ' code'
24 console.log(selector)
25 const codeElem = document.querySelector(selector);
26 const linkElem = document.createElement("a");
27 const linkText = document.createTextNode(packageName)
28 linkElem.appendChild(linkText);
29
30 const linkUrl = './docs/' + packageName + '/'
31
32 linkElem.href = linkUrl
33 codeElem.replaceWith(linkElem)
34 }
35 replaceWithLink('assert')
36 replaceWithLink('random')
37 replaceWithLink('lifecycle')
38 </script>
39
40 </body>
41 </html>
42 '';
43
44
45 docPages = {
46 "assert" = {
47 title = "package assert";
48 desc = "Docs page for antithesis sdk golang assert package";
49 };
50 random = {
51 title = "package random";
52 desc = "Docs page for antithesis sdk golang random package";
53 };
54 lifecycle = {
55 title = "package lifecycle";
56 desc = "Docs page for antithesis sdk golang lifecycle package";
57 };
58 };
59
60 docs = stdenv.mkDerivation {
61 name = "go_sdk_docs";
62 src = ./.; # TODO: filter
63 nativeBuildInputs = [ go pandoc (doc2go.overrideAttrs (old: {
64 patches = (old.patches or [ ]) ++ [
65 ./doc2go-headers.patch
66 ./doc2go-title.patch
67 ./doc2go-meta-desc.patch
68 ];
69 doCheck = false;
70 })) ];
71 buildPhase = ''
72 export HOME=$TMPDIR
73 mkdir -p $out/docs
74 # TODO: can add `-emded` to generate basic stubs for the docs with no styling to customize our own
75 doc2go -home github.com/antithesishq/antithesis-sdk-go -out $out/docs ${lib.concatMapStringsSep " " (p: "./${p}") (lib.attrNames docPages)}
76
77 ${lib.concatMapStringsSep "\n" ({ name, value }:
78 let
79 title = value.title or "package ${name}";
80 in
81 ''
82 substituteInPlace $out/docs/${name}/index.html --replace-fail "%META_DESCRIPTION%" "${value.desc}"
83 substituteInPlace $out/docs/${name}/index.html --replace-fail "%TITLE%" "${title}"
84 '') (lib.attrsToList docPages)}
85
86 pandoc --template ${index_template} -o $out/index.html README.md
87 '';
88 };
89
90 go_sdk = pkgs.buildGoModule {
91 pname = "antithesis-go-sdk";
92 version = "v0.3.4";
93
94 src = ./.;
95
96 vendorHash = "sha256-K/4hq42VooKVwHydh+SWB8YAzumkONpglfHyRvr82z8=";
97
98 meta = {
99 description = "Antithesis go sdk.";
100 homepage = "https://github.com/antithesishq/antithesis-sdk-go";
101 platforms = lib.platforms.linux;
102 licenses = lib.licenses.mit;
103 };
104 };
105
106 go_sdk_no_antithesis = go_sdk.overrideAttrs (old: {
107 pname = "antithesis-go-sdk-no-antithesis";
108 checkFlags = (old.checkFlags or []) ++ ["-tags=no_antithesis_sdk"];
109 });
110
111 # Builds and tests the SDK with cgo disabled (a frequently encountered misconfiguration)
112 go_sdk_no_cgo = go_sdk.overrideAttrs (old: {
113 pname = "antithesis-go-sdk-no-cgo";
114 env = old.env // { CGO_ENABLED = "0"; };
115 });
116 in
117
118 {
119 inherit docs go_sdk go_sdk_no_antithesis go_sdk_no_cgo;
120 }