<commit_before>{ pkgs, options
# revision can have multiple values: local, HEAD or any revision number.
, revision ? "HEAD"
}:

with pkgs.lib;

let

  # Remove invisible and internal options.
  options' = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);

  # Clean up declaration sites to not refer to the NixOS source tree.
  options'' = flip map options' (opt: opt // {
    declarations = map (fn: stripPrefix fn) opt.declarations;
  });

  prefix = toString pkgs.path;
  
  stripPrefix = fn:
    if substring 0 (stringLength prefix) fn == prefix then
      substring (add (stringLength prefix) 1) 1000 fn
    else
      fn;

  optionsXML = builtins.toFile "options.xml" (builtins.unsafeDiscardStringContext (builtins.toXML options''));

  optionsDocBook = pkgs.runCommand "options-db.xml" {} ''
    ${pkgs.libxslt}/bin/xsltproc \
      --stringparam revision '${revision}' \
      -o $out ${./options-to-docbook.xsl} ${optionsXML}
  '';

in rec {

  # Generate the NixOS manual.
  manual = pkgs.stdenv.mkDerivation {
    name = "nixos-manual";

    sources = sourceFilesBySuffices ./. [".xml"];

    buildInputs = [ pkgs.libxml2 pkgs.libxslt ];

    xsltFlags = ''
      --param section.autolabel 1
      --param section.label.includes.component.label 1
      --param html.stylesheet 'style.css'
      --param xref.with.number.and.title 1
      --param toc.section.depth 3
      --param admon.style '''
      --param callout.graphics.extension '.gif'
    '';

    buildCommand = ''
      ln -s $sources/*.xml . # */
      ln -s ${optionsDocBook} options-db.xml<commit_msg>Manual: Check that we don't depend on the Nixpkgs location<commit_after>{ pkgs, options
# revision can have multiple values: local, HEAD or any revision number.
, revision ? "HEAD"
}:

with pkgs.lib;

let

  # Remove invisible and internal options.
  options' = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);

  # Clean up declaration sites to not refer to the NixOS source tree.
  options'' = flip map options' (opt: opt // {
    declarations = map (fn: stripPrefix fn) opt.declarations;
  });

  prefix = toString pkgs.path;

  stripPrefix = fn:
    if substring 0 (stringLength prefix) fn == prefix then
      substring (add (stringLength prefix) 1) 1000 fn
    else
      fn;

  optionsXML = builtins.toFile "options.xml" (builtins.unsafeDiscardStringContext (builtins.toXML options''));

  optionsDocBook = pkgs.runCommand "options-db.xml" {} ''
    if grep /nixpkgs/nixos/modules ${optionsXML}; then
      echo "The manual appears to depend on the location of Nixpkgs, which is bad"
      echo "since this prevents sharing via the NixOS channel.  This is typically"
      echo "caused by an option default that refers to a relative path (see above"
      echo "for hints about the offending path)."
      exit 1
    fi
    ${pkgs.libxslt}/bin/xsltproc \
      --stringparam revision '${revision}' \
      -o $out ${./options-to-docbook.xsl} ${optionsXML}
  '';

in rec {

  # Generate the NixOS manual.
  manual = pkgs.stdenv.mkDerivation {
    name = "nixos-manual";

    sources = sourceFilesBySuffices ./. [".xml"];

    buildInputs = [ pkgs.libxml2 pkgs.libxslt ];

    xsltFlags = ''
      --param section.autolabel 1
      --param section.label.includes.component.label 1
      --param html.stylesheet 'style.css'
      --param xref.with.number.and.title 1
      --param toc.section.depth 3
      --param admon.style '''
      --param callout.graphics.extension '.gif'
    '';

    buildCommand = ''
      ln -s $sources/*.xml . # */
      ln -s ${optionsDocBook} options-db.xml
{'fraction_non_alphanumeric': 0.12255037261937621, 'fraction_numerical': 0.006348330113165885, 'mean_word_length': 2.851222104144527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4795847', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1123, 'n_words': 341}