{ config, pkgs, lib, inputs, system, ... }:
let
  # https://stackoverflow.com/a/60232211
  system = config.nixpkgs.system;

  #mk-nixpkgs-manual = input: import "${input}/doc" { pkgs = import input { inherit system; }; };
  mk-nixpkgs-manual = input: (import "${input}/pkgs/top-level/release.nix" { nixpkgs = import input { inherit system; }; }).manual;
  mk-nixos-manual   = input: (import "${input}/nixos/release.nix" { nixpkgs = import input { inherit system; }; }).manualHTML.${system};

in
{
  services.docs-to-host.docs = [
    {
      dirname = "nix-manual";
      path    = "${pkgs.nix.doc}/share/doc/nix/manual";
      desc    = "Official Nix manual";
    }
    {
      dirname = "nixpkgs-manual";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs manual";
    }
    {
      dirname = "nixos-manual";
      path    = "${mk-nixos-manual inputs.nixpkgs}/share/doc/nixos";
      desc    = "Official Nixos manual";
    }
    # == Old Nixpkgs manuals ==
    /** /
    {
      dirname = "nixpkgs-manual-23.05";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2213}05share/doc/nixpkgs";
      desc    = "Official Nixpkgs 23.05 manual";
    }
    {
      dirname = "nixpkgs-manual-22.11";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2211}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 22.11 manual";
    }
    {
      dirname = "nixpkgs-manual-22.05";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2205}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 22.05 manual";
    }
    {
      dirname = "nixpkgs-manual-21.11";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2111}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 21.11 manual";
    }
    {
      dirname = "nixpkgs-manual-21.05";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2105}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 21.05 manual";
    }
    {
      dirname = "nixpkgs-manual-20.09";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2009}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 20.09 manual";
    }
    {
      dirname = "nixpkgs-manual-20.03";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-2003}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 20.03 manual";
    }
    {
      dirname = "nixpkgs-manual-19.09";
      basename= "manual.html";
      path    = "${mk-nixpkgs-manual inputs.nixpkgs-1909}/share/doc/nixpkgs";
      desc    = "Official Nixpkgs 19.09 manual";
    }
    /**/
    # == Old Nixos manuals ==
    /** /
    {
      dirname = "nixos-manual-22.11";
      path    = "${mk-nixos-manual inputs.nixpkgs-2211}/share/doc/nixos";
      desc    = "Official Nixos 22.11 manual";
    }
    {
      dirname = "nixos-manual-22.05";
      path    = "${mk-nixos-manual inputs.nixpkgs-2205}/share/doc/nixos";
      desc    = "Official Nixos 22.05 manual";
    }
    {
      dirname = "nixos-manual-21.11";
      path    = "${mk-nixos-manual inputs.nixpkgs-2111}/share/doc/nixos";
      desc    = "Official Nixos 21.11 manual";
    }
    {
      dirname = "nixos-manual-21.05";
      path    = "${mk-nixos-manual inputs.nixpkgs-2105}/share/doc/nixos";
      desc    = "Official Nixos 21.05 manual";
    }
    {
      dirname = "nixos-manual-20.09";
      path    = "${mk-nixos-manual inputs.nixpkgs-2009}/share/doc/nixos";
      desc    = "Official Nixos 20.09 manual";
    }
    {
      dirname = "nixos-manual-20.03";
      path    = "${mk-nixos-manual inputs.nixpkgs-2003}/share/doc/nixos";
      desc    = "Official Nixos 20.03 manual";
    }
    {
      dirname = "nixos-manual-19.09";
      path    = "${mk-nixos-manual inputs.nixpkgs-19}/share/doc/nixos";
      desc    = "Official Nixos 19.09 manual";
    }
    /**/
  ];
}
