docs/server: simplify using http-server

Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Matt Sturgeon 2025-05-28 19:48:35 +01:00
parent af5a0deadd
commit 28a2abf874
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 19 additions and 43 deletions

View file

@ -1,21 +1,22 @@
{
lib,
runCommand,
makeBinaryWrapper,
python3,
xdg-utils,
docs,
http-server,
writeShellApplication,
}:
runCommand "serve-docs"
{
nativeBuildInputs = [ makeBinaryWrapper ];
meta.mainProgram = "server";
}
''
mkdir -p $out/bin
makeWrapper ${lib.getExe python3} \
$out/bin/server \
--add-flags ${./server.py} \
--chdir ${docs} \
--prefix PATH : ${lib.makeBinPath [ xdg-utils ]}
''
writeShellApplication {
name = "serve-docs";
runtimeInputs = [ http-server ];
runtimeEnv.server_flags = [
# Search for available port
"--port=0"
# Disable browser cache
"-c-1"
# Open using xdg-open
"-o"
];
text = ''
http-server ${docs} "''${server_flags[@]}"
'';
}