aboutsummaryrefslogtreecommitdiff
path: root/nixos/profiles/workstation/doc.nix
blob: 0b8a332c14e684eaf73aa57f5c631baa6d1c8d95 (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
# Many packages include documentation other than man pages.
# Nixpkgs conventionally installs this under share/doc, which NixOS
# exposes at /run/current-system/sw/share/doc. Much of it is HTML.
# This module collects plaintext documentation and exposes it under /doc/,
# to make it more accessible to terminal users and digestible for LLMs.

{
  config,
  pkgs,
  pkgs-unstable,
  nvim,
}:

let
  gitDocs = pkgs.runCommand "git-docs" { } ''
    mkdir -p $out
    tar --extract --xz --file ${pkgs.git.src} \
      --strip-components=2 --directory $out \
      --wildcards '*/Documentation/*.adoc'
  '';

  jjDocs = pkgs.runCommand "jj-docs" { } ''
    mkdir -p $out
    cp -R ${pkgs.jujutsu.src}/docs/. $out/
    # changelog.md includes CHANGELOG.md via a directive
    cp -f ${pkgs.jujutsu.src}/CHANGELOG.md $out/changelog.md
  '';

  nvimPluginDocs = pkgs.runCommand "nvim-plugin-docs" { } ''
    mkdir -p $out
    ${pkgs.lib.concatMapStringsSep "\n" (plugin: ''
      pluginOut="$out/${pkgs.lib.getName plugin}"
      find ${plugin} -path '*/doc/*.txt' -type f | while IFS= read -r file; do
        mkdir -p "$pluginOut"
        ln -s "$file" "$pluginOut/$(basename "$file")"
      done
    '') nvim.plugins}
  '';

  symlinks = {
    nix = "${config.nix.package.src}/doc/manual/source";
    git = "${gitDocs}";
    jj = "${jjDocs}";
    niri = "${pkgs.niri.src}/docs/wiki";
    nvim = "${pkgs.neovim-unwrapped}/share/nvim/runtime/doc";
    nvim-plugins = "${nvimPluginDocs}";
    pi = "${pkgs-unstable.pi-coding-agent}/lib/node_modules/pi-monorepo/docs";
  };
in
{
  systemd.tmpfiles.rules = [
    # /doc is a real directory rather than a symlink so sandbox bind mounts
    # of /doc keep seeing updated entries when the symlinks inside it change.
    "d /doc 0555 root root -"
  ]
  ++ pkgs.lib.mapAttrsToList (name: target: "L+ /doc/${name} - - - - ${target}") symlinks;
}