diff --git a/.gitignore b/.gitignore index 4a32b9b572c0..560a8c4d1e66 100644 --- a/.gitignore +++ b/.gitignore @@ -12,18 +12,6 @@ perl/Makefile.config /svn-revision /libtool -# /doc/manual/ -/doc/manual/*.1 -/doc/manual/*.5 -/doc/manual/*.8 -/doc/manual/nix.json -/doc/manual/conf-file.json -/doc/manual/builtins.json -/doc/manual/src/SUMMARY.md -/doc/manual/src/command-ref/new-cli -/doc/manual/src/command-ref/conf-file.md -/doc/manual/src/expressions/builtins.md - # /scripts/ /scripts/nix-profile.sh /scripts/nix-reduce-build diff --git a/doc/manual/local.mk b/doc/manual/local.mk index e25157af80bc..c4cedc810baa 100644 --- a/doc/manual/local.mk +++ b/doc/manual/local.mk @@ -86,6 +86,5 @@ install: $(d)/src/command-ref/new-cli $(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css $(d)/src/SUMMARY.md $(d)/src/command-ref/new-cli $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md $(trace-gen) RUST_LOG=warn mdbook build doc/manual -d $(docdir)/manual - @cp doc/manual/highlight.pack.js $(docdir)/manual/highlight.js endif diff --git a/doc/manual/meson.build b/doc/manual/meson.build new file mode 100644 index 000000000000..7801a222cbba --- /dev/null +++ b/doc/manual/meson.build @@ -0,0 +1,46 @@ +doc_manual_dir = meson.current_source_dir() + +if get_option('doc_generate') + + # Provide a dummy environment for nix, so that it will not access files outside the macOS sandbox. + dummy_env = [ + 'HOME=/dummy', + 'NIX_CONF_DIR=/dummy', + 'NIX_SSL_CERT_FILE=/dummy/no-ca-bundle.crt', + 'NIX_STATE_DIR=/dummy', + ] + + foreach dir : ['src'] + subdir(dir) + endforeach + + # generate the web version of the manual + #============================================================================ + + custom_target( + 'index.html', + input: src_markdown_files + [ + summary_dot_md, + new_cli, + conf_file_dot_md, + builtins_dot_md, + ] + files( + 'book.toml', + 'custom.css', + join_paths('theme', 'highlight.js'), + ), + output: 'manual', + command: [ + 'mdbook', + 'build', + meson.current_build_dir(), + '-d', + 'manual', + ], + env: ['RUST_LOG=warn'], + install: true, + install_dir: docdir, + build_by_default: true, + ) + +endif diff --git a/doc/manual/src/command-ref/meson.build b/doc/manual/src/command-ref/meson.build new file mode 100644 index 000000000000..4ea499a5e309 --- /dev/null +++ b/doc/manual/src/command-ref/meson.build @@ -0,0 +1,160 @@ +doc_manual_src_command_ref_src = meson.current_source_dir() + +# generate `doc/manual/src/command-ref/new-cli` +#============================================================================ + +nix_dot_json = custom_target( + 'nix.json', + output: 'nix.json', + command: [ + nix_bin, + '__dump-args', + ], + capture: true, + env: dummy_env, + install: true, + install_dir: mandir, + build_by_default: true, +) + +new_cli = custom_target( + 'new-cli', + input: [ + nix_bin, + nix_dot_json, + join_paths(doc_manual_dir, 'generate-manpage.nix'), + ], + output: 'new-cli', + command: [ + find_program( + 'write-new-cli.sh', + dirs: [join_paths(scripts_dir, 'manual')], + ), + '@INPUT@', + '@OUTPUT@', + ], + env: dummy_env, + install: true, + install_dir: mandir, + build_by_default: true, +) + +# generate `doc/manual/src/command-ref/conf-file.md` +#============================================================================ + +conf_file_dot_json = custom_target( + 'conf-file.json', + output: 'conf-file.json', + command: [ + nix_bin, + 'show-config', + '--json', + '--experimental-features', + 'nix-command', + ], + capture: true, + env: dummy_env, + install: true, + install_dir: mandir, + build_by_default: true, +) + +conf_file_dot_md = custom_target( + 'conf-file.md', + input: [ + nix_bin, + conf_file_dot_json, + join_paths(doc_manual_dir, 'generate-options.nix') + ] + files( + 'conf-file-prefix.md' + ), + output: 'conf-file.md', + command: [ + find_program( + 'write-conf-file.sh', + dirs: [join_paths(scripts_dir, 'manual')], + ), + '@INPUT@', + ], + capture: true, + install: true, + install_dir: mandir, + build_by_default: true, +) + +# man pages +#============================================================================ + +prepend_title = generator( + find_program( + 'prepend-title-to-manpage.sh', + dirs: [join_paths(scripts_dir, 'manual')], + ), + arguments: ['@BASENAME@', '@EXTRA_ARGS@', '@INPUT@'], + capture: true, + output: '@BASENAME@.tmp', +) + +man_pages = { + '1': [ + 'nix-env', + 'nix-build', + 'nix-shell', + 'nix-store', + 'nix-instantiate', + 'nix-collect-garbage', + 'nix-prefetch-url', + 'nix-channel', + 'nix-hash', + 'nix-copy-closure', + ], + '8': [ + 'nix-daemon', + ] +} + +foreach section, pages : man_pages + foreach page : pages + man_dst = '@0@.@1@'.format(page, section) + man_src = files('@0@.md'.format(page)) + + custom_target( + man_dst, + input: prepend_title.process(man_src, extra_args: [section]), + output: man_dst, + command: [ + 'lowdown', + '-sT', + 'man', + '-M section=@0@'.format(section), + '@INPUT@', + '-o', + '@OUTPUT@' + ], + install: true, + install_dir: mandir, + build_by_default: true, + ) + endforeach +endforeach + +custom_target( + 'nix.conf.5', + input: prepend_title.process( + conf_file_dot_md, + extra_args: ['5'] + ), + output: 'nix.conf.5', + command: [ + 'lowdown', + '-sT', + 'man', + '-M section=5', + '@INPUT@', + '-o', + '@OUTPUT@', + ], + install: true, + install_dir: mandir, + build_by_default: true, +) diff --git a/doc/manual/src/expressions/meson.build b/doc/manual/src/expressions/meson.build new file mode 100644 index 000000000000..8eaf159a5c96 --- /dev/null +++ b/doc/manual/src/expressions/meson.build @@ -0,0 +1,42 @@ +doc_manual_src_expressions_dir = meson.current_source_dir() + +# Generate `doc/manual/src/expressions/builtins.md` +#============================================================================ + +builtins_dot_json = custom_target( + 'builtins.json', + output: 'builtins.json', + command: [ + nix_bin, + '__dump-builtins', + ], + capture: true, + env: dummy_env + ['NIX_PATH=nix/corepkgs=corepkgs'], + install: true, + install_dir: mandir, + build_by_default: true, +) + +builtins_dot_md = custom_target( + 'builtins.md', + input: [ + nix_bin, + builtins_dot_json, + join_paths(doc_manual_dir, 'generate-builtins.nix') + ] + files( + 'builtins-prefix.md', + 'builtins-suffix.md', + ), + output: 'builtins.md', + command: [ + find_program( + 'write-builtins.sh', + dirs: [join_paths(scripts_dir, 'manual')], + ), + '@INPUT@', + ], + capture: true, + install: true, + install_dir: mandir, + build_by_default: true, +) diff --git a/doc/manual/src/meson.build b/doc/manual/src/meson.build new file mode 100644 index 000000000000..ad7872db0365 --- /dev/null +++ b/doc/manual/src/meson.build @@ -0,0 +1,29 @@ +doc_manual_src_dir = meson.current_source_dir() + +foreach dir : ['command-ref', 'expressions'] + subdir(dir) +endforeach + +# generate `doc/manual/src/SUMMARY.md` +#============================================================================ + +summary_dot_md = custom_target( + 'SUMMARY.md', + input: [ + join_paths(doc_manual_dir, 'src', 'SUMMARY.md.in'), + new_cli, + ], + output: 'SUMMARY.md', + command: [ + find_program( + 'write-summary.sh', + dirs: [join_paths(scripts_dir, 'manual')], + ), + '@INPUT@', + ], + capture: true, + install: true, + install_dir: mandir, + build_by_default: true, +) + diff --git a/doc/manual/highlight.pack.js b/doc/manual/theme/highlight.js similarity index 100% rename from doc/manual/highlight.pack.js rename to doc/manual/theme/highlight.js diff --git a/meson.build b/meson.build index aebfa8eb6054..d0142727b58a 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,7 @@ datadir = join_paths(prefix, get_option('datadir')) sysconfdir = join_paths(prefix, get_option('sysconfdir')) libexecdir = join_paths(prefix, get_option('libexecdir')) mandir = join_paths(prefix, get_option('mandir')) +docdir = join_paths(prefix, get_option('docdir')) includedir = join_paths(prefix, get_option('includedir')) proj_inc = [] @@ -225,8 +226,8 @@ project_dirs = [ 'include', 'src', 'scripts', + 'doc/manual', #'misc', - #'doc', #'tests', ] diff --git a/scripts/manual/prepend-title-to-manpage.sh b/scripts/manual/prepend-title-to-manpage.sh new file mode 100644 index 000000000000..78c19e402bb3 --- /dev/null +++ b/scripts/manual/prepend-title-to-manpage.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +# This script is meant to be used by `doc/manual/meson.build` to help build the documentation. + +printf "Title: %s\n\n" "${1}.${2}" +cat $3 diff --git a/scripts/manual/write-builtins.sh b/scripts/manual/write-builtins.sh new file mode 100644 index 000000000000..140269593d5b --- /dev/null +++ b/scripts/manual/write-builtins.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh +# This script is meant to be used by `doc/manual/meson.build` to help build the documentation. + +nixBinary="$1" +builtinsJsonFile="$2" +generateBuiltinsNix="$3" +prefixFile="$4" +suffixFile="$5" + +cat $prefixFile + +$nixBinary eval \ + --experimental-features nix-command \ + -I nix/corepkgs=corepkgs \ + --store dummy:// \ + --impure \ + --raw \ + --expr "import $generateBuiltinsNix (builtins.fromJSON (builtins.readFile $builtinsJsonFile))" + +cat $suffixFile diff --git a/scripts/manual/write-conf-file.sh b/scripts/manual/write-conf-file.sh new file mode 100644 index 000000000000..7e8133c30778 --- /dev/null +++ b/scripts/manual/write-conf-file.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh +# This script is meant to be used by `doc/manual/meson.build` to help build the documentation. + +nixBinary="$1" +confJsonFile="$2" +generateOptionsNix="$3" +prefixFile="$4" + + +cat $prefixFile + +$nixBinary eval \ + --experimental-features nix-command \ + -I nix/corepkgs=corepkgs \ + --store dummy:// \ + --impure \ + --raw \ + --expr "import $generateOptionsNix (builtins.fromJSON (builtins.readFile $confJsonFile))" diff --git a/scripts/manual/write-new-cli.sh b/scripts/manual/write-new-cli.sh new file mode 100644 index 000000000000..2d9952815c01 --- /dev/null +++ b/scripts/manual/write-new-cli.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +# This script is meant to be used by `doc/manual/meson.build` to help build the documentation. + +nixBinary="$1" +newCliFile="$2" +generateManPageNix="$3" +output="$4" + +# `--write-to` requires the file to *NOT* be present. +rm -Rf $output + +$nixBinary eval \ + --experimental-features nix-command \ + -I nix/corepkgs=corepkgs \ + --store dummy:// \ + --impure \ + --raw \ + --write-to $output \ + --expr "import $generateManPageNix (builtins.fromJSON (builtins.readFile $newCliFile))" diff --git a/scripts/manual/write-summary.sh b/scripts/manual/write-summary.sh new file mode 100644 index 000000000000..156efef2971b --- /dev/null +++ b/scripts/manual/write-summary.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +# This script is meant to be used by `doc/manual/meson.build` to help build the documentation. + +input="$1" +newCliSummaryFile="$2/SUMMARY.md" + + +cat $input | while IFS= read line; do + if [[ $line = @manpages@ ]]; then + cat $newCliSummaryFile + else + echo "$line"; + fi; +done diff --git a/scripts/meson.build b/scripts/meson.build index b8b7e1d9ed80..0626c6f1b464 100644 --- a/scripts/meson.build +++ b/scripts/meson.build @@ -1,6 +1,7 @@ # Nix corepkgs build file #============================================================================ +scripts_dir = meson.current_source_dir() scripts_inc = [include_directories('.')] diff --git a/src/nix/meson.build b/src/nix/meson.build index 6a954437fd00..83ab63cc18e5 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -68,6 +68,21 @@ nix_src = files( 'upgrade-nix.cc', 'verify.cc', 'why-depends.cc') + +src_markdown_files = files( + 'flake-lock.md', 'store-repair.md', 'nix.md', 'why-depends.md', 'registry-list.md', 'store-dump-path.md', + 'nar.md', 'edit.md', 'nar-ls.md', 'store-delete.md', 'nar-cat.md', 'upgrade-nix.md', 'show-derivation.md', + 'copy.md', 'bundle.md', 'registry.md', 'search.md', 'optimise-store.md', 'key-convert-secret-to-public.md', + 'profile-install.md', 'run.md', 'nar-dump-path.md', 'flake-archive.md', 'profile.md', 'flake-check.md', + 'daemon.md', 'repl.md', 'store-prefetch-file.md', 'profile-upgrade.md', 'add-path.md', 'flake-new.md', + 'profile-history.md', 'profile-diff-closures.md', 'help.md', 'diff-closures.md', 'key-generate-secret.md', + 'store-gc.md', 'registry-add.md', 'profile-remove.md', 'shell.md', 'path-info.md', 'ping-store.md', + 'flake.md', 'flake-update.md', 'flake-clone.md', 'eval.md', 'flake-metadata.md', 'profile-list.md', + 'flake-init.md', 'make-content-addressable.md', 'registry-pin.md', 'verify.md', 'develop.md', + 'flake-prefetch.md', 'store-ls.md', 'add-file.md', 'flake-show.md', 'build.md', 'registry-remove.md', + 'print-dev-env.md', 'store-cat.md', 'log.md', join_paths('realisation', 'info.md'), +) + # nix_ln_src = [ # [ bindir, 'nix-build' ], # [ bindir, 'nix-channel' ],