1
0
Fork 0
mirror of https://github.com/NixOS/nix.dev.git synced 2024-10-18 00:06:26 -04:00
nix.dev/default.nix
fricklerhandwerk 21bfef408a host Nix reference manual on nix.dev
this is the most cursed setup you will see any time soon.

we're dumping the Nix manual unchanged into the build tree *after*
building. the reason is that we'd want to link to it from our table of
contents, but because Sphinx does not allow adding arbitrary files to
the build output in arbitrary locations (only `_static` works). but we
want to place the manual behind a particular URL, and the alternative of
maintaining URL rewrites (e.g. in nginx) is not accessible here because the
infrastructure is managed somewhere else.

now that the files won't appear in their desired locations at Sphinx
build time, we can't use relative links to reference them, therefore we
have to resort to pointing to the web URL the manual will appear at.
this is terrible and I'm sorry. please fix this if you have a better
idea. once we use URLs though, we have to avoid linkchecking, since
those files may not be there before deploying them.

figuring all of this out took way longer than anyone would wish.

Co-authored-by: Alejandro Sanchez Medina <alejandrosanchzmedina@gmail.com>
2023-11-27 07:30:35 +01:00

95 lines
2.2 KiB
Nix

{
inputs ? import ./nix/sources.nix,
system ? builtins.currentSystem,
}:
let
pkgs = import inputs.nixpkgs {
config = { };
overlays = [ (import ./overlay.nix) ];
inherit system;
};
nix-dev = pkgs.stdenv.mkDerivation {
name = "nix-dev";
src = ./.;
nativeBuildInputs = with pkgs.python310.pkgs; [
linkify-it-py
myst-parser
sphinx
sphinx-book-theme
sphinx-copybutton
sphinx-design
sphinx-notfound-page
sphinx-sitemap
];
buildPhase = ''
make html
'';
installPhase =
let
# Various versions of the Nix manuals, grep for (nix-manual)=
# FIXME: This requires human interaction to update!
# See ./CONTRIBUTING.md for details.
releases = [
"2.19"
"2.18"
"2.13"
];
inputName = version: pkgs.lib.strings.replaceStrings [ "." ] [ "-" ] version;
src = version: (import inputs."nix_${inputName version}").default.doc;
copy = version: ''
cp -R ${src version}/share/doc/nix/manual/* $out/manual/nix/${version}
'';
in
with pkgs.lib.strings;
''
mkdir -p $out/manual/nix/{${concatStringsSep "," releases}}
${concatStringsSep "\n" (map copy releases)}
cp -R build/html/* $out/
'';
};
devmode =
let
pythonEnvironment = pkgs.python310.withPackages (ps: with ps; [
livereload
]);
script = ''
from livereload import Server, shell
server = Server()
build_docs = shell("make html")
print("Doing an initial build of the docs...")
build_docs()
server.watch("source/*", build_docs)
server.watch("source/**/*", build_docs)
server.watch("_templates/*.html", build_docs)
server.serve(root="build/html")
'';
in
pkgs.writeShellApplication {
name = "devmode";
runtimeInputs = [ pythonEnvironment ];
text = ''
python ${pkgs.writeText "live.py" script}
'';
};
in
{
# build with `nix-build -A build`
build = nix-dev;
shell = pkgs.mkShell {
inputsFrom = [ nix-dev ];
packages = [
devmode
pkgs.niv
pkgs.python310.pkgs.black
pkgs.vale
];
};
}