# 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' ''; 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 = "${pkgs.jujutsu.src}/docs"; 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; }