forked from nix-community/ethereum.nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkdocs.nix
127 lines (111 loc) · 3.17 KB
/
mkdocs.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
perSystem = {
lib,
pkgsUnstable,
...
}: let
inherit (pkgsUnstable) stdenv runCommand;
in {
packages.docs = let
mkdocs-custom =
pkgsUnstable.runCommand "mkdocs-custom" {
buildInputs = [
pkgsUnstable.python311
pkgsUnstable.python311Packages.mkdocs
pkgsUnstable.python311Packages.mkdocs-material
pkgsUnstable.python311Packages.neoteroi-mkdocs
];
meta.mainProgram = "mkdocs";
} ''
mkdir -p $out/bin
cat <<MKDOCS > $out/bin/mkdocs
#!${pkgsUnstable.runtimeShell}
set -euo pipefail
export PYTHONPATH=$PYTHONPATH
exec ${pkgsUnstable.python311Packages.mkdocs}/bin/mkdocs "\$@"
MKDOCS
chmod +x $out/bin/mkdocs
'';
docsPath = "./docs/nixos/modules";
nixosMarkdownDocs = runCommand "nixos-options" {} ''
mkdir $out
${lib.extras.mkdocs.createNixosMarkdownDocs {modulesPath = ./modules;}}
'';
in
stdenv.mkDerivation {
name = "ethereum-nix-docs";
src = lib.cleanSourceWith {
src = ./.;
filter = path: _type: let
file = builtins.baseNameOf path;
inDocsFolder = builtins.match ".*/docs(/.*)?" path != null;
in
file == "mkdocs.yml" || inDocsFolder;
};
buildInput = [nixosMarkdownDocs];
nativeBuildInputs = [mkdocs-custom];
preBuild = ''
# create link to nixos markdown options reference
mkdir -p ${docsPath}
ln -sf ${nixosMarkdownDocs}/* ${docsPath}/
'';
buildPhase = ''
runHook preBuild
mkdocs build
'';
installPhase = ''
mv site $out
'';
passthru.serve = pkgsUnstable.writeShellScriptBin "serve" ''
set -euo pipefail
# create link to nixos markdown options reference
rm -f ${docsPath}/*.md
ln -sf ${nixosMarkdownDocs}/* ${docsPath}/
${lib.getExe mkdocs-custom} serve
'';
};
devshells.default.commands = let
category = "Docs";
in [
{
inherit category;
name = "docs";
help = "Build and watch for docs";
command = ''
Help() {
echo " Ethereum.nix Docs"
echo
echo " Usage:"
echo " docs build"
echo " docs serve"
echo
echo " Options:"
echo " -h --help Show this screen."
echo
}
Build() {
nix build .#docs
}
Serve() {
nix run .#docs.serve
}
ARGS=$(getopt --options h --longoptions help -- "$@")
while [ $# -gt 0 ]; do
case "$1" in
build) Build; exit 0;;
serve) Serve; exit 0;;
-h | --help) Help; exit 0;;
-- ) shift; break;;
* ) break;;
esac
done
if [ $# -eq 0 ]; then
# No test name has been provided
Help
exit 1
fi
'';
}
];
};
}