summaryrefslogtreecommitdiffstats
path: root/docs/manual.nix
blob: e12777e7708b62a444708619bd4cbc1e0b4310a4 (plain)
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
{
  path,
  stdenvNoCC,
  optionsJSON,
  jaq,
  ndg,
  gnused,
} @ args: let
  manual-release = args.release or "unstable";
in
  stdenvNoCC.mkDerivation (finalAttrs: {
    pname = "nvf-docs-html";
    version = manual-release;
    src = ./manual;

    nativeBuildInputs = [
      ndg
      jaq
      gnused
    ];

    patchPhase = ''
      # Replace variables following the @VARIABLE@ style in the manual
      # pages. This can be built into ndg at a later date.
      substituteInPlace index.md \
        --subst-var-by NVF_VERSION ${finalAttrs.version}

      language_options=$(cat "${optionsJSON}/share/doc/nixos/options.json" | jaq -r 'keys
        | map(select(test("^vim\\.languages\\.[^.]+\\.enable$")))
        | map("- {option}`" + . + "`")
        | join("\n")'
      )

      substituteInPlace configuring/languages.md \
        --subst-var-by NVF_LANGUAGES_ENABLE "$language_options"
    '';

    buildPhase = ''
      mkdir -p queries/nix

      # apply nix injections
      sed -n -f /dev/stdin ${../modules/plugins/languages/nix.nix} <<'EOF' > ./queries/nix/injections.scm
      /type = "injections"/,/^[[:space:]]*};/ {
        /query = '''/,/^[[:space:]]*''';/ {
          /query = '''/d
          /^[[:space:]]*''';/d
          p
        }
      }
      EOF

      # Syntactica doesnt support `query` so we patch it with the closest it does,
      # which is `haskell` :bwaa:
      sed -i 's|#set! injection\.language "query"|#set! injection.language "haskell"|' ./queries/nix/injections.scm

      # Generate the final manual from a set of parameters. This uses
      # feel-co/ndg to render the web manual.
      ndg --config-file ${./ndg.toml} html \
        --jobs $NIX_BUILD_CORES --title "NVF" \
        --module-options ${optionsJSON}/share/doc/nixos/options.json \
        --manpage-urls ${path}/doc/manpage-urls.json \
        --input-dir . \
        --output-dir build
    '';

    installPhase = ''
      mkdir -p $out/share/doc
      cp -r build/* $out/share/doc/

      # Hydra support. Probably not necessary.
      mkdir -p $out/nix-support/
      echo "doc manual $out/share/doc index.html" >> $out/nix-support/hydra-build-products
    '';
  })